How to submit your own 8base tips

So you want to submit a tip to be featured in our Tip of the Week newsletter, huh? THANK YOU YOU’RE AWESOME.

Just go ahead and make a comment in this forum topic. Our team and other developers will get to see your genius immediately, and then we’ll pull out the most popular tips to be sent to our 10K plus subscriber list, and give YOU the credit!

1 Like

Hey Sebastian,

A tip I’d give — when developing custom functions, upgrade your graphql-request package which will then ask for TypedDocumentNode instead of strings for your GraphQL query.

  • Add GraphQL codegen
  • Set up a script to generate your typed documents
  • Get fully typed results and query

For me, this made development significantly less error prone.

1 Like

Sounds awesome, Kenna! Could you provide a few of the steps for this and an screenshot? I think we could slate it for week 8 :slight_smile:

Using currying or higher order functions with custom resolvers.

For example I what to send all my errors to Sentry.

// src/shared/withSentry.js
import * as Sentry from '@sentry/node';

const config = {
  dsn: process.env.SENTRY_DSN,
};

Sentry.init(config);

export const withSentry = (customFunction) => async (
  event,
  ctx,
) => {
  try {
    return await customFunction(event, ctx);
  } catch (error) {
    if (error) {
      console.error(error.message);
      console.error(JSON.stringify(error.message, null, 2));
    }

    Sentry.withScope(scope => {
      scope.setExtras({
        event,
        rawEvent: JSON.stringify(event),
        ctx,
        functionName: customFunction?.name,
        error,
      });

      Sentry.captureMessage(customFunction.name);
    });

    await Sentry.flush(2000);

    throw error;
  }
};

//----

// 
const myResolver = async (
  even,
  ctx,
) => {
  const shouldThrowError = event.data?.shouldThrowError;

  if (!!shouldThrowError) {
    throw new Error('Test error');
  }

  return {
    data: {
      success: true,
    },
  };
};

export default withSentry(myResolver);

Hey @vyacheslav.solomin we actually have 2 content pieces coming out for the Academy that talk about using higher-order functions! You’ll see them soon :+1: