-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add __typename to base TS and flow types #1701
Conversation
Hi @jefflewis , thank you for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should make skipTypename: true
by default?
And maybe |
@kamilkisiela why only for interfaces? I think we can add it for types as well. |
@kamilkisiela Adding @dotansimha I was unsure of a good way to refactor this to use a It seems that both could be addressed in a future commit. Anyone needing typenames would be helped by this. and adding |
@jefflewis ok, seems reasonable. About the default, I think since {
users: (parent, args, context, info) {
// parent.__typename is accessible but undefined
}
} |
@kamilkisiela I'm not sure I understand what you mean here... If Changing the default to not generate |
I had to rebase after all of the packages moved into folders... |
|
@cristianosantos95 this is for GraphQL operations, i.e. query, mutation, subscription and fragment, but not for the GraphQL types. |
Is there anything I need to change about this before it gets merged and released? I'm more than willing to update the PR with any necessary changes. |
@tokenvolt you mean this pull request or the one that's on the docs? Either way, none of my generated definitions have |
@cristianosantos95 on the docs. This PR adds |
Hi! Thanks for library and PR. |
Hi @jefflewis , Sorry for the delay, I hope I'll find the time to merge it in the next days. |
No worries @dotansimha! Ping me if you need me to make any changes. |
@jefflewis Is this helping or related to this issue? |
@dotansimha sorry to push on this, but do you have an expectation of when to merge this PR? I'm not getting |
We are also waiting eagerly for this PR to be merged and released, we need it to migrate from Apollo's type generation |
Hi all, sorry for the delay. I'm rebasing this PR manually now, and then I'll merge it to |
I think, at the moment, I'll merge it as-is to allow the base plugins to add @jefflewis I did some minor changes to your PR (moved the Making sure now that everything works, and then I'll merge it :) |
@@ -287,6 +291,7 @@ describe('TypeScript', () => { | |||
|
|||
expect(result).toBeSimilarStringTo(` | |||
export type MyType = { | |||
__typename?: "MyType", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be readonly __typename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, thanks.
As seen in these issues,
__typename
being included in the base type will help with comparing types returned by unions.I hooked into the
skipTypenames
configuration flag. Ifundefined
orfalse
,__typename
will be generated as an optional type in base types.