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

Fix options getting swallowed by client preset #9496

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 4 additions & 21 deletions packages/presets/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,6 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {

const reexports: Array<string> = [];

// the `client` preset is restricting the config options inherited from `typescript`, `typescript-operations` and others.
const forwardedConfig = {
scalars: options.config.scalars,
defaultScalarType: options.config.defaultScalarType,
strictScalars: options.config.strictScalars,
namingConvention: options.config.namingConvention,
useTypeImports: options.config.useTypeImports,
skipTypename: options.config.skipTypename,
arrayInputCoercion: options.config.arrayInputCoercion,
enumsAsTypes: options.config.enumsAsTypes,
dedupeFragments: options.config.dedupeFragments,
nonOptionalTypename: options.config.nonOptionalTypename,
avoidOptionals: options.config.avoidOptionals,
documentMode: options.config.documentMode,
};

const visitor = new ClientSideBaseVisitor(options.schemaAst!, [], options.config, options.config);
let fragmentMaskingConfig: FragmentMaskingConfig | null = null;

Expand Down Expand Up @@ -252,9 +236,8 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
],
schema: options.schema,
config: {
useTypeImports: options.config.useTypeImports,
...options.config,
unmaskFunctionName: fragmentMaskingConfig.unmaskFunctionName,
emitLegacyCommonJSImports: options.config.emitLegacyCommonJSImports,
isStringDocumentMode: options.config.documentMode === DocumentMode.string,
},
documents: [],
Expand Down Expand Up @@ -283,7 +266,7 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
},
],
schema: options.schema,
config: {},
config,
documents: [],
documentTransforms: options.documentTransforms,
};
Expand All @@ -296,8 +279,8 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
pluginMap,
schema: options.schema,
config: {
...options.config,
inlineFragmentTypes: isMaskingFragments ? 'mask' : options.config['inlineFragmentTypes'],
...forwardedConfig,
},
documents: sources,
documentTransforms: options.documentTransforms,
Expand Down Expand Up @@ -334,7 +317,7 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
},
},
schema: options.schema,
config: {},
config,
documents: sources,
documentTransforms: options.documentTransforms,
},
Expand Down
26 changes: 26 additions & 0 deletions packages/presets/client/tests/client-preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2513,4 +2513,30 @@ export * from "./gql.js";`);
`);
});
});

// Note: The main test for "dedupeOperationSuffix" happens elsewhere. This is just a regression test to verify that
// the preset doesn't fundamentally break it.
it('Test for dedupeOperationSuffix', async () => {
const result = await executeCodegen({
schema: [
/* GraphQL */ `
type Query {
a: String
}
`,
],
documents: path.join(__dirname, 'fixtures/operation-suffix.ts'),
generates: {
'out1/': {
preset,
config: {
dedupeOperationSuffix: true,
},
},
},
});

const graphqlFile = result.find(file => file.filename === 'out1/graphql.ts');
expect(graphqlFile.content).toContain('export type SomeQuery =');
});
});
10 changes: 10 additions & 0 deletions packages/presets/client/tests/fixtures/operation-suffix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
//@ts-ignore
import gql from 'gql-tag';

//@ts-ignore
const A = gql(/* GraphQL */ `
query someQuery {
a
}
`);