Questions tagged [graphql-codegen]

182 questions
2
votes
2 answers

How to infer types from an imported file in Typescript

I have a tricky Typescript problem I can't seem to solve. I would like to infer values based on a generic. However, the catch is the inferred types needs to come from an imported file. To explain in an example, this is my generic function. import {…
Charklewis
  • 4,427
  • 4
  • 31
  • 69
2
votes
1 answer

graphql client: map enum value to desired form

We are using graphql-codegen on both the client and the server to handle mapping from our graphql schema to our typescript types. We have an enum in graphql enum Status { ACTIVE INACTIVE NOT_CONFIRMED } On the server side of the equation I…
Matt
  • 2,795
  • 2
  • 29
  • 47
2
votes
1 answer

Adding a custom type to codegen.yml

My GraphQL schema uses a type called PointScalar, which in Typescript would be defined as export type PointScalar = { coordinates: [number, number] } Without any modification, codegen declares PointScalar fields as Scalars['PointScalar'], which…
Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
2
votes
0 answers

Error: Unable to merge GraphQL directive "abstractEntity" in graphql-codegen

Codegen worked fine with "@graphql-codegen/add": "^3.1.0", "@graphql-codegen/cli": "1.21.7", "@graphql-codegen/typescript": "1.23.0", "@graphql-codegen/typescript-resolvers": "1.20.0", "@graphql-codegen/typescript-mongodb": "^1.19.5", and then…
Adam
  • 437
  • 1
  • 4
  • 12
2
votes
0 answers

GraphQL Codegen – How to make Partial the return type of a resolver partial but keep the arguments required?

I am using this configuration file: overwrite: true schema: "src/**/*.(resolver|type).ts" documents: null generates: src/graphql/generated/graphql.ts: plugins: - "typescript" - "typescript-resolvers" config: typesSuffix:…
Some random IT boy
  • 7,569
  • 2
  • 21
  • 47
2
votes
0 answers

How to get Typescript Type definition for generating angular forms

I am using @graphql-codegen/typescript-apollo-angular for generating types and services for my Angular Application. Now I would like to try to generate angular forms out of this generated code. I would like to use the…
user3241778
  • 294
  • 2
  • 4
  • 20
2
votes
1 answer

How do I make Graphql Code Generator for typescript make its enums into pascal case instead of snake case?

Currently, the enums that Graphql Code Generator produces looks like this export enum Test_Type { Test: 'TEST', } however I want the generated enums to be in pascal case like this: export enum TestType { Test: 'TEST', } Edit, my…
Embedded_Mugs
  • 2,132
  • 3
  • 21
  • 33
2
votes
1 answer

How to forward Auth0's ID token to GraphQL Code Generator?

I am using GraphQL Code Generator with React Query, this is my codegen.yml: overwrite: true schema: http://localhost:4000/graphql generates: src/lib/__generated__/graphql.ts: documents: - "**/graphql/**/*.graphql" -…
user16985789
2
votes
2 answers

Enum mismatch between typescript and graphql-codegen

I'm currently trying to wrap my head around the below issue, and not getting very far. Currently, I'm running an Apollo-Server as my graphQL server, have prisma2 configured with a postgres database, and am utilizing graphql-codegen to generate the…
2
votes
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
  • 3,783
  • 5
  • 37
  • 91
2
votes
0 answers

Rename types with graphql-codegen

I'm working on a legacy codebase where, in our GraphQL schema, an interface was defined as 'Subscription': interface Subscription { fieldOne: String fieldTwo: String } type FirstSubscriptionType implements Subscription { …
kqcef
  • 527
  • 1
  • 4
  • 17
2
votes
1 answer

Graphql Codegen - Enum with custom key => value

I use graphql-codegen to generate type files. As an example, let's say I have the following in my schema.graphql file: enum cities { JOHANNESBURG CAIRO NEW_YORK LONDON BEIJING } The output in my generated-types.ts file is as follows: export…
techedemic
  • 341
  • 2
  • 6
2
votes
1 answer

typescript error: ' ' only refers to a type, but is being used as a namespace here

I went through several similar questions but wasn't able to get anywhere in solving this. I was following along with a tutorial from 2019 and I'm having trouble figuring out the right way to do the same thing in 2020. Here's the line I'm getting an…
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
  • 15,844
  • 47
  • 176
  • 332
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
  • 1,012
  • 14
  • 23