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

Bug: Running plugin setup can duplicate inngestPlugin in the GraphQLHandler extraPlugins #67

Open
dthyresson opened this issue Apr 22, 2023 · 3 comments

Comments

@dthyresson
Copy link
Collaborator

If the GraphQLHandler is:

import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'
import { inngestPlugin } from 'src/plugins/useInngest'

export const handler = createGraphQLHandler({
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,

  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect()
  },

  extraPlugins: [inngestPlugin],
})

where extraPlugins: [inngestPlugin], is already set, re-running and forcing the plugin setup duplicates:

import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'
import { inngestPlugin } from 'src/plugins/useInngest'

export const handler = createGraphQLHandler({
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,

  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect()
  },

  extraPlugins: [inngestPlugin],
  extraPlugins: [inngestPlugin]
})
@dthyresson
Copy link
Collaborator Author

While there is a test for when the extraPlugins exists:

it('when GraphQL handler already has useInngest setup', () => {
          const source = fs.readFileSync(path.join(__dirname, '__testfixtures__', 'plugin', 'exists.input.js'), 'utf8');
          const output = pluginTransform(
            { path: '../__testfixtures__/exists.input.js', source },
            { jscodeshift },
            { ...defaultJscodeshiftOpts }
          );
          expect(output).toMatchSnapshot();
        });

with a fixture:

import { createGraphQLHandler } from '@redwoodjs/graphql-server';

import directives from 'src/directives/**/*.{js,ts}';
import sdls from 'src/graphql/**/*.sdl.{js,ts}';
import services from 'src/services/**/*.{js,ts}';

import { getCurrentUser } from 'src/lib/auth';
import { db } from 'src/lib/db';
import { logger } from 'src/lib/logger';

import { inngestPlugin } from 'src/inngest/plugin';

export const handler = createGraphQLHandler({
  getCurrentUser,
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,
  extraPlugins: [inngestPlugin],
  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect();
  },
});

and that test passes, for some reason the plugins still are duplicated.

@dthyresson
Copy link
Collaborator Author

While test pass, for some reason when running in a RW project, the codemod behaves differently.

Something in this detection behaves differently:

      const extraPluginsProp = optionsProps.properties?.find(
        (p): p is Property => j.Property.check(p) && j.Identifier.check(p.key) && p.key.name === 'extraPlugins'
      );

Perhaps some type guard issue?

@Tobbe
Copy link

Tobbe commented Jul 30, 2023

I ran into something similar where I already had useResponseCache configured

export const handler = createGraphQLHandler({
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,
  cors: {
    origin: '*',
    credentials: true,
  },
  extraPlugins:
    process.env.NODE_ENV === 'production'
      ? [useResponseCache({ cache, session: () => null, ...cacheConfig })]
      : [],
  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect()
  },
  extraPlugins: [inngestPlugin],
})

Got an extra extraPlugins at the end

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

No branches or pull requests

2 participants