1- import { Types } from '@graphql-codegen/plugin-helpers' ;
1+ import { mergeOutputs , Types } from '@graphql-codegen/plugin-helpers' ;
2+ import { DocumentMode } from '@graphql-codegen/visitor-plugin-common' ;
23import { buildSchema , parse } from 'graphql' ;
34import { plugin } from '../src/index.js' ;
45
@@ -9,6 +10,77 @@ describe('TypedDocumentNode', () => {
910 expect ( result . prepend . length ) . toBe ( 0 ) ;
1011 } ) ;
1112
13+ it ( 'dedupes fragments automatically when documentMode=graphQLTag' , async ( ) => {
14+ const schema = buildSchema ( /* GraphQL */ `
15+ type Query {
16+ person(id: ID!): Person!
17+ }
18+ type Person {
19+ id: ID!
20+ name: String!
21+ children: [Person!]
22+ }
23+ ` ) ;
24+
25+ const document = parse ( /* GraphQL */ `
26+ query Person {
27+ person(id: 1) {
28+ ...PersonDetails
29+ children {
30+ ...BasePersonDetails
31+ }
32+ }
33+ }
34+
35+ fragment PersonDetails on Person {
36+ ...BasePersonDetails
37+ name
38+ }
39+
40+ fragment BasePersonDetails on Person {
41+ id
42+ }
43+ ` ) ;
44+
45+ const result = mergeOutputs ( [
46+ await plugin (
47+ schema ,
48+ [ { document } ] ,
49+ {
50+ documentMode : DocumentMode . graphQLTag ,
51+ } ,
52+ { outputFile : '' }
53+ ) ,
54+ ] ) ;
55+
56+ expect ( result ) . toMatchInlineSnapshot ( `
57+ "import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
58+ import gql from 'graphql-tag';
59+ export const BasePersonDetailsFragmentDoc = gql\`
60+ fragment BasePersonDetails on Person {
61+ id
62+ }
63+ \` as unknown as DocumentNode<BasePersonDetailsFragment, unknown>;
64+ export const PersonDetailsFragmentDoc = gql\`
65+ fragment PersonDetails on Person {
66+ ...BasePersonDetails
67+ name
68+ }
69+ \` as unknown as DocumentNode<PersonDetailsFragment, unknown>;
70+ export const PersonDocument = gql\`
71+ query Person {
72+ person(id: 1) {
73+ ...PersonDetails
74+ children {
75+ ...BasePersonDetails
76+ }
77+ }
78+ }
79+ \${PersonDetailsFragmentDoc}
80+ \${BasePersonDetailsFragmentDoc}\` as unknown as DocumentNode<PersonQuery, PersonQueryVariables>;"
81+ ` ) ;
82+ } ) ;
83+
1284 describe ( 'addTypenameToSelectionSets' , ( ) => {
1385 it ( 'Check is add __typename to typed document' , async ( ) => {
1486 const schema = buildSchema ( /* GraphQL */ `
0 commit comments