Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypedDocumentString #997

Closed
lopezjurip opened this issue Jul 25, 2024 · 1 comment · Fixed by #1021
Closed

Support TypedDocumentString #997

lopezjurip opened this issue Jul 25, 2024 · 1 comment · Fixed by #1021

Comments

@lopezjurip
Copy link

lopezjurip commented Jul 25, 2024

Perceived Problem

The most popular codegen for GraphQL (graphql-codegen) has two output modes:

  1. TypedDocumentNode where the output are JSON representation of the graphql queries.
  2. TypedDocumentString where the output is a string representation of the graphql queries.

When using string representation the output is usually smaller and easy to compare than it's object representation.

See: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#documentmode

Currently graphql-request doesn't support TypedDocumentString

Example:

// codegen.ts
import { type CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  schema: 'schema.graphql',
  documents: ['src/**/*.tsx'],
  generates: {
    './src/gql/': {
      preset: 'client',
      config: {
        documentMode: 'string' // 👈
      }
    }
  }
}
import { request } from 'graphql-request'
import { gql } from './gql'
 
// This is a TypedDocumentString
const helloQuery = gql(`
  query hello {
    hello
  }
`)

await request(endpoint, helloQuery) // typescript error 🚨
// Generated code
export type HelloQueryVariables = Exact<{ [key: string]: never }>
 
export type HelloQuery = { __typename?: 'Query'; hello: string }
 
export const HelloDocument = new TypedDocumentString(`
  query hello {
    hello
  }
`) as unknown as TypedDocumentString<HelloQuery, HelloQueryVariables>

Ideas / Proposed Solution(s)

Support TypedDocumentString

@jasonkuhrt
Copy link
Owner

Related #854

@jasonkuhrt jasonkuhrt pinned this issue Aug 2, 2024
@jasonkuhrt jasonkuhrt mentioned this issue Aug 6, 2024
4 tasks
@jasonkuhrt jasonkuhrt unpinned this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants