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
{{ message }}
This repository has been archived by the owner on May 7, 2023. It is now read-only.
As you can see A) AuthType in src/__generated__/AppUserQuery.graphql.ts is union type, but B) AuthType in src/types/graphql.ts is enum type, which makes an error since union type is not compatible with enum type.
As we know the problem, we could simply check there is no error occurred if we change AuthType's type from union to enum.
$ yarn tsc
yarn run v1.22.4
$ tsc
✨ Done in 5.65s.
Unfortunately, AppUserQuery.graphql.ts is generated by relay-compiler library, which means we should not change it manually.
And it seems that this default behavior, changing enum to union type, is no problem to the community and its users according to some issues.
And we can't change AuthType enum type in src/types/graphql.ts to union type either. Because AuthType enum is also generated by graphql-codegen library, and also it is widely used in the clilent side code like below and it seems irreplaceable.
smallbee3
changed the title
Union type generated by relay-compiler is not compatible with enum type generated by codegen.
Union type generated by relay-compiler is not compatible with enum type generated by codegen
Jul 2, 2020
Specify project
Server
To Reproduce
client/src/App.tsx
$ cd client $ yarn tsc
Expected behavior
No error when running
yarn tsc
Screenshots
Describe the bug
There is a type error in the below code.
The error occurs in
setUser(me);
because the type of argumentme
is not compatible with the type ofsetUser
func's argument.A) The type of argument
me
type AppUserQueryResponse['me']
-> type AuthType
B) the type of
setUser
func's argumenttype User
-> type AuthType
As you can see A) AuthType in
src/__generated__/AppUserQuery.graphql.ts
is union type, but B) AuthType insrc/types/graphql.ts
is enum type, which makes an error since union type is not compatible with enum type.As we know the problem, we could simply check there is no error occurred if we change AuthType's type from union to enum.
$ yarn tsc yarn run v1.22.4 $ tsc ✨ Done in 5.65s.
Unfortunately,
AppUserQuery.graphql.ts
is generated by relay-compiler library, which means we should not change it manually.And it seems that this default behavior, changing enum to union type, is no problem to the community and its users according to some issues.
relay-tools/relay-compiler-language-typescript#81
relay-tools/relay-compiler-language-typescript#164
And we can't change AuthType enum type in
src/types/graphql.ts
to union type either. Because AuthType enum is also generated by graphql-codegen library, and also it is widely used in the clilent side code like below and it seems irreplaceable....
So, in my opinion, we should deal with union Type AuthType in
src/__generated__/AppUserQuery.graphql.ts
to fix the compatibility issue.Possible workarounds
1. Change union type AuthType to enum Type in
src/__generated__/AppUserQuery.graphql.ts
by a compiler or something else.To be honest, I don't know how to do this.
And I'm not sure whether this change makes no side effect.
2. Current makeshift
Add
// @ts-ignore ==> TODO
Related Issues
#147
The text was updated successfully, but these errors were encountered: