@@ -748,10 +748,10 @@ export * from "./gql";`);
748
748
expect ( result ) . toHaveLength ( 4 ) ;
749
749
const gqlFile = result . find ( file => file . filename === 'out1/fragment-masking.ts' ) ;
750
750
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';
752
752
753
753
754
- export type FragmentType<TDocumentType extends DocumentNode <any, any>> = TDocumentType extends DocumentNode <
754
+ export type FragmentType<TDocumentType extends DocumentTypeDecoration <any, any>> = TDocumentType extends DocumentTypeDecoration <
755
755
infer TType,
756
756
any
757
757
>
@@ -764,34 +764,34 @@ export * from "./gql";`);
764
764
765
765
// return non-nullable if \`fragmentType\` is non-nullable
766
766
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>>
769
769
): TType;
770
770
// return nullable if \`fragmentType\` is nullable
771
771
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
774
774
): TType | null | undefined;
775
775
// return array of non-nullable if \`fragmentType\` is array of non-nullable
776
776
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>>>
779
779
): ReadonlyArray<TType>;
780
780
// return array of nullable if \`fragmentType\` is array of nullable
781
781
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
784
784
): ReadonlyArray<TType> | null | undefined;
785
785
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
788
788
): TType | ReadonlyArray<TType> | null | undefined {
789
789
return fragmentType as any;
790
790
}
791
791
792
792
793
793
export function makeFragmentData<
794
- F extends DocumentNode ,
794
+ F extends DocumentTypeDecoration<any, any> ,
795
795
FT extends ResultOf<F>
796
796
>(data: FT, _fragment: F): FragmentType<F> {
797
797
return data as FragmentType<F>;
@@ -800,32 +800,32 @@ export * from "./gql";`);
800
800
801
801
expect ( gqlFile . content ) . toBeSimilarStringTo ( `
802
802
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>>
805
805
): TType;
806
806
` ) ;
807
807
expect ( gqlFile . content ) . toBeSimilarStringTo ( `
808
808
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
811
811
): TType | null | undefined;
812
812
` ) ;
813
813
expect ( gqlFile . content ) . toBeSimilarStringTo ( `
814
814
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>>>
817
817
): ReadonlyArray<TType>;
818
818
` ) ;
819
819
expect ( gqlFile . content ) . toBeSimilarStringTo ( `
820
820
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
823
823
): ReadonlyArray<TType> | null | undefined;
824
824
` ) ;
825
825
expect ( gqlFile . content ) . toBeSimilarStringTo ( `
826
826
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
829
829
): TType | ReadonlyArray<TType> | null | undefined {
830
830
return fragmentType as any;
831
831
}
@@ -1708,35 +1708,6 @@ export * from "./gql.js";`);
1708
1708
` ) ;
1709
1709
} ) ;
1710
1710
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
-
1740
1711
it ( 'graphql overloads have a nice result type' , async ( ) => {
1741
1712
const result = await executeCodegen ( {
1742
1713
schema : [
@@ -1765,6 +1736,26 @@ export * from "./gql.js";`);
1765
1736
const gqlFile = result . find ( file => file . filename === 'out1/gql.ts' ) ;
1766
1737
expect ( gqlFile . content ) . toMatchInlineSnapshot ( `
1767
1738
"/* 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
+
1768
1759
/**
1769
1760
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
1770
1761
*/
@@ -1779,7 +1770,10 @@ export * from "./gql.js";`);
1779
1770
export function graphql(source: "\\n fragment Foo on Foo {\\n value\\n }\\n"): typeof import('./graphql').FooFragmentDoc;
1780
1771
1781
1772
1782
- export function graphql(source: string): string { return source; }"
1773
+ export function graphql(source: string) {
1774
+ return (documents as any)[source] ?? {};
1775
+ }
1776
+ "
1783
1777
` ) ;
1784
1778
} ) ;
1785
1779
} ) ;
0 commit comments