You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I am using msw to mock the request from Relay Client and return a dummy response. In order to help creating dummy responses, I developed graphql-fabbrica, which is a graphql-code-generator's plugin. This plugin allows users to create dummy data that matches the type definitions generated by @graphql-codegen/typescript. I use this to create dummy responses.
graphql-fabbrica cannot generate data that passes type checking because this __is<AbstractType> is not included in the type definition generated by @graphql-codegen/typescript.
Describe the solution you'd like
I would like to add the following two options to @graphql-codegen/typescript.
They are similar to the skipTypename, nonOptionalTypename option. If skipIsAbstractType === false, add __is<AbstractType> to the type definition, if nonOptionalIsAbstractType === true, make the field optional.
If this proposal is acceptable, I am going to create a Pull Request. Is this proposal acceptable?
mizdra
changed the title
[@graphql-codegen/typescript] Support for __is<AbstractType> field in relays
[@graphql-codegen/typescript] Support for __is<AbstractType> field in relay
Sep 9, 2023
mizdra
changed the title
[@graphql-codegen/typescript] Support for __is<AbstractType> field in relay
[@graphql-codegen/typescript] Support for __is<AbstractType> field in Relay
Sep 9, 2023
Is your feature request related to a problem? Please describe.
I am using msw to mock the request from Relay Client and return a dummy response. In order to help creating dummy responses, I developed graphql-fabbrica, which is a graphql-code-generator's plugin. This plugin allows users to create dummy data that matches the type definitions generated by
@graphql-codegen/typescript
. I use this to create dummy responses.The above example works well. However, a problem occurs when trying to define a dummy response for a query that returns a union or interface.
When this code is type-checked by
tsc
, the following type errors are reported.This is caused by the type definitions generated by the relate-compiler.
The relay-compiler converts the original query to one with the field
__is<AbstractType>
added so that the Relay Client can determine if the type implements the interface (more details: facebook/relay#3129 (comment),repo:facebook/relay /__is<AbstractType>/
).graphql-fabbrica
cannot generate data that passes type checking because this__is<AbstractType>
is not included in the type definition generated by@graphql-codegen/typescript
.Describe the solution you'd like
I would like to add the following two options to
@graphql-codegen/typescript
.skipIsAbstractType
(type:boolean
, default:true
)nonOptionalIsAbstractType
(type:boolean
, default:false
)They are similar to the
skipTypename
,nonOptionalTypename
option. IfskipIsAbstractType === false
, add__is<AbstractType>
to the type definition, ifnonOptionalIsAbstractType === true
, make the field optional.Describe alternatives you've considered
No response
Is your feature request related to a problem? Please describe.
Demo codes: https://github.com/mizdra/example-relay-is-abstruct-type
The text was updated successfully, but these errors were encountered: