__typename should not be optional when used in query
See original GitHub issueDescribe 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:
- Created 5 years ago
- Reactions:4
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?Fixed in 0.15.2 😃