Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GraphQL support #23

Merged
merged 1 commit into from
Jan 7, 2021
Merged

Add GraphQL support #23

merged 1 commit into from
Jan 7, 2021

Conversation

hileomsi
Copy link
Contributor

@hileomsi hileomsi commented Jan 4, 2021

Improvements added

  • Add GraphQL support
  • Expose all sentry options as module options
  • Add integrations in sentry options
  • Update packages
  • Release new version
  • Remove unused code and improve file organization

Describe the solution

I added support for all sentry options with this code below:

export type SentryModuleOptions = Omit<Options, 'integrations'> & {
    integrations?: Integration[];
};
const { debug, integrations = [], ...sentryOptions } = options;

Sentry.init({
  ...sentryOptions,
  integrations: [
    new Sentry.Integrations.OnUncaughtException({
      onFatalError: (async (err) => {
        if (err.name === 'SentryError') { console.log(err); } else { (Sentry.getCurrentHub().getClient<Client<Options>>() as Client<Options>).captureException(err); process.exit(1); }
      }),
    }),
    new Sentry.Integrations.OnUnhandledRejection({mode: 'warn'})
    ...integrations
  ]
});

I added GraphQL support with this code below:

case 'graphql':
  return this.captureGraphqlException(
    scope, 
    GqlExecutionContext.create(context), 
    exception
  );
private captureGraphqlException(scope: Scope, gqlContext: GqlExecutionContext, exception: any): void {
    const info = gqlContext.getInfo()
    const context = gqlContext.getContext() 

    scope.setExtra('type', info.parentType.name)

    if (context.req) {
      // req within graphql context needs modification in 
      const data = Handlers.parseRequest(<any>{}, context.req, {});

      scope.setExtra('req', data.request);

      if (data.extra) scope.setExtras(data.extra);
      if (data.user) scope.setUser(data.user);
   }

    this.client.instance().captureException(exception);
  }

* chore(graphql) add graphql support

* chore(service) pass initializing properties

* chore(dist) build

* chore(SentryInterceptor): remove options

* refactor: remove all unused code

* chore(build) add build folder

* refactor(interceptor)
@juanpujol
Copy link

Thank you for this @hileomsi 🙏 👍

@ntegral ntegral merged commit 3af009c into ntegral:master Jan 7, 2021
This was referenced Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants