Questions tagged [graphql-codegen]

182 questions
3
votes
0 answers

GraphQL code generation using Typescript loader

How can I use a typescript loader for graphql-codegen? I need to build my graphql schema dynamically, therefore I have to load it from a typescript file. Here are the files I'm using: codegen.yaml generates: src/generated/auth-resolvers.types.ts: …
Atlinx
  • 318
  • 3
  • 10
3
votes
3 answers

Generate the correct type instead of a union in GraphQL codegen

I am trying to migrate a setup which generates all the types exactly like what the server has into something which is based on just the document nodes that we've written. I currenly have this configuration in .graphqlrc.js /** @type…
JP Calvo
  • 173
  • 1
  • 2
  • 14
3
votes
0 answers

graphql-codegen + typescript-svelte-apollo - Refetch not working?

(Edited) Refetching with the generated query type seems to work different from the refetch function in Apollo Client useQuery. I don't understand how to phrase it - can anyone provide an example? I'm realizing the problem is probably either my…
nimmolo
  • 191
  • 3
  • 14
3
votes
0 answers

Apollo codegen duplicating nested fragment imports

I'm using reusable fragments in .gql files but the resulting query will declare the fragments multiple times when using codegen. A simplified example: # ImagesInfos.gql fragment ImageInfos { url alt } #Post.gql #import…
rayfranco
  • 3,630
  • 3
  • 26
  • 38
3
votes
1 answer

What is the purpose of the `Exact` type that @graphql-codegen creates?

GraphQL Code Generator creates this type on the top of the created TypeScript file: export type Exact = { [K in keyof T]: T[K] }; and uses it for all client created query variables: src/foo.graphql: query…
ruohola
  • 21,987
  • 6
  • 62
  • 97
3
votes
1 answer

GraphQL Code Generator - Graphql Document Validation Failed

I keep getting an error when I run yarn run graphql-codegen --config codegen.yml The error says Found 1 error ✖ src/generated/graphql.tsx AggregateError: GraphQL Document Validation failed with 1 errors at Object.checkValidationErrors…
skele
  • 83
  • 1
  • 7
3
votes
4 answers

how to run amplify codegen in where codegen is already configured?

we have a project repo where backend team have added new apis. other developers have run and configured amplify and codegen. now I want to add these new queries and their types. when I run amplify codegen i get this error: Please download the…
2
votes
1 answer

Apollo Angular GraphQL Code Generation. Generate Queries and Mutations from single schema.graphqls file

I'm currently trying to get the Apollo Angular Code Generation (see: https://the-guild.dev/graphql/codegen/docs/guides/angular) to create types, queries and mutations from a single schema.graphqls file. I'm using the same schema file as in the…
IdealOutage
  • 69
  • 1
  • 1
  • 11
2
votes
1 answer

get sub types in graphql query using @graphql-codegen/cli

I have a below query export const GET_ALL_ADVERT_CUSTOM_FIELD = gql(` query advertCustomFields { advertCustomFields { nodes { slug valueType displayName description canRead } } …
2
votes
2 answers

Remove null and undefined from type (including nested props)

I found this resource, which works great for types that don't have nested props. https://bobbyhadz.com/blog/typescript-remove-null-and-undefined-from-type But in my case, I need to strip all props, even nested ones. Is there any solution for doing…
octavemirbeau
  • 481
  • 6
  • 19
2
votes
0 answers

loadTs is not a function

After running graphql-codegen-esm --config codegen.yml the following message is shown in the console loadTs is not a function I add files with my project configuration package.json { "main": "src/index.js", "type": "module", "scripts": { …
Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68
2
votes
1 answer

Cannot use enum values imported from GraphQL Codegen types

Whenever I import enums from graphql-codegen generated types and use their values, the app fails to start. import { MyEnum } from 'graphql-types.ts'; let x: MyEnum; // This works x = MyEnum.MY_ENUM_VALUE; // Whenever I use this code, it…
Z0q
  • 1,689
  • 3
  • 28
  • 57
2
votes
0 answers

Cannot find type __Schema in destination schema Apollo Rover and graphql-codegen schema-ast

Hello I'm trying to federate two example APIs (built using latest Apollo server) but when I try to run rover supergraph compose --config ./supergraph.yaml I get this error: rover supergraph compose --config ./supergraph.yaml Composing supergraph…
2
votes
1 answer

Using getServerSideProps for graphql-codegen mutation in nextjs

I would like to perform a graphql mutation in getServerSideProps. I am using graphql-codegen to generate code from my graphql call. The code I use to perform my mutation is: const [getTokenMutation, _] = useGetTokenMutation() const token = await…
sev
  • 1,500
  • 17
  • 45
2
votes
1 answer

GraphQL - Failed to load schema from http://localhost:5555/graphql: fetch failed

I'm trying to use this boilerplate project. My codegen.yml file defines the schema as: schema: http://localhost:5555/graphql When I try to generate the graphql code-gen, I get an error that says: > yarn run v1.22.18 $ DEBUG=true graphql-codegen ✔…
Mel
  • 2,481
  • 26
  • 113
  • 273
1 2
3
12 13