question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"typescript-operations@2.2.1" + "avoidOptionals: true" generating "| undefined"

See original GitHub issue

Describe the bug Starting in typescript-operations@2.2.1, avoidOptionals: true is appending | undefined; The | undefined should not be present with avoidOptionals: true.

This was not happening in typescript-operations@2.2.0. In 2.2.0, the package correctly generates x | null.

To Reproduce Steps to reproduce the behavior:

Live example https://codesandbox.io/s/icy-browser-u7p8q?file=/codegen.yml:180-201

  1. My GraphQL schema:
type Query {
    user(id: ID!): User!
}

type User {
    id: ID!
    username: String!
    email: String
}
  1. My GraphQL operations:
query user {
    user(id: 1) {
        id
        username
        email
    }
}

  1. My codegen.yml config file:
schema: schema.graphql
documents: document.graphql
generates:
  types.ts:
    config:
      avoidOptionals: true
    plugins:
      - typescript
      - typescript-operations

Expected behavior

Maybe types generate x | null, not x | null | undefined. Environment:

  • OS:
  • @graphql-codegen/...:
  • NodeJS:

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rjensen-r7commented, Jan 31, 2022

Verified that this is fixed, thank you

2reactions
simPodcommented, Jan 26, 2022

Ok I just found myself again already solving this 😕 https://github.com/dotansimha/graphql-code-generator/pull/7104

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript-operations - GraphQL Code Generator
This plugin generates TypeScript types based on your GraphQLSchema and ... It generates types for your GraphQL documents: Query, Mutation, ...
Read more >
Property 'cursor' does not exist on type X, null or undefined ...
I was using SvelteKit without the amazing "strict": true in tsconfig.json until today. I have this code generated (with codegen) from a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found