Open dthyresson opened 1 year ago
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.
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?
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
If the GraphQLHandler is:
where
extraPlugins: [inngestPlugin],
is already set, re-running and forcing the plugin setup duplicates: