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.

__typename should not be optional when used in query

See original GitHub issue

Describe the bug When use __typename in a query, it’s type should not be optional in corresponding query namespace.

To Reproduce Steps to reproduce the behavior:

schema:

# schema.graphql

type Person {
  name: String!
}

type Query {
  person: Person
}

document:

query search {
  person {
    __typename
    name
  }
}

command: gql-gen --template graphql-codegen-typescript-template --schema schema.graphql document.graphql --out schema.ts

Expected behavior

The namespace of query search in generated schema.ts:

export namespace Search {
  export type Variables = {};

  export type Query = {
    __typename?: "Query";
    person?: Person | null;
  };

  export type Person = {
    __typename?: "Person"; // <- this should not be optional because we used it in query
    name: string;
  };
}

Search.Person.__typename is optional, while it should not be.

Environment:

  • OS: Arch Linux (latest)
  • Codegen: 0.12.6
  • Node: 10.11.0
  • graphql: 14.0.2

Issue Analytics

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

github_iconTop GitHub Comments

9reactions
mfbx9da4commented, Oct 4, 2021

So this is supposedly fixed but I don’t see any docs of how to use the query version where __typename is required any guidance?

2reactions
dotansimhacommented, Dec 24, 2018

Fixed in 0.15.2 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL schema basics
GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return...
Read more >
How to remove the `__typename` field from the graphql ...
js:28 DEPRECATION WARNING: using fragments without __typename is unsupported behavior and will be removed in future versions of Apollo client.
Read more >
Parameter pack(since C++11) - cppreference.com
A template parameter pack is a template parameter that accepts zero or more template arguments (non-types, types, or templates).
Read more >
typescript-operations - GraphQL Code Generator
This plugin generates TypeScript types based on your GraphQLSchema and your GraphQL operations and fragments. It generates types for your ...
Read more >
@urql/core | urql Documentation
This is similar to client.query , but does not provide a toPromise() ... An optional request policy that should be used specifying the...
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