@@ -748,10 +748,10 @@ export * from "./gql";`);
748748 expect ( result ) . toHaveLength ( 4 ) ;
749749 const gqlFile = result . find ( file => file . filename === 'out1/fragment-masking.ts' ) ;
750750 expect ( gqlFile . content ) . toMatchInlineSnapshot ( `
751- "import { ResultOf, TypedDocumentNode as DocumentNode , } from '@graphql-typed-document-node/core';
751+ "import { ResultOf, DocumentTypeDecoration , } from '@graphql-typed-document-node/core';
752752
753753
754- export type FragmentType<TDocumentType extends DocumentNode <any, any>> = TDocumentType extends DocumentNode <
754+ export type FragmentType<TDocumentType extends DocumentTypeDecoration <any, any>> = TDocumentType extends DocumentTypeDecoration <
755755 infer TType,
756756 any
757757 >
@@ -764,34 +764,34 @@ export * from "./gql";`);
764764
765765 // return non-nullable if \`fragmentType\` is non-nullable
766766 export function iLikeTurtles<TType>(
767- _documentNode: DocumentNode <TType, any>,
768- fragmentType: FragmentType<DocumentNode <TType, any>>
767+ _documentNode: DocumentTypeDecoration <TType, any>,
768+ fragmentType: FragmentType<DocumentTypeDecoration <TType, any>>
769769 ): TType;
770770 // return nullable if \`fragmentType\` is nullable
771771 export function iLikeTurtles<TType>(
772- _documentNode: DocumentNode <TType, any>,
773- fragmentType: FragmentType<DocumentNode <TType, any>> | null | undefined
772+ _documentNode: DocumentTypeDecoration <TType, any>,
773+ fragmentType: FragmentType<DocumentTypeDecoration <TType, any>> | null | undefined
774774 ): TType | null | undefined;
775775 // return array of non-nullable if \`fragmentType\` is array of non-nullable
776776 export function iLikeTurtles<TType>(
777- _documentNode: DocumentNode <TType, any>,
778- fragmentType: ReadonlyArray<FragmentType<DocumentNode <TType, any>>>
777+ _documentNode: DocumentTypeDecoration <TType, any>,
778+ fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration <TType, any>>>
779779 ): ReadonlyArray<TType>;
780780 // return array of nullable if \`fragmentType\` is array of nullable
781781 export function iLikeTurtles<TType>(
782- _documentNode: DocumentNode <TType, any>,
783- fragmentType: ReadonlyArray<FragmentType<DocumentNode <TType, any>>> | null | undefined
782+ _documentNode: DocumentTypeDecoration <TType, any>,
783+ fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration <TType, any>>> | null | undefined
784784 ): ReadonlyArray<TType> | null | undefined;
785785 export function iLikeTurtles<TType>(
786- _documentNode: DocumentNode <TType, any>,
787- fragmentType: FragmentType<DocumentNode <TType, any>> | ReadonlyArray<FragmentType<DocumentNode <TType, any>>> | null | undefined
786+ _documentNode: DocumentTypeDecoration <TType, any>,
787+ fragmentType: FragmentType<DocumentTypeDecoration <TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration <TType, any>>> | null | undefined
788788 ): TType | ReadonlyArray<TType> | null | undefined {
789789 return fragmentType as any;
790790 }
791791
792792
793793 export function makeFragmentData<
794- F extends DocumentNode ,
794+ F extends DocumentTypeDecoration<any, any> ,
795795 FT extends ResultOf<F>
796796 >(data: FT, _fragment: F): FragmentType<F> {
797797 return data as FragmentType<F>;
@@ -800,32 +800,32 @@ export * from "./gql";`);
800800
801801 expect ( gqlFile . content ) . toBeSimilarStringTo ( `
802802 export function iLikeTurtles<TType>(
803- _documentNode: DocumentNode <TType, any>,
804- fragmentType: FragmentType<DocumentNode <TType, any>>
803+ _documentNode: DocumentTypeDecoration <TType, any>,
804+ fragmentType: FragmentType<DocumentTypeDecoration <TType, any>>
805805 ): TType;
806806 ` ) ;
807807 expect ( gqlFile . content ) . toBeSimilarStringTo ( `
808808 export function iLikeTurtles<TType>(
809- _documentNode: DocumentNode <TType, any>,
810- fragmentType: FragmentType<DocumentNode <TType, any>> | null | undefined
809+ _documentNode: DocumentTypeDecoration <TType, any>,
810+ fragmentType: FragmentType<DocumentTypeDecoration <TType, any>> | null | undefined
811811 ): TType | null | undefined;
812812 ` ) ;
813813 expect ( gqlFile . content ) . toBeSimilarStringTo ( `
814814 export function iLikeTurtles<TType>(
815- _documentNode: DocumentNode <TType, any>,
816- fragmentType: ReadonlyArray<FragmentType<DocumentNode <TType, any>>>
815+ _documentNode: DocumentTypeDecoration <TType, any>,
816+ fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration <TType, any>>>
817817 ): ReadonlyArray<TType>;
818818 ` ) ;
819819 expect ( gqlFile . content ) . toBeSimilarStringTo ( `
820820 export function iLikeTurtles<TType>(
821- _documentNode: DocumentNode <TType, any>,
822- fragmentType: ReadonlyArray<FragmentType<DocumentNode <TType, any>>> | null | undefined
821+ _documentNode: DocumentTypeDecoration <TType, any>,
822+ fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration <TType, any>>> | null | undefined
823823 ): ReadonlyArray<TType> | null | undefined;
824824 ` ) ;
825825 expect ( gqlFile . content ) . toBeSimilarStringTo ( `
826826 export function iLikeTurtles<TType>(
827- _documentNode: DocumentNode <TType, any>,
828- fragmentType: FragmentType<DocumentNode <TType, any>> | ReadonlyArray<FragmentType<DocumentNode <TType, any>>> | null | undefined
827+ _documentNode: DocumentTypeDecoration <TType, any>,
828+ fragmentType: FragmentType<DocumentTypeDecoration <TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration <TType, any>>> | null | undefined
829829 ): TType | ReadonlyArray<TType> | null | undefined {
830830 return fragmentType as any;
831831 }
@@ -1708,35 +1708,6 @@ export * from "./gql.js";`);
17081708 ` ) ;
17091709 } ) ;
17101710
1711- it ( 'does not include documents dictionary' , async ( ) => {
1712- const result = await executeCodegen ( {
1713- schema : [
1714- /* GraphQL */ `
1715- type Query {
1716- foo: Foo
1717- foos: [Foo]
1718- }
1719-
1720- type Foo {
1721- value: String
1722- }
1723- ` ,
1724- ] ,
1725- documents : path . join ( __dirname , 'fixtures/with-fragment.ts' ) ,
1726- generates : {
1727- 'out1/' : {
1728- preset,
1729- config : {
1730- documentMode : 'string' ,
1731- } ,
1732- } ,
1733- } ,
1734- } ) ;
1735-
1736- const gqlFile = result . find ( file => file . filename === 'out1/gql.ts' ) ;
1737- expect ( gqlFile . content ) . not . toContain ( 'const documents = {' ) ;
1738- } ) ;
1739-
17401711 it ( 'graphql overloads have a nice result type' , async ( ) => {
17411712 const result = await executeCodegen ( {
17421713 schema : [
@@ -1765,6 +1736,26 @@ export * from "./gql.js";`);
17651736 const gqlFile = result . find ( file => file . filename === 'out1/gql.ts' ) ;
17661737 expect ( gqlFile . content ) . toMatchInlineSnapshot ( `
17671738 "/* eslint-disable */
1739+ import * as types from './graphql';
1740+
1741+
1742+
1743+ /**
1744+ * Map of all GraphQL operations in the project.
1745+ *
1746+ * This map has several performance disadvantages:
1747+ * 1. It is not tree-shakeable, so it will include all operations in the project.
1748+ * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1749+ * 3. It does not support dead code elimination, so it will add unused operations.
1750+ *
1751+ * Therefore it is highly recommended to use the babel or swc plugin for production.
1752+ */
1753+ const documents = {
1754+ "\\n query Foo {\\n foo {\\n ...Foo\\n }\\n }\\n": types.FooDocument,
1755+ "\\n query Foos {\\n foos {\\n ...Foo\\n }\\n }\\n": types.FoosDocument,
1756+ "\\n fragment Foo on Foo {\\n value\\n }\\n": types.FooFragmentDoc,
1757+ };
1758+
17681759 /**
17691760 * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
17701761 */
@@ -1779,7 +1770,10 @@ export * from "./gql.js";`);
17791770 export function graphql(source: "\\n fragment Foo on Foo {\\n value\\n }\\n"): typeof import('./graphql').FooFragmentDoc;
17801771
17811772
1782- export function graphql(source: string): string { return source; }"
1773+ export function graphql(source: string) {
1774+ return (documents as any)[source] ?? {};
1775+ }
1776+ "
17831777 ` ) ;
17841778 } ) ;
17851779 } ) ;
0 commit comments