typescript-urql-graphcache plugin: function argument types always have optional fields
See original GitHub issueDescribe the bug
All generated object types for graphcache handler function arguments have their field types converted to T | undefined
. This means I have to perform a lot of redundant checks (which is infeasible for a large number of fields) or I must type-assert everywhere.
To Reproduce Steps to reproduce the behavior:
- Generate the
GraphCacheConfig
type using the typescript-urql-graphcache plugin - Use this type parameter on your cacheExchange constructor
- Try to e.g. define an update function using a non-nullable object return value with non-nullable fields
- The object’s type annotation will declare all of its fields as optional.
The culprit is the WithTypename
type definition, which makes all fields of the input type optional.
Reproduction with example of an issue this causes: https://codesandbox.io/s/amazing-field-zlkgp?file=/main.ts
Expected behavior Objects defined in the generated typedefs have the exact same field types as specified in the gql schema.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5 (3 by maintainers)
Top Results From Across the Web
python - How do I define a function with optional arguments?
Just use the *args parameter, which allows you to pass as many arguments as you want after your a,b,c . You would have...
Read more >Documentation - More on Functions - TypeScript
We've created a type parameter Func that doesn't relate two values. That's always a red flag, because it means callers wanting to specify...
Read more >Using Python Optional Arguments When Defining Functions
In this tutorial, you'll explore the techniques you have available for defining Python functions that take optional arguments. When you master Python ...
Read more >Parameters — Dataiku DSS 11 documentation
The definition of each parameter has the following fields: type : Type of the parameter. Most common types are STRING, INT, DOUBLE, BOOLEAN,...
Read more >Declaring optional function parameters in JavaScript - Flexiple
In today's article, let's take a dive into how Optional Parameters in JavaScript can be implemented and also understand where exactly using them ......
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 Free
Top 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
Thank you for your contribution @AndysonDK!
The fix has been released in
@graphql-codegen/typescript-urql@3.5.7
and@graphql-codegen/typescript-urql-graphcache@2.2.10
📦Hi @tobz1000,
Indeed, it seems that the
WithTypename
type definition is incorrect, it should keep the givenT
type as it, not make all its properties optional.Would you have time to submit a PR to fix this and test it in your application? 👀