Questions tagged [graphql-codegen]

59 questions
10
votes
2 answers

Unable to find any GraphQL type definitions for the following pointers: src/**/*.graphql

I am using the @graphql-codegen/cli tool to generate typescript types out of my graphql server. Here is my codegen.yml content: overwrite: true schema: "http://localhost:3001/graphql" documents: "src/**/*.graphql" generates: …
TheSoul
  • 2,726
  • 7
  • 30
  • 58
5
votes
0 answers

The generated type is not suitable for resolvers

I have problems with graphql-code-generator. The generated type is not suitable for resolvers. I get an error in the line viewer: () => ({. Type '() => { createUser: () => { lastName: string; firstName: string; nickName: string; email: string;…
Nida
  • 87
  • 4
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
  • 508
  • 6
  • 12
4
votes
1 answer

How to generate GraphQL operations from GraphQL schema

I am looking for a way to make the developer workflow more efficient while GraphQL. Currently, using graphql-code-generator to generate types from my GraphQL server on the frontend. This is great, but this is only generating types. In order to…
Dave
  • 274
  • 1
  • 3
  • 20
4
votes
2 answers

GraphQL Code Generator - Cannot load my GQL Schema from Nestjs server endpoint

I'm using graphQL code generator on an angular app and I'm trying to load my schema from a local nestjs app. Here is the codegen.yml file: schema: http://localhost:3000/graphql documents: ./src/app/graphql/**/*.graphql generates: …
AtActionPark
  • 85
  • 1
  • 7
3
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
  • 17,152
  • 66
  • 217
  • 397
3
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,834
  • 2
  • 21
  • 32
3
votes
6 answers

graphql-codegen not running with config file

In my package.json file I've got script entry that runs graphql-codegen but it complains that the --config argument is invalid: $> yarn gen yarn run v1.21.1 $ graphql-codegen --config codegen.yml Error: Unknown argument: config ... error Command…
aarona
  • 32,176
  • 39
  • 119
  • 171
2
votes
1 answer

How to get simple graphql mutation query from generated schema?

I'm using the graphql code generator to get my generated file: npx graphql-codegen --config libs/codegen.yml In this file I do have export const AddDataDocument = gql` mutation addData($input: AddDataInput!) { addData(input: $input) { …
user3142695
  • 11,619
  • 29
  • 119
  • 238
2
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
  • 749
  • 1
  • 8
  • 20
2
votes
1 answer

Update cache after a mutation: Property 'names' does not exist on type '{ names: any; } | null'

Using GraphQL Code Generator with React with hooks, I'm trying to update the Apollo cache after a mutation, following the example in the Apollo docs: const [addName] = useAddNameMutation({ update(cache, {data: {addName}}) { const {names}…
lewislbr
  • 520
  • 4
  • 15
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
  • 243
  • 2
  • 8
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
  • 4,250
  • 3
  • 27
  • 41
2
votes
1 answer

How to customize the type for a graphql-code-generator produced field when consuming a Hasura graphql schema

I would like to override a the jsonb type for a speficic field in a graphql schema produced by Hasura and run through graphql-code-generator. I have a customList field of type jsonb. Ths is used to contain an array of json objects. When using…
arhnee
  • 715
  • 5
  • 19
1
vote
0 answers

Using generated graphql query types with my custom React hook inside Gatsby and Typescript project

I created a custom React hook in my Gatsby (and Typescript) project for my Site Metadata: // hooks/useSiteMetadata.ts import { useStaticQuery, graphql } from 'gatsby'; const useSiteMetadata = () => { const { site } = useStaticQuery( graphql` …
meez
  • 1,125
  • 2
  • 13
  • 33
1
2 3 4