diff --git a/packages/knip/fixtures/plugins/graphql-codegen/codegen.ts b/packages/knip/fixtures/plugins/graphql-codegen/codegen.ts index 7b0b091b7..fdb82ab84 100644 --- a/packages/knip/fixtures/plugins/graphql-codegen/codegen.ts +++ b/packages/knip/fixtures/plugins/graphql-codegen/codegen.ts @@ -3,13 +3,14 @@ module.exports = { overwrite: true, generates: { './graphql.schema.json': { - plugins: ['introspection'], + plugins: ['introspection', 'graphql-codegen-typescript-validation-schema'], }, './graphql.schema.graphql': { 'schema-ast': {}, }, './src/generated/graphql.ts': { documents: ['./src/**/*.tsx'], + preset: '@graphql-codegen/graphql-modules-preset', plugins: ['typescript', 'typescript-operations', 'typescript-urql'], }, './lib/': { diff --git a/packages/knip/src/plugins/graphql-codegen/index.ts b/packages/knip/src/plugins/graphql-codegen/index.ts index 502dec661..26a4c166a 100644 --- a/packages/knip/src/plugins/graphql-codegen/index.ts +++ b/packages/knip/src/plugins/graphql-codegen/index.ts @@ -54,12 +54,20 @@ const resolveConfig: ResolveConfig (configOutput.preset ? configOutput.preset : undefined)) .filter((preset): preset is PresetNames => typeof preset === 'string') - .map(presetName => `@graphql-codegen/${presetName}${presetName.endsWith('-preset') ? '' : '-preset'}`); + .map(presetName => + // https://github.com/dotansimha/graphql-code-generator/blob/master/packages/graphql-codegen-cli/src/presets.ts#L8-L11 + presetName.startsWith('@graphql-codegen/') + ? presetName + : `@graphql-codegen/${presetName}${presetName.endsWith('-preset') ? '' : '-preset'}` + ); const flatPlugins = generateSet .filter((config): config is ConfiguredPlugin => !isConfigurationOutput(config)) .flatMap(item => Object.keys(item)) - .map(plugin => `@graphql-codegen/${plugin}`); + .map(plugin => + // https://github.com/dotansimha/graphql-code-generator/blob/master/packages/graphql-codegen-cli/src/plugins.ts#L8-L18 + plugin.includes('codegen-') ? plugin : `@graphql-codegen/${plugin}` + ); const nestedPlugins = configurationOutput .flatMap(configOutput => (configOutput.plugins ? configOutput.plugins : [])) @@ -70,7 +78,7 @@ const resolveConfig: ResolveConfig { if (typeof plugin !== 'string') return []; if (isInternal(plugin)) return [toEntryPattern(plugin)]; - return [`@graphql-codegen/${plugin}`]; + return [plugin.includes('codegen-') ? plugin : `@graphql-codegen/${plugin}`]; }); return [...presets, ...flatPlugins, ...nestedPlugins]; diff --git a/packages/knip/test/plugins/graphql-codegen.test.ts b/packages/knip/test/plugins/graphql-codegen.test.ts index 165d1f918..24b603ed5 100644 --- a/packages/knip/test/plugins/graphql-codegen.test.ts +++ b/packages/knip/test/plugins/graphql-codegen.test.ts @@ -20,6 +20,8 @@ test('Find dependencies with the graphql-codegen plugin (codegen.ts function)', assert(issues.unlisted['codegen.ts']['@graphql-codegen/typescript-operations']); assert(issues.unlisted['codegen.ts']['@graphql-codegen/typescript-urql']); assert(issues.unlisted['codegen.ts']['@graphql-codegen/typescript-msw']); + assert(issues.unlisted['codegen.ts']['@graphql-codegen/graphql-modules-preset']); + assert(issues.unlisted['codegen.ts']['graphql-codegen-typescript-validation-schema']); assert(issues.unlisted['codegen.yaml']['@graphql-codegen/add']); assert(issues.unlisted['codegen.yaml']['@graphql-codegen/typescript']); @@ -31,7 +33,7 @@ test('Find dependencies with the graphql-codegen plugin (codegen.ts function)', assert.deepEqual(counters, { ...baseCounters, - unlisted: 13, + unlisted: 15, processed: 1, total: 1, });