Skip to content

Commit 8da7dff

Browse files
Mark Molinaroardatan
Mark Molinaro
authored andcommittedMay 18, 2021
Update fragment generation for better TS perf (#5992)
* Update fragment generation for better TS perf * Cleanup * Fix all dev-test
1 parent 95074ba commit 8da7dff

File tree

10 files changed

+142
-456
lines changed

10 files changed

+142
-456
lines changed
 

‎.changeset/tricky-guests-film.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-codegen/visitor-plugin-common': minor
3+
'@graphql-codegen/typescript-document-nodes': minor
4+
---
5+
6+
Skip typechecking on generated values by casting to unknown

‎dev-test/githunt/typed-document-nodes.ts

+22-25
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export type VoteMutation = { __typename?: 'Mutation' } & {
268268
>;
269269
};
270270

271-
export const CommentsPageCommentFragmentDoc: DocumentNode<CommentsPageCommentFragment, unknown> = {
271+
export const CommentsPageCommentFragmentDoc = {
272272
kind: 'Document',
273273
definitions: [
274274
{
@@ -296,8 +296,8 @@ export const CommentsPageCommentFragmentDoc: DocumentNode<CommentsPageCommentFra
296296
},
297297
},
298298
],
299-
};
300-
export const VoteButtonsFragmentDoc: DocumentNode<VoteButtonsFragment, unknown> = {
299+
} as unknown as DocumentNode<CommentsPageCommentFragment, unknown>;
300+
export const VoteButtonsFragmentDoc = {
301301
kind: 'Document',
302302
definitions: [
303303
{
@@ -320,8 +320,8 @@ export const VoteButtonsFragmentDoc: DocumentNode<VoteButtonsFragment, unknown>
320320
},
321321
},
322322
],
323-
};
324-
export const RepoInfoFragmentDoc: DocumentNode<RepoInfoFragment, unknown> = {
323+
} as unknown as DocumentNode<VoteButtonsFragment, unknown>;
324+
export const RepoInfoFragmentDoc = {
325325
kind: 'Document',
326326
definitions: [
327327
{
@@ -359,8 +359,8 @@ export const RepoInfoFragmentDoc: DocumentNode<RepoInfoFragment, unknown> = {
359359
},
360360
},
361361
],
362-
};
363-
export const FeedEntryFragmentDoc: DocumentNode<FeedEntryFragment, unknown> = {
362+
} as unknown as DocumentNode<RepoInfoFragment, unknown>;
363+
export const FeedEntryFragmentDoc = {
364364
kind: 'Document',
365365
definitions: [
366366
{
@@ -399,8 +399,8 @@ export const FeedEntryFragmentDoc: DocumentNode<FeedEntryFragment, unknown> = {
399399
...VoteButtonsFragmentDoc.definitions,
400400
...RepoInfoFragmentDoc.definitions,
401401
],
402-
};
403-
export const OnCommentAddedDocument: DocumentNode<OnCommentAddedSubscription, OnCommentAddedSubscriptionVariables> = {
402+
} as unknown as DocumentNode<FeedEntryFragment, unknown>;
403+
export const OnCommentAddedDocument = {
404404
kind: 'Document',
405405
definitions: [
406406
{
@@ -451,8 +451,8 @@ export const OnCommentAddedDocument: DocumentNode<OnCommentAddedSubscription, On
451451
},
452452
},
453453
],
454-
};
455-
export const CommentDocument: DocumentNode<CommentQuery, CommentQueryVariables> = {
454+
} as unknown as DocumentNode<OnCommentAddedSubscription, OnCommentAddedSubscriptionVariables>;
455+
export const CommentDocument = {
456456
kind: 'Document',
457457
definitions: [
458458
{
@@ -568,11 +568,8 @@ export const CommentDocument: DocumentNode<CommentQuery, CommentQueryVariables>
568568
},
569569
...CommentsPageCommentFragmentDoc.definitions,
570570
],
571-
};
572-
export const CurrentUserForProfileDocument: DocumentNode<
573-
CurrentUserForProfileQuery,
574-
CurrentUserForProfileQueryVariables
575-
> = {
571+
} as unknown as DocumentNode<CommentQuery, CommentQueryVariables>;
572+
export const CurrentUserForProfileDocument = {
576573
kind: 'Document',
577574
definitions: [
578575
{
@@ -597,8 +594,8 @@ export const CurrentUserForProfileDocument: DocumentNode<
597594
},
598595
},
599596
],
600-
};
601-
export const FeedDocument: DocumentNode<FeedQuery, FeedQueryVariables> = {
597+
} as unknown as DocumentNode<CurrentUserForProfileQuery, CurrentUserForProfileQueryVariables>;
598+
export const FeedDocument = {
602599
kind: 'Document',
603600
definitions: [
604601
{
@@ -663,8 +660,8 @@ export const FeedDocument: DocumentNode<FeedQuery, FeedQueryVariables> = {
663660
},
664661
...FeedEntryFragmentDoc.definitions,
665662
],
666-
};
667-
export const SubmitRepositoryDocument: DocumentNode<SubmitRepositoryMutation, SubmitRepositoryMutationVariables> = {
663+
} as unknown as DocumentNode<FeedQuery, FeedQueryVariables>;
664+
export const SubmitRepositoryDocument = {
668665
kind: 'Document',
669666
definitions: [
670667
{
@@ -700,8 +697,8 @@ export const SubmitRepositoryDocument: DocumentNode<SubmitRepositoryMutation, Su
700697
},
701698
},
702699
],
703-
};
704-
export const SubmitCommentDocument: DocumentNode<SubmitCommentMutation, SubmitCommentMutationVariables> = {
700+
} as unknown as DocumentNode<SubmitRepositoryMutation, SubmitRepositoryMutationVariables>;
701+
export const SubmitCommentDocument = {
705702
kind: 'Document',
706703
definitions: [
707704
{
@@ -748,8 +745,8 @@ export const SubmitCommentDocument: DocumentNode<SubmitCommentMutation, SubmitCo
748745
},
749746
...CommentsPageCommentFragmentDoc.definitions,
750747
],
751-
};
752-
export const VoteDocument: DocumentNode<VoteMutation, VoteMutationVariables> = {
748+
} as unknown as DocumentNode<SubmitCommentMutation, SubmitCommentMutationVariables>;
749+
export const VoteDocument = {
753750
kind: 'Document',
754751
definitions: [
755752
{
@@ -806,4 +803,4 @@ export const VoteDocument: DocumentNode<VoteMutation, VoteMutationVariables> = {
806803
},
807804
},
808805
],
809-
};
806+
} as unknown as DocumentNode<VoteMutation, VoteMutationVariables>;

