diff --git a/dev-test/general/gql-tag-operations-masking/gql/fragment-masking.ts b/dev-test/general/gql-tag-operations-masking/gql/fragment-masking.ts index 5f31332416f..749b250a4de 100644 --- a/dev-test/general/gql-tag-operations-masking/gql/fragment-masking.ts +++ b/dev-test/general/gql-tag-operations-masking/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/dev-test/general/gql-tag-operations-urql/gql/fragment-masking.ts b/dev-test/general/gql-tag-operations-urql/gql/fragment-masking.ts index 5f31332416f..749b250a4de 100644 --- a/dev-test/general/gql-tag-operations-urql/gql/fragment-masking.ts +++ b/dev-test/general/gql-tag-operations-urql/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/dev-test/general/gql-tag-operations/gql/fragment-masking.ts b/dev-test/general/gql-tag-operations/gql/fragment-masking.ts index 5f31332416f..749b250a4de 100644 --- a/dev-test/general/gql-tag-operations/gql/fragment-masking.ts +++ b/dev-test/general/gql-tag-operations/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/dev-test/general/gql-tag-operations/graphql/fragment-masking.ts b/dev-test/general/gql-tag-operations/graphql/fragment-masking.ts index 5f31332416f..749b250a4de 100644 --- a/dev-test/general/gql-tag-operations/graphql/fragment-masking.ts +++ b/dev-test/general/gql-tag-operations/graphql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts b/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts index b0d34a36d2f..1056e81bdf3 100644 --- a/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts +++ b/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts @@ -11,11 +11,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/persisted-documents/src/gql/fragment-masking.ts b/examples/persisted-documents/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/persisted-documents/src/gql/fragment-masking.ts +++ b/examples/persisted-documents/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/react/apollo-client-defer/src/gql/fragment-masking.ts b/examples/react/apollo-client-defer/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/react/apollo-client-defer/src/gql/fragment-masking.ts +++ b/examples/react/apollo-client-defer/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/react/apollo-client/src/gql/fragment-masking.ts b/examples/react/apollo-client/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/react/apollo-client/src/gql/fragment-masking.ts +++ b/examples/react/apollo-client/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/react/http-executor/src/gql/fragment-masking.ts b/examples/react/http-executor/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/react/http-executor/src/gql/fragment-masking.ts +++ b/examples/react/http-executor/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/react/tanstack-react-query/src/gql/fragment-masking.ts b/examples/react/tanstack-react-query/src/gql/fragment-masking.ts index b0d34a36d2f..1056e81bdf3 100644 --- a/examples/react/tanstack-react-query/src/gql/fragment-masking.ts +++ b/examples/react/tanstack-react-query/src/gql/fragment-masking.ts @@ -11,11 +11,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/react/urql/src/gql/fragment-masking.ts b/examples/react/urql/src/gql/fragment-masking.ts index b0d34a36d2f..1056e81bdf3 100644 --- a/examples/react/urql/src/gql/fragment-masking.ts +++ b/examples/react/urql/src/gql/fragment-masking.ts @@ -11,11 +11,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/typescript-esm/src/gql/fragment-masking.ts b/examples/typescript-esm/src/gql/fragment-masking.ts index 5f31332416f..749b250a4de 100644 --- a/examples/typescript-esm/src/gql/fragment-masking.ts +++ b/examples/typescript-esm/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/typescript-graphql-request/src/gql/fragment-masking.ts b/examples/typescript-graphql-request/src/gql/fragment-masking.ts index b0d34a36d2f..1056e81bdf3 100644 --- a/examples/typescript-graphql-request/src/gql/fragment-masking.ts +++ b/examples/typescript-graphql-request/src/gql/fragment-masking.ts @@ -11,11 +11,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/vite/vite-react-cts/src/gql/fragment-masking.ts b/examples/vite/vite-react-cts/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/vite/vite-react-cts/src/gql/fragment-masking.ts +++ b/examples/vite/vite-react-cts/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/vite/vite-react-mts/src/gql/fragment-masking.ts b/examples/vite/vite-react-mts/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/vite/vite-react-mts/src/gql/fragment-masking.ts +++ b/examples/vite/vite-react-mts/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/vite/vite-react-ts/src/gql/fragment-masking.ts b/examples/vite/vite-react-ts/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/vite/vite-react-ts/src/gql/fragment-masking.ts +++ b/examples/vite/vite-react-ts/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/vue/apollo-composable/src/gql/fragment-masking.ts b/examples/vue/apollo-composable/src/gql/fragment-masking.ts index 4427899b266..75e31f7960d 100644 --- a/examples/vue/apollo-composable/src/gql/fragment-masking.ts +++ b/examples/vue/apollo-composable/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/vue/urql/src/gql/fragment-masking.ts b/examples/vue/urql/src/gql/fragment-masking.ts index 4427899b266..75e31f7960d 100644 --- a/examples/vue/urql/src/gql/fragment-masking.ts +++ b/examples/vue/urql/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/vue/villus/src/gql/fragment-masking.ts b/examples/vue/villus/src/gql/fragment-masking.ts index 4427899b266..75e31f7960d 100644 --- a/examples/vue/villus/src/gql/fragment-masking.ts +++ b/examples/vue/villus/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/examples/yoga-tests/src/gql/fragment-masking.ts b/examples/yoga-tests/src/gql/fragment-masking.ts index 6a9cfb0e81c..60a650c2641 100644 --- a/examples/yoga-tests/src/gql/fragment-masking.ts +++ b/examples/yoga-tests/src/gql/fragment-masking.ts @@ -16,11 +16,6 @@ export type FragmentType> : never : never; -// return partial if `fragmentType` is partial e.g. because of conditional directives -export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>>, -): Partial; // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, diff --git a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts index a3ab47dd34e..528d6a76b5c 100644 --- a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts +++ b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts @@ -1023,11 +1023,12 @@ export class SelectionSetToObject< fields.push( `{ ' $fragmentRefs'?: { ${fragmentsSpreadUsages .map(name => { + // FIXME: https://github.com/dotansimha/graphql-code-generator/pull/10904/changes#r3729881814 // A conditional (`@skip`/`@include`) masked spread may be absent, // so its data is wrapped in `Partial`. - if (options.partialTypes) { - return `'${name}': Partial<${name}>`; - } + // if (options.partialTypes) { + // return `'${name}': Partial<${name}>`; + // } if (options.unsetTypes) { return `'${name}': Incremental<${name}>`; } diff --git a/packages/presets/client/src/fragment-masking-plugin.ts b/packages/presets/client/src/fragment-masking-plugin.ts index 383cb1ae75c..e9044330738 100644 --- a/packages/presets/client/src/fragment-masking-plugin.ts +++ b/packages/presets/client/src/fragment-masking-plugin.ts @@ -23,11 +23,12 @@ export function makeFragmentData< const defaultUnmaskFunctionName = 'useFragment'; const createUnmaskFunctionTypeDefinitions = (unmaskFunctionName = defaultUnmaskFunctionName) => [ - `// return partial if \`fragmentType\` is partial e.g. because of conditional directives -export function ${unmaskFunctionName}( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>> -): Partial;`, + // FIXME: https://github.com/dotansimha/graphql-code-generator/pull/10904/changes#r3729881814 + // `// return partial if \`fragmentType\` is partial e.g. because of conditional directives + // export function ${unmaskFunctionName}( + // _documentNode: DocumentTypeDecoration, + // fragmentType: FragmentType, any>> + // ): Partial;`, `// return non-nullable if \`fragmentType\` is non-nullable export function ${unmaskFunctionName}( diff --git a/packages/presets/client/tests/client-preset.fragment-masking.spec.ts b/packages/presets/client/tests/client-preset.fragment-masking.spec.ts index 3efaf0deb79..5dff71f1855 100644 --- a/packages/presets/client/tests/client-preset.fragment-masking.spec.ts +++ b/packages/presets/client/tests/client-preset.fragment-masking.spec.ts @@ -148,100 +148,95 @@ describe('client-preset - fragment masking', () => { expect(result).toHaveLength(4); const gqlFile = result.find(file => file.filename === 'out1/fragment-masking.ts'); expect(gqlFile.content).toMatchInlineSnapshot(` - "/* eslint-disable */ - import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; - import { FragmentDefinitionNode } from 'graphql'; - import { Incremental } from './graphql'; - - - export type FragmentType> = TDocumentType extends DocumentTypeDecoration< - infer TType, - any - > - ? [TType] extends [{ ' $fragmentName'?: infer TKey }] - ? TKey extends string - ? { ' $fragmentRefs'?: { [key in TKey]: TType } } - : never + "/* eslint-disable */ + import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; + import { FragmentDefinitionNode } from 'graphql'; + import { Incremental } from './graphql'; + + + export type FragmentType> = TDocumentType extends DocumentTypeDecoration< + infer TType, + any + > + ? [TType] extends [{ ' $fragmentName'?: infer TKey }] + ? TKey extends string + ? { ' $fragmentRefs'?: { [key in TKey]: TType } } : never - : never; - - // return partial if \`fragmentType\` is partial e.g. because of conditional directives - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>> - ): Partial; - // return non-nullable if \`fragmentType\` is non-nullable - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> - ): TType; - // return nullable if \`fragmentType\` is undefined - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined - ): TType | undefined; - // return nullable if \`fragmentType\` is nullable - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null - ): TType | null; - // return nullable if \`fragmentType\` is nullable or undefined - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined - ): TType | null | undefined; - // return array of non-nullable if \`fragmentType\` is array of non-nullable - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> - ): Array; - // return array of nullable if \`fragmentType\` is array of nullable - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined - ): Array | null | undefined; - // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> - ): ReadonlyArray; - // return readonly array of nullable if \`fragmentType\` is array of nullable - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined - ): ReadonlyArray | null | undefined; - export function iLikeTurtles( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined - ): TType | Array | ReadonlyArray | null | undefined { - return fragmentType as any; - } + : never + : never; + // return non-nullable if \`fragmentType\` is non-nullable + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> + ): TType; + // return nullable if \`fragmentType\` is undefined + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | undefined + ): TType | undefined; + // return nullable if \`fragmentType\` is nullable + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null + ): TType | null; + // return nullable if \`fragmentType\` is nullable or undefined + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null | undefined + ): TType | null | undefined; + // return array of non-nullable if \`fragmentType\` is array of non-nullable + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> + ): Array; + // return array of nullable if \`fragmentType\` is array of nullable + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> | null | undefined + ): Array | null | undefined; + // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> + ): ReadonlyArray; + // return readonly array of nullable if \`fragmentType\` is array of nullable + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> | null | undefined + ): ReadonlyArray | null | undefined; + export function iLikeTurtles( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined + ): TType | Array | ReadonlyArray | null | undefined { + return fragmentType as any; + } - export function makeFragmentData< - F extends DocumentTypeDecoration, - FT extends ResultOf - >(data: FT, _fragment: F): FragmentType { - return data as FragmentType; - } - export function isFragmentReady( - queryNode: DocumentTypeDecoration, - fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined - ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; - if (!deferredFields) return true; + export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf + >(data: FT, _fragment: F): FragmentType { + return data as FragmentType; + } + export function isFragmentReady( + queryNode: DocumentTypeDecoration, + fragmentNode: TypedDocumentNode, + data: FragmentType, any>> | null | undefined + ): data is FragmentType { + const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ + ?.deferredFields; - const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; - const fragName = fragDef?.name?.value; + if (!deferredFields) return true; - const fields = (fragName && deferredFields[fragName]) || []; - return fields.length > 0 && fields.every(field => data && field in data); - } - " - `); + const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; + const fragName = fragDef?.name?.value; + + const fields = (fragName && deferredFields[fragName]) || []; + return fields.length > 0 && fields.every(field => data && field in data); + } + " + `); }); it('can accept null in useFragment', async () => { @@ -273,100 +268,95 @@ describe('client-preset - fragment masking', () => { const fragmentFile = result.find(file => file.filename.includes('fragment-masking.ts')); expect(fragmentFile.content).toMatchInlineSnapshot(` - "/* eslint-disable */ - import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; - import { FragmentDefinitionNode } from 'graphql'; - import { Incremental } from './graphql'; - - - export type FragmentType> = TDocumentType extends DocumentTypeDecoration< - infer TType, - any - > - ? [TType] extends [{ ' $fragmentName'?: infer TKey }] - ? TKey extends string - ? { ' $fragmentRefs'?: { [key in TKey]: TType } } - : never + "/* eslint-disable */ + import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; + import { FragmentDefinitionNode } from 'graphql'; + import { Incremental } from './graphql'; + + + export type FragmentType> = TDocumentType extends DocumentTypeDecoration< + infer TType, + any + > + ? [TType] extends [{ ' $fragmentName'?: infer TKey }] + ? TKey extends string + ? { ' $fragmentRefs'?: { [key in TKey]: TType } } : never - : never; - - // return partial if \`fragmentType\` is partial e.g. because of conditional directives - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>> - ): Partial; - // return non-nullable if \`fragmentType\` is non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> - ): TType; - // return nullable if \`fragmentType\` is undefined - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined - ): TType | undefined; - // return nullable if \`fragmentType\` is nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null - ): TType | null; - // return nullable if \`fragmentType\` is nullable or undefined - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined - ): TType | null | undefined; - // return array of non-nullable if \`fragmentType\` is array of non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> - ): Array; - // return array of nullable if \`fragmentType\` is array of nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined - ): Array | null | undefined; - // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> - ): ReadonlyArray; - // return readonly array of nullable if \`fragmentType\` is array of nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined - ): ReadonlyArray | null | undefined; - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined - ): TType | Array | ReadonlyArray | null | undefined { - return fragmentType as any; - } + : never + : never; + + // return non-nullable if \`fragmentType\` is non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> + ): TType; + // return nullable if \`fragmentType\` is undefined + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | undefined + ): TType | undefined; + // return nullable if \`fragmentType\` is nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null + ): TType | null; + // return nullable if \`fragmentType\` is nullable or undefined + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null | undefined + ): TType | null | undefined; + // return array of non-nullable if \`fragmentType\` is array of non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> + ): Array; + // return array of nullable if \`fragmentType\` is array of nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> | null | undefined + ): Array | null | undefined; + // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> + ): ReadonlyArray; + // return readonly array of nullable if \`fragmentType\` is array of nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> | null | undefined + ): ReadonlyArray | null | undefined; + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined + ): TType | Array | ReadonlyArray | null | undefined { + return fragmentType as any; + } - export function makeFragmentData< - F extends DocumentTypeDecoration, - FT extends ResultOf - >(data: FT, _fragment: F): FragmentType { - return data as FragmentType; - } - export function isFragmentReady( - queryNode: DocumentTypeDecoration, - fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined - ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf + >(data: FT, _fragment: F): FragmentType { + return data as FragmentType; + } + export function isFragmentReady( + queryNode: DocumentTypeDecoration, + fragmentNode: TypedDocumentNode, + data: FragmentType, any>> | null | undefined + ): data is FragmentType { + const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ + ?.deferredFields; - if (!deferredFields) return true; + if (!deferredFields) return true; - const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; - const fragName = fragDef?.name?.value; + const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; + const fragName = fragDef?.name?.value; - const fields = (fragName && deferredFields[fragName]) || []; - return fields.length > 0 && fields.every(field => data && field in data); - } - " - `); + const fields = (fragName && deferredFields[fragName]) || []; + return fields.length > 0 && fields.every(field => data && field in data); + } + " + `); // FIXME(pnpm-update): TypeScript errors. Maybe content shouldn't be merged? // const content = mergeOutputs([ @@ -411,100 +401,95 @@ describe('client-preset - fragment masking', () => { const fragmentFile = result.find(file => file.filename.includes('fragment-masking.ts')); expect(fragmentFile.content).toMatchInlineSnapshot(` - "/* eslint-disable */ - import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; - import { FragmentDefinitionNode } from 'graphql'; - import { Incremental } from './graphql'; - - - export type FragmentType> = TDocumentType extends DocumentTypeDecoration< - infer TType, - any - > - ? [TType] extends [{ ' $fragmentName'?: infer TKey }] - ? TKey extends string - ? { ' $fragmentRefs'?: { [key in TKey]: TType } } - : never + "/* eslint-disable */ + import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; + import { FragmentDefinitionNode } from 'graphql'; + import { Incremental } from './graphql'; + + + export type FragmentType> = TDocumentType extends DocumentTypeDecoration< + infer TType, + any + > + ? [TType] extends [{ ' $fragmentName'?: infer TKey }] + ? TKey extends string + ? { ' $fragmentRefs'?: { [key in TKey]: TType } } : never - : never; - - // return partial if \`fragmentType\` is partial e.g. because of conditional directives - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>> - ): Partial; - // return non-nullable if \`fragmentType\` is non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> - ): TType; - // return nullable if \`fragmentType\` is undefined - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined - ): TType | undefined; - // return nullable if \`fragmentType\` is nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null - ): TType | null; - // return nullable if \`fragmentType\` is nullable or undefined - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined - ): TType | null | undefined; - // return array of non-nullable if \`fragmentType\` is array of non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> - ): Array; - // return array of nullable if \`fragmentType\` is array of nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined - ): Array | null | undefined; - // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> - ): ReadonlyArray; - // return readonly array of nullable if \`fragmentType\` is array of nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined - ): ReadonlyArray | null | undefined; - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined - ): TType | Array | ReadonlyArray | null | undefined { - return fragmentType as any; - } + : never + : never; + + // return non-nullable if \`fragmentType\` is non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> + ): TType; + // return nullable if \`fragmentType\` is undefined + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | undefined + ): TType | undefined; + // return nullable if \`fragmentType\` is nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null + ): TType | null; + // return nullable if \`fragmentType\` is nullable or undefined + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null | undefined + ): TType | null | undefined; + // return array of non-nullable if \`fragmentType\` is array of non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> + ): Array; + // return array of nullable if \`fragmentType\` is array of nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> | null | undefined + ): Array | null | undefined; + // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> + ): ReadonlyArray; + // return readonly array of nullable if \`fragmentType\` is array of nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> | null | undefined + ): ReadonlyArray | null | undefined; + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined + ): TType | Array | ReadonlyArray | null | undefined { + return fragmentType as any; + } - export function makeFragmentData< - F extends DocumentTypeDecoration, - FT extends ResultOf - >(data: FT, _fragment: F): FragmentType { - return data as FragmentType; - } - export function isFragmentReady( - queryNode: DocumentTypeDecoration, - fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined - ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf + >(data: FT, _fragment: F): FragmentType { + return data as FragmentType; + } + export function isFragmentReady( + queryNode: DocumentTypeDecoration, + fragmentNode: TypedDocumentNode, + data: FragmentType, any>> | null | undefined + ): data is FragmentType { + const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ + ?.deferredFields; - if (!deferredFields) return true; + if (!deferredFields) return true; - const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; - const fragName = fragDef?.name?.value; + const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; + const fragName = fragDef?.name?.value; - const fields = (fragName && deferredFields[fragName]) || []; - return fields.length > 0 && fields.every(field => data && field in data); - } - " - `); + const fields = (fragName && deferredFields[fragName]) || []; + return fields.length > 0 && fields.every(field => data && field in data); + } + " + `); // FIXME(pnpm-update): TypeScript errors. Maybe content shouldn't be merged? // const content = mergeOutputs([ @@ -549,100 +534,95 @@ describe('client-preset - fragment masking', () => { const fragmentFile = result.find(file => file.filename.includes('fragment-masking.ts')); expect(fragmentFile.content).toMatchInlineSnapshot(` - "/* eslint-disable */ - import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; - import { FragmentDefinitionNode } from 'graphql'; - import { Incremental } from './graphql'; - - - export type FragmentType> = TDocumentType extends DocumentTypeDecoration< - infer TType, - any - > - ? [TType] extends [{ ' $fragmentName'?: infer TKey }] - ? TKey extends string - ? { ' $fragmentRefs'?: { [key in TKey]: TType } } - : never + "/* eslint-disable */ + import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; + import { FragmentDefinitionNode } from 'graphql'; + import { Incremental } from './graphql'; + + + export type FragmentType> = TDocumentType extends DocumentTypeDecoration< + infer TType, + any + > + ? [TType] extends [{ ' $fragmentName'?: infer TKey }] + ? TKey extends string + ? { ' $fragmentRefs'?: { [key in TKey]: TType } } : never - : never; - - // return partial if \`fragmentType\` is partial e.g. because of conditional directives - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>> - ): Partial; - // return non-nullable if \`fragmentType\` is non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> - ): TType; - // return nullable if \`fragmentType\` is undefined - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined - ): TType | undefined; - // return nullable if \`fragmentType\` is nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null - ): TType | null; - // return nullable if \`fragmentType\` is nullable or undefined - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined - ): TType | null | undefined; - // return array of non-nullable if \`fragmentType\` is array of non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> - ): Array; - // return array of nullable if \`fragmentType\` is array of nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined - ): Array | null | undefined; - // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> - ): ReadonlyArray; - // return readonly array of nullable if \`fragmentType\` is array of nullable - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined - ): ReadonlyArray | null | undefined; - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined - ): TType | Array | ReadonlyArray | null | undefined { - return fragmentType as any; - } + : never + : never; + + // return non-nullable if \`fragmentType\` is non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> + ): TType; + // return nullable if \`fragmentType\` is undefined + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | undefined + ): TType | undefined; + // return nullable if \`fragmentType\` is nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null + ): TType | null; + // return nullable if \`fragmentType\` is nullable or undefined + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | null | undefined + ): TType | null | undefined; + // return array of non-nullable if \`fragmentType\` is array of non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> + ): Array; + // return array of nullable if \`fragmentType\` is array of nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: Array>> | null | undefined + ): Array | null | undefined; + // return readonly array of non-nullable if \`fragmentType\` is array of non-nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> + ): ReadonlyArray; + // return readonly array of nullable if \`fragmentType\` is array of nullable + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: ReadonlyArray>> | null | undefined + ): ReadonlyArray | null | undefined; + export function useFragment( + _documentNode: DocumentTypeDecoration, + fragmentType: FragmentType> | Array>> | ReadonlyArray>> | null | undefined + ): TType | Array | ReadonlyArray | null | undefined { + return fragmentType as any; + } - export function makeFragmentData< - F extends DocumentTypeDecoration, - FT extends ResultOf - >(data: FT, _fragment: F): FragmentType { - return data as FragmentType; - } - export function isFragmentReady( - queryNode: DocumentTypeDecoration, - fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined - ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf + >(data: FT, _fragment: F): FragmentType { + return data as FragmentType; + } + export function isFragmentReady( + queryNode: DocumentTypeDecoration, + fragmentNode: TypedDocumentNode, + data: FragmentType, any>> | null | undefined + ): data is FragmentType { + const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ + ?.deferredFields; - if (!deferredFields) return true; + if (!deferredFields) return true; - const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; - const fragName = fragDef?.name?.value; + const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; + const fragName = fragDef?.name?.value; - const fields = (fragName && deferredFields[fragName]) || []; - return fields.length > 0 && fields.every(field => data && field in data); - } - " - `); + const fields = (fragName && deferredFields[fragName]) || []; + return fields.length > 0 && fields.every(field => data && field in data); + } + " + `); // FIXME(pnpm-update): TypeScript errors. Maybe content shouldn't be merged? // const content = mergeOutputs([ @@ -711,7 +691,7 @@ describe('client-preset - fragment masking', () => { }>; - export type GetUserQuery = { user: { id: string } & { age?: number | null } & { ' $fragmentRefs'?: { 'UserNicknamesFragment': Partial } } | null }; + export type GetUserQuery = { user: { id: string } & { age?: number | null } & { ' $fragmentRefs'?: { 'UserNicknamesFragment': UserNicknamesFragment } } | null }; export type UserNicknamesFragment = { nicknames: Array | null } & { ' $fragmentName'?: 'UserNicknamesFragment' }; @@ -737,11 +717,6 @@ describe('client-preset - fragment masking', () => { : never : never; - // return partial if \`fragmentType\` is partial e.g. because of conditional directives - export function useFragment( - _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType, any>> - ): Partial; // return non-nullable if \`fragmentType\` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration,