-
Notifications
You must be signed in to change notification settings - Fork 309
Description
Description
Similar to #1453 (fixed in graphql-request branch), the main Graffle codebase has the same issue with TypedDocumentString from @graphql-codegen when using documentMode: 'string'.
Root Cause
In src/lib/graphql-kit/document/utilities.ts, three functions use Str.Type.is() to check for strings:
toString()(line 9-12)getOperationType()(line 35-83)normalizeDocumentToNode()(line 85-88)
Str.Type.is() checks typeof value === 'string', which returns false for boxed String objects.
TypedDocumentString uses extends String (source), creating boxed String instances where typeof returns "object".
The Typed.unType() helper just casts to any - it doesn't normalize boxed Strings.
Suggested Fix
Similar to the fix in #1453, normalize boxed Strings before the typeof checks:
```typescript
// Example for toString():
export const toString = (document: Typed.TypedDocumentLike): string => {
const documentUntyped = Typed.unType(document)
// Normalize boxed Strings to primitive strings
const normalized = typeof documentUntyped === 'string' || (documentUntyped as DocumentNode).kind
? documentUntyped
: `${documentUntyped}`
return Str.Type.is(normalized) ? normalized : graphqlWebPrint(normalized)
}
```
Apply similar fixes to getOperationType() and normalizeDocumentToNode().
Related
- graphql-request doesn't work with graphql-codegen TypedDocumentString input #1453 - Fixed in graphql-request branch
- Affects users using
@graphql-codegenwithdocumentMode: 'string'