‎package.json

-14
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,9 @@
4141
"@apollo/client": "3.3.19",
4242
"@babel/preset-typescript": "7.13.0",
4343
"@changesets/cli": "2.16.0",
44-
"@graphql-tools/apollo-engine-loader": "6.2.5",
45-
"@graphql-tools/code-file-loader": "6.3.1",
46-
"@graphql-tools/git-loader": "6.2.6",
47-
"@graphql-tools/github-loader": "6.2.5",
48-
"@graphql-tools/graphql-file-loader": "6.2.7",
49-
"@graphql-tools/json-file-loader": "6.2.6",
50-
"@graphql-tools/load": "6.2.8",
51-
"@graphql-tools/prisma-loader": "6.3.0",
52-
"@graphql-tools/url-loader": "6.10.1",
53-
"@graphql-tools/utils": "7.10.0",
5444
"@graphql-typed-document-node/core": "3.1.0",
5545
"@urql/exchange-graphcache": "4.1.1",
5646
"@types/common-tags": "1.8.0",
57-
"@types/glob": "7.1.3",
5847
"@types/jest": "26.0.23",
5948
"@types/mkdirp": "1.0.1",
6049
"@types/node": "14.17.0",
@@ -63,11 +52,8 @@
6352
"@typescript-eslint/parser": "4.24.0",
6453
"@vue/apollo-composable": "4.0.0-alpha.12",
6554
"@vue/composition-api": "0.6.7",
66-
"apollo-cache": "1.3.5",
6755
"apollo-client": "2.6.10",
68-
"apollo-link": "1.2.14",
6956
"apollo-server": "2.24.0",
70-
"apollo-utilities": "1.3.4",
7157
"auto-bind": "4.0.0",
7258
"bob-the-bundler": "1.2.0",
7359
"eslint": "7.26.0",

