Skip to content

Graffle doesn't work with TypedDocumentString from graphql-codegen #1455

@jasonkuhrt

Description

@jasonkuhrt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions