Skip to content

Commit b874eb5

Browse files
committed
Switch codegen document mode to string
1 parent c3f1578 commit b874eb5

File tree

4 files changed

+861
-121
lines changed

4 files changed

+861
-121
lines changed

frontend/codegen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const config: CodegenConfig = {
1515
preset: "client",
1616
plugins: ["typescript-msw"],
1717
config: {
18+
documentMode: "string",
1819
useTypeImports: true,
1920
enumsAsTypes: true,
2021
// By default, unknown scalars are generated as `any`. This is not ideal for catching potential bugs.

frontend/src/gql/fragment-masking.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable */
2-
import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
3-
import type { FragmentDefinitionNode } from 'graphql';
4-
import type { Incremental } from './graphql';
2+
import type { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core';
3+
import type { Incremental, TypedDocumentString } from './graphql';
54

65

76
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
@@ -70,18 +69,15 @@ export function makeFragmentData<
7069
return data as FragmentType<F>;
7170
}
7271
export function isFragmentReady<TQuery, TFrag>(
73-
queryNode: DocumentTypeDecoration<TQuery, any>,
74-
fragmentNode: TypedDocumentNode<TFrag>,
75-
data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
72+
queryNode: TypedDocumentString<TQuery, any>,
73+
fragmentNode: TypedDocumentString<TFrag, any>,
74+
data: FragmentType<TypedDocumentString<Incremental<TFrag>, any>> | null | undefined
7675
): data is FragmentType<typeof fragmentNode> {
77-
const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
78-
?.deferredFields;
76+
const deferredFields = queryNode.__meta__?.deferredFields as Record<string, (keyof TFrag)[]>;
77+
const fragName = fragmentNode.__meta__?.fragmentName as string | undefined;
7978

80-
if (!deferredFields) return true;
79+
if (!deferredFields || !fragName) return true;
8180

82-
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
83-
const fragName = fragDef?.name?.value;
84-
85-
const fields = (fragName && deferredFields[fragName]) || [];
81+
const fields = deferredFields[fragName] ?? [];
8682
return fields.length > 0 && fields.every(field => data && field in data);
8783
}

0 commit comments

Comments
 (0)