‎packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ export class ClientSideBaseVisitor<
334334
protected _generateFragment(fragmentDocument: FragmentDefinitionNode): string | void {
335335
const name = this.getFragmentVariableName(fragmentDocument);
336336
const fragmentTypeSuffix = this.getFragmentSuffix(fragmentDocument);
337-
return `export const ${name}${this.getDocumentNodeSignature(
337+
return `export const ${name} =${this.config.pureMagicComment ? ' /*#__PURE__*/' : ''} ${this._gql(
338+
fragmentDocument
339+
)}${this.getDocumentNodeSignature(
338340
this.convertName(fragmentDocument.name.value, {
339341
useTypesPrefix: true,
340342
suffix: fragmentTypeSuffix,
@@ -345,7 +347,7 @@ export class ClientSideBaseVisitor<
345347
})
346348
: 'unknown',
347349
fragmentDocument
348-
)} =${this.config.pureMagicComment ? ' /*#__PURE__*/' : ''} ${this._gql(fragmentDocument)};`;
350+
)};`;
349351
}
350352

351353
private get fragmentsGraph(): DepGraph<LoadedFragment> {
@@ -527,7 +529,7 @@ export class ClientSideBaseVisitor<
527529
this.config.documentMode === DocumentMode.documentNode ||
528530
this.config.documentMode === DocumentMode.documentNodeImportFragments
529531
) {
530-
return `: DocumentNode`;
532+
return ` as unknown as DocumentNode`;
531533
}
532534

533535
return '';
@@ -571,13 +573,9 @@ export class ClientSideBaseVisitor<
571573
if (this.config.documentMode !== DocumentMode.external) {
572574
// only generate exports for named queries
573575
if (documentVariableName !== '') {
574-
documentString = `${
575-
this.config.noExport ? '' : 'export'
576-
} const ${documentVariableName}${this.getDocumentNodeSignature(
577-
operationResultType,
578-
operationVariablesTypes,
579-
node
580-
)} =${this.config.pureMagicComment ? ' /*#__PURE__*/' : ''} ${this._gql(node)};`;
576+
documentString = `${this.config.noExport ? '' : 'export'} const ${documentVariableName} =${
577+
this.config.pureMagicComment ? ' /*#__PURE__*/' : ''
578+
} ${this._gql(node)}${this.getDocumentNodeSignature(operationResultType, operationVariablesTypes, node)};`;
581579
}
582580
}
583581

‎packages/plugins/typescript/document-nodes/tests/graphql-document-nodes.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ describe('graphql-codegen typescript-graphql-document-nodes', () => {
315315
) as Types.ComplexPluginOutput;
316316

317317
expect(result.content).toBeSimilarStringTo(`
318-
export const MyQuery: DocumentNode = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyQuery"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}}]}}]};
318+
export const MyQuery = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyQuery"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}}]}}]} as unknown as DocumentNode;
319319
`);
320320
validateTs(mergeOutputs([result]));
321321
});

‎packages/plugins/typescript/react-apollo/tests/__snapshots__/react-apollo.spec.ts.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,9 @@ export type GetSomethingQueryResult = Apollo.QueryResult<GetSomethingQuery, GetS
777777
`;
778778
779779
exports[`React Apollo documentMode and importDocumentNodeExternallyFrom should generate definitions Document variable when documentMode is "documentNode" and nested fragments 1`] = `
780-
"export const CFieldsFragmentDoc: DocumentNode = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]};
781-
export const BFieldsFragmentDoc: DocumentNode = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"B\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"cs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]};
782-
export const AFieldsFragmentDoc: DocumentNode = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"AFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"A\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"bs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"B\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"cs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]};
783-
export const TestDocument: DocumentNode = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"OperationDefinition\\",\\"operation\\":\\"query\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"Test\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"a\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"AFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"AFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"A\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"bs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"B\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"cs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]};
780+
"export const CFieldsFragmentDoc = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]} as unknown as DocumentNode;
781+
export const BFieldsFragmentDoc = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"B\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"cs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]} as unknown as DocumentNode;
782+
export const AFieldsFragmentDoc = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"AFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"A\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"bs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"B\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"cs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]} as unknown as DocumentNode;
783+
export const TestDocument = {\\"kind\\":\\"Document\\",\\"definitions\\":[{\\"kind\\":\\"OperationDefinition\\",\\"operation\\":\\"query\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"Test\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"a\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"AFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"AFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"A\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"bs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"BFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"B\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"cs\\"},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"FragmentSpread\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"}}]}}]}},{\\"kind\\":\\"FragmentDefinition\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"CFields\\"},\\"typeCondition\\":{\\"kind\\":\\"NamedType\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"C\\"}},\\"selectionSet\\":{\\"kind\\":\\"SelectionSet\\",\\"selections\\":[{\\"kind\\":\\"Field\\",\\"name\\":{\\"kind\\":\\"Name\\",\\"value\\":\\"greeting\\"}}]}}]} as unknown as DocumentNode;
784784
export type TestQueryResult = Apollo.QueryResult<TestQuery, TestQueryVariables>;"
785785
`;

‎packages/plugins/typescript/react-apollo/tests/react-apollo.spec.ts

+66-50
Original file line numberDiff line numberDiff line change
@@ -447,36 +447,44 @@ describe('React Apollo', () => {
447447
((await plugin(schema, [{ location: 'test-file.ts', document: ast }], {}, { outputFile: '' })) as any).content
448448
).toContain('Apollo.QueryResult<NotificationsQueryQuery, NotificationsQueryQueryVariables>;');
449449
expect(
450-
((await plugin(
451-
schema,
452-
[{ location: 'test-file.ts', document: ast }],
453-
{ dedupeOperationSuffix: false },
454-
{ outputFile: '' }
455-
)) as any).content
450+
(
451+
(await plugin(
452+
schema,
453+
[{ location: 'test-file.ts', document: ast }],
454+
{ dedupeOperationSuffix: false },
455+
{ outputFile: '' }
456+
)) as any
457+
).content
456458
).toContain('Apollo.QueryResult<NotificationsQueryQuery, NotificationsQueryQueryVariables>');
457459
expect(
458-
((await plugin(
459-
schema,
460-
[{ location: 'test-file.ts', document: ast }],
461-
{ dedupeOperationSuffix: true },
462-
{ outputFile: '' }
463-
)) as any).content
460+
(
461+
(await plugin(
462+
schema,
463+
[{ location: 'test-file.ts', document: ast }],
464+
{ dedupeOperationSuffix: true },
465+
{ outputFile: '' }
466+
)) as any
467+
).content
464468
).toContain('Apollo.QueryResult<NotificationsQuery, NotificationsQueryVariables>');
465469
expect(
466-
((await plugin(
467-
schema,
468-
[{ location: 'test-file.ts', document: ast2 }],
469-
{ dedupeOperationSuffix: true },
470-
{ outputFile: '' }
471-
)) as any).content
470+
(
471+
(await plugin(
472+
schema,
473+
[{ location: 'test-file.ts', document: ast2 }],
474+
{ dedupeOperationSuffix: true },
475+
{ outputFile: '' }
476+
)) as any
477+
).content
472478
).toContain('Apollo.QueryResult<NotificationsQuery, NotificationsQueryVariables>');
473479
expect(
474-
((await plugin(
475-
schema,
476-
[{ location: 'test-file.ts', document: ast2 }],
477-
{ dedupeOperationSuffix: false },
478-
{ outputFile: '' }
479-
)) as any).content
480+
(
481+
(await plugin(
482+
schema,
483+
[{ location: 'test-file.ts', document: ast2 }],
484+
{ dedupeOperationSuffix: false },
485+
{ outputFile: '' }
486+
)) as any
487+
).content
480488
).toContain('Apollo.QueryResult<NotificationsQuery, NotificationsQueryVariables>');
481489
});
482490

@@ -500,36 +508,44 @@ describe('React Apollo', () => {
500508
((await plugin(schema, [{ location: 'test-file.ts', document: ast }], {}, { outputFile: '' })) as any).content
501509
).toContain('Apollo.QueryResult<NotificationsQueryQuery, NotificationsQueryQueryVariables>;');
502510
expect(
503-
((await plugin(
504-
schema,
505-
[{ location: 'test-file.ts', document: ast }],
506-
{ omitOperationSuffix: false },
507-
{ outputFile: '' }
508-
)) as any).content
511+
(
512+
(await plugin(
513+
schema,
514+
[{ location: 'test-file.ts', document: ast }],
515+
{ omitOperationSuffix: false },
516+
{ outputFile: '' }
517+
)) as any
518+
).content
509519
).toContain('Apollo.QueryResult<NotificationsQueryQuery, NotificationsQueryQueryVariables>');
510520
expect(
511-
((await plugin(
512-
schema,
513-
[{ location: 'test-file.ts', document: ast }],
514-
{ omitOperationSuffix: true },
515-
{ outputFile: '' }
516-
)) as any).content
521+
(
522+
(await plugin(
523+
schema,
524+
[{ location: 'test-file.ts', document: ast }],
525+
{ omitOperationSuffix: true },
526+
{ outputFile: '' }
527+
)) as any
528+
).content
517529
).toContain('Apollo.QueryResult<NotificationsQuery, NotificationsQueryVariables>');
518530
expect(
519-
((await plugin(
520-
schema,
521-
[{ location: 'test-file.ts', document: ast2 }],
522-
{ omitOperationSuffix: true },
523-
{ outputFile: '' }
524-
)) as any).content
531+
(
532+
(await plugin(
533+
schema,
534+
[{ location: 'test-file.ts', document: ast2 }],
535+
{ omitOperationSuffix: true },
536+
{ outputFile: '' }
537+
)) as any
538+
).content
525539
).toContain('Apollo.QueryResult<Notifications, NotificationsVariables>');
526540
expect(
527-
((await plugin(
528-
schema,
529-
[{ location: 'test-file.ts', document: ast2 }],
530-
{ omitOperationSuffix: false },
531-
{ outputFile: '' }
532-
)) as any).content
541+
(
542+
(await plugin(
543+
schema,
544+
[{ location: 'test-file.ts', document: ast2 }],
545+
{ omitOperationSuffix: false },
546+
{ outputFile: '' }
547+
)) as any
548+
).content
533549
).toContain('Apollo.QueryResult<NotificationsQuery, NotificationsQueryVariables>');
534550
});
535551

@@ -825,7 +841,7 @@ query MyFeed {
825841
)) as Types.ComplexPluginOutput;
826842

827843
expect(content.content).toBeSimilarStringTo(
828-
`export const TestDocument: DocumentNode = {"kind":"Document","defin`
844+
`[{"kind":"Field","name":{"kind":"Name","value":"avatar_url"}}]}}]}}]}}]}}]} as unknown as DocumentNode;`
829845
);
830846

831847
// For issue #1599 - make sure there are not `loc` properties
@@ -1796,7 +1812,7 @@ export function useListenToCommentsSubscription(baseOptions?: Apollo.Subscriptio
17961812
)) as Types.ComplexPluginOutput;
17971813

17981814
expect(content.content).toBeSimilarStringTo(
1799-
`export const TestDocument: DocumentNode = {"kind":"Document","defin`
1815+
`[{"kind":"Field","name":{"kind":"Name","value":"avatar_url"}}]}}]}}]}}]}}]} as unknown as DocumentNode;`
18001816
);
18011817

18021818
// For issue #1599 - make sure there are not `loc` properties

‎packages/plugins/typescript/typed-document-node/src/visitor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor<
4747
this.config.documentMode === DocumentMode.documentNodeImportFragments ||
4848
this.config.documentMode === DocumentMode.graphQLTag
4949
) {
50-
return `: DocumentNode<${resultType}, ${variablesTypes}>`;
50+
return ` as unknown as DocumentNode<${resultType}, ${variablesTypes}>`;
5151
}
5252

5353
return super.getDocumentNodeSignature(resultType, variablesTypes, node);

‎packages/plugins/typescript/urql/tests/urql.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ query MyFeed {
345345
)) as Types.ComplexPluginOutput;
346346

347347
expect(content.content).toBeSimilarStringTo(
348-
`export const TestDocument: DocumentNode = {"kind":"Document","defin`
348+
`[{"kind":"Field","name":{"kind":"Name","value":"avatar_url"}}]}}]}}]}}]}}]} as unknown as DocumentNode;`
349349
);
350350

351351
// For issue #1599 - make sure there are not `loc` properties

‎yarn.lock

+33-350
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.