Questions tagged [graphql-codegen]
182 questions
2
votes
1 answer
Resolving auto-generated typescript-mongodb types for GraphQL output
I'm using the typescript-mongodb plugin to graphql-codegen to generate Typescript types for pulling data from MongoDB and outputting it via GraphQL on Node.
My input GraphQL schema looks like this
type User @entity{
id: ID @id,
firstName:…

pyromanfo
- 353
- 2
- 9
2
votes
1 answer
How to graphql-codegen handle schema with string templates in typescript/javascript exports
I am using graphql-codegen to generate the typescript type files for given schema.
All good except if there is string template in the exported scheme, it will complain the sytax and seems it will not compile it. Check the following files for more…

Ron
- 6,037
- 4
- 33
- 52
2
votes
1 answer
Assigning a type to a property that is a nested type of a Maybe type
I'm trying to assign to a property a type generated by the graphql-codegen tool. The type I'm trying to assign is a nested type. Given the following type:
type SomeType = {
someKey: Maybe<
{ __typename?: "OtherType" | undefined } &
{…

Lee
- 601
- 9
- 21
1
vote
0 answers
graphql codegen defaults to watchQuery, no possible way to alter? I only want to get the value 1 time
I have a sveltekit + apollo graphql project here. introspecting from my dev-env api here.
The issue I'm having is the codegen with this config:
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema:…

SebastianG
- 8,563
- 8
- 47
- 111
1
vote
0 answers
graphql-codegen + graphql-request transform/resolve date fields to Date objects
Is there a way to make fields of a special scalar type to be converted to date objects by graphql-request? Not just alias type, but have Date object, like Apollo can do with resolvers?
Here's my codegen.ts file:
import type { CodegenConfig } from…

Spadar Shut
- 15,111
- 5
- 47
- 54
1
vote
1 answer
How to allow Urql (typescript) to accept Vue reactive variables for queries created with graphql-codegen
I'm building a Vue project with urql and graphql-codegen.
Urql has the ability to take Vue reactive variables when using useQuery() to enable useQuery to be reactive and update when the variables do.
But graphql-codegen is creating the type for the…

Dov Rosenberg
- 673
- 6
- 20
1
vote
0 answers
graphql-request sending ENUMs as strings in mutations
I use graphql-codegen + graphql-request to mutate some data like this:
export const updateRoomQuery = graphql(/* GraphQL */ `
mutation UpdateRoomInOffice($cmd: UpdateRoomInOfficeInput!) {
updateRoomInOffice(cmd: $cmd) {
roomId
…

Spadar Shut
- 15,111
- 5
- 47
- 54
1
vote
2 answers
How to narrow and reuse TS Types with autogenerated by GraphQL codegen?
I am using graphql codegen together with urql to ensure back-to-back ts safety. But, after generating types and queries, I am having an issue typing the component props when passing data down to the component. Here is an example:
This is the query…

Miloslavc
- 127
- 2
- 7
1
vote
0 answers
I've added graphql-codegen to my create-react-app project, but it slows starting my local development server to a crawl. Is there a way around this?
So I've followed a few tutorials on how to get graphql-codegen to work and I'm fetching my schema from my backend server. This all works and I have a generated directory of my types, queries, and mutations.
However, when I want to start my server,…

nyphur
- 2,404
- 2
- 24
- 48
1
vote
3 answers
GraphQL code generator - typescript-graphql-request generates sdk with invalid import
I'm trying to use typescript-graphql-request to generate an sdk.
The generated file contains this import at the top
import * as Dom from 'graphql-request/dist/types.dom';
You can see an example if you go here and select "graphql-request typed SDK"…

J. Doe
- 317
- 2
- 15
1
vote
1 answer
jwt protected graphql resolvers not calling on SSR Nextjs
I have a backend with Nest + Graphql
and me resolver:
@Query(() => User)
@UseGuards(JwtAuthGuard)
me(@Context() { req }) {
return this.usersService.findOne(req.user.id);
}
On the frontend, i use Nextjs, Apollo client and code-gen:
#…

A.Anvarbekov
- 955
- 1
- 7
- 21
1
vote
1 answer
Codegen config can't load custom schema loader
I tried to set up codegen for my react, I use customized schema load to load schema from my api endpoint, but each time got error
Failed to load schema from pulse-api:
Failed to load custom loader: codegen_schema_loader.js
Error: Failed to load…

Michael Hua
- 11
- 1
1
vote
1 answer
Typescript: How to know if a union type MIGHT contain a subset?
I'm trying to type a function parameter where the param accepts any type where the union contains a known subset.
For example:
type One = { a: "one"; b: 1 };
type Two = { a: "two"; b: 2 };
type U = One | Two;
// `CouldContain` is some kind of…

Lee Benson
- 11,185
- 6
- 43
- 57
1
vote
1 answer
Using keys with graphql fragment masking
As far as I know, fragment masking is considered a best practice when developing graphql clients, but I'm having some difficulties wrapping my head around how to write even some simple react necessities with that level of obscurity. One common…

Haf
- 375
- 1
- 3
- 13
1
vote
0 answers
How to set graphql-codegen documents file?
I have graphql-codegen.yml file and src folder under project root path.
graphql-codegen.yml
schema: "https://swapi-graphql.netlify.app/.netlify/functions/index"
overwrite: true
documents: "src/**/*.graphql"
generates:
…

Morton
- 5,380
- 18
- 63
- 118