Questions tagged [graphql-codegen]
182 questions
5
votes
0 answers
Is there a way to remove Maybe and Scalars with GraphQl Codegen?
I'm using GraphQl Codegen with the typescript and typescript-operations plugins, but the file generated contains a tone of Maybe and Scalars making the file look very messy.
export type Formation = {
availability?: Maybe;
…
5
votes
2 answers
TypeScript incorrectly errors when I map and flat an array?
I'm using GraphQL Codegen to generate TypeScript types from my GraphQL schema. Here is my query, I've used a fragment so that it has it's only type which is easy to export:
query reservationsPage($schoolSettingId: Int!, $day: UnixDate!) {
…

Evanss
- 23,390
- 94
- 282
- 505
5
votes
2 answers
graphql-codegen dynamic fields with interpolation
I'm using graphql-codegen to generate typescript types from graphql schema. I'm trying to create a fragment with dynamic fields.
schema.ts
This is the type generated by graphql-codegen.
/** User Type */
export type UserType = {
__typename?:…

in3pi2
- 877
- 1
- 11
- 22
5
votes
2 answers
Typesafe wrap of autogenerated functions and then call dynamically by just using `__typename` as parameter. Typescript
I have fully typesafe auto-generated code by the awesome graphql-codgen/vue.
I use it in my project by building a little wrapper so my Users don't have to do common config tasks every call. Like e.g. defining cache-behavior, auto-update cache,…

JoeSchr
- 1,067
- 1
- 9
- 14
4
votes
0 answers
How to parse custom scalars in graphql-codegen / apollo client?
The ethers.js library provides the BigNumber type. To create a BigNumber from a string we call BigNumber.from("42")
I have created aGraphQLScalar called GraphQLBignumber on my server:
import { GraphQLScalarType } from 'graphql';
import { BigNumber }…

sev
- 1,500
- 17
- 45
4
votes
1 answer
typescript can't resolve typing from graphql query that returns a union type
I would like to understand what is going on here, and since i'm not very experienced with typescript, any help would be greatly appreciated !
I've got a resolver to return one cost from database :
@Query(() => FixedOrVariableCost, { name:…

LIIT
- 496
- 6
- 16
4
votes
1 answer
Return ENUM - Cannot return null for non-nullable field
I am using apollo-server-lambda, Prisma ORM and graphql-codegen.
I have a query (getBookById) that returns a Book. Book contains an enum called BookStatus. I want to be able to return in ENUM in the playground but I get the error:
Cannot return…

Magofoco
- 5,098
- 6
- 35
- 77
4
votes
1 answer
Is there any way to use @next/env in codegen.yaml?
I was wondering if there was a way to use @next/env to replace variables in codegen.yaml when i run yarn codegen:
graphql-codegen -r dotenv/config --config codegen.yml - this is codegen example to load dot env
graphql-codegen -r @next/env --config…

Martinn3
- 51
- 5
4
votes
1 answer
Use RTK Query with Graphql
So far I understand I need to build my own baseQuery. I could write graphql queries and mutations like in example here https://rtk-query-docs.netlify.app/examples/react-with-graphql, will I get full type safety for queries and mutations if I add…

Nenad
- 231
- 3
- 15
4
votes
2 answers
Property does not exist on type in GraphQL query result
In the React component I use a GraphQL query to fetch data:
const { data, error, loading } = useGetEmployeeQuery({
variables: { id: "a34c0d11-f51d-4a9b-ac7fd-bfb7cbffa" }
});
On the data destructure
const { first_name } =…

El Anonimo
- 1,759
- 3
- 24
- 38
4
votes
3 answers
Convert Maybe[]' to 'string[]
I am using graphql with generated types and struggling with how to convert them to the type I need to pass it to my data service calls.
@graphql-codegen has given me an args type of
export type QueryOrdersArgs = {
ids:…

tmc
- 404
- 1
- 7
- 20
4
votes
1 answer
How to generate Typescript definitions from AppSync GraphQL schema if I am not using amplify?
I have my AppSync api set up using aws-cdk and am not using their amplify framework. I am trying to figure out how / if I can generate Typescript definitions from my AppSync schema.graphql file while not using amplify, i.e. no access to amplify…

Ilja
- 44,142
- 92
- 275
- 498
4
votes
1 answer
Reference Complex type from union in Typescript
I'm using graphql-codegen to generate types from my graphQL queries.
The result is sometimes pretty complex specifically when unions are involved.
Here is a concrete example
export type GroupQuery = { __typename?: 'Query' } & {
group?: Maybe<
…

Paté
- 1,914
- 2
- 22
- 33
3
votes
1 answer
The query is always of type unknown when created with @graphql-codegen
I have a this graphql query:
import { graphql } from '../__generated__/gql';
// typeof IndexPageQuery is unknown
const IndexPageQuery = graphql(`
query IndexPageQuery {
user {
...UserInputFragment
}
}
…

Pavel Perevezencev
- 2,596
- 3
- 28
- 49
3
votes
1 answer
Graphql Codegen Wizard Terminated Unexpected
I am trying to use the GraphQL Codegen Wizard for my application. I followed the installation instruction from this site: https://www.graphql-code-generator.com/docs/getting-started/installation
All the dependencies are successfully installed via…

Alex
- 33
- 3