Skip to content

Commit

Permalink
fix(vue-apollo): regression, respect omitOperationSuffix even with de…
Browse files Browse the repository at this point in the history
…dupeOperationSuffix enabled (#5015)

* fix(vue-apollo): regression, respect omitOperationSuffix even with dedupeOperationSuffix enabled

* updated changeset

* fix changeset

Co-authored-by: Dotan Simha <dotansimha@gmail.com>
  • Loading branch information
JoeSchr and dotansimha committed Nov 4, 2020
1 parent 7610ce6 commit b83668d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/empty-dragons-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-vue-apollo': patch
---

Fix regression so omitOperationSuffix is respected again
2 changes: 1 addition & 1 deletion packages/plugins/typescript/vue-apollo/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class VueApolloVisitor extends ClientSideBaseVisitor<VueApolloRawPluginCo

private getCompositionFunctionSuffix(name: string, operationType: string) {
if (!this.config.dedupeOperationSuffix) {
return pascalCase(operationType);
return this.config.omitOperationSuffix ? '' : pascalCase(operationType);
}
if (name.includes('Query') || name.includes('Mutation') || name.includes('Subscription')) {
return '';
Expand Down
76 changes: 76 additions & 0 deletions packages/plugins/typescript/vue-apollo/tests/vue-apollo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,64 @@ query MyFeed {
await validateTypeScript(content, schema, docs, {});
});

it(`Should respect omitOperationSuffix and generate type omitted composition functions`, async () => {
const documentWithHardcodedQuerySuffix = parse(/* GraphQL */ `
query notificationsQuery {
notifications {
id
}
}
`);
const documentNoQuerySuffix = parse(/* GraphQL */ `
query notifications {
notifications {
id
}
}
`);

expect(
((await plugin(
schema,
[{ location: 'test-file.ts', document: documentWithHardcodedQuerySuffix }],
{},
{ outputFile: '' }
)) as any).content
).toContain('type NotificationsQueryQueryCompositionFunctionResult');
expect(
((await plugin(
schema,
[{ location: 'test-file.ts', document: documentWithHardcodedQuerySuffix }],
{ omitOperationSuffix: false },
{ outputFile: '' }
)) as any).content
).toContain('type NotificationsQueryQueryCompositionFunctionResult');
expect(
((await plugin(
schema,
[{ location: 'test-file.ts', document: documentWithHardcodedQuerySuffix }],
{ omitOperationSuffix: true },
{ outputFile: '' }
)) as any).content
).toContain('type NotificationsQueryCompositionFunctionResult');
expect(
((await plugin(
schema,
[{ location: 'test-file.ts', document: documentNoQuerySuffix }],
{ omitOperationSuffix: true },
{ outputFile: '' }
)) as any).content
).toContain('type NotificationsCompositionFunctionResult');
expect(
((await plugin(
schema,
[{ location: 'test-file.ts', document: documentNoQuerySuffix }],
{ omitOperationSuffix: false },
{ outputFile: '' }
)) as any).content
).toContain('type NotificationsQueryCompositionFunctionResult');
});

it('Should generate deduped composition functions for query and mutation', async () => {
const documents = parse(/* GraphQL */ `
query FeedQuery {
Expand Down Expand Up @@ -502,6 +560,24 @@ query MyFeed {
await validateTypeScript(content, schema, docs, {});
});

it(`Should generate deduped and type omitted compositions functions`, async () => {
const documentWithQuerySuffix = parse(/* GraphQL */ `
query notificationsQuery {
notifications {
id
}
}
`);
expect(
((await plugin(
schema,
[{ location: 'test-file.ts', document: documentWithQuerySuffix }],
{ omitOperationSuffix: true, dedupeOperationSuffix: true },
{ outputFile: '' }
)) as any).content
).toContain('type NotificationsQueryCompositionFunctionResult');
});

it('Should not generate composition functions for query and mutation', async () => {
const docs = [{ location: '', document: basicDoc }];
const content = (await plugin(
Expand Down

0 comments on commit b83668d

Please sign in to comment.