-
Notifications
You must be signed in to change notification settings - Fork 276
Union's resolveType doesn't know about __typename #188
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
Comments
Looks like it's possible to get this working by modifying
I've no idea how to actually get this as a proper fix though. Well, that was just part of it, to be able to correctly return |
This is indeed an oversight and something I recently also realized/encountered as well when trying to build some union types using the same pattern from that talk. Will look to get a fix in for this soon! |
Agree. We will need to make this invariant safe though. For example, making the resolver for a union-typed field be forced to include |
This feels like a bug to me, more than a feature. |
This makes sense to me. |
Started thinking more about this, and there's a few things to address here. First, I believe the messaging / behavior of the current warning message is incorrect:
You should always implement this somehow, The question is really whether you want a custom resolve or whether you just want the default behavior, as @ThisIsMissEm is re-implementing by hand with the If you are in-fact providing the
So essentially if you call The tricky thing with typings here is that if you are using the default execution algorithm, @ThisIsMissEm does this sound like a reasonable approach/change to the issue you describe? I was thinking of adding the change in the messaging / ability to call |
So all unions will have to be written as:
Wouldn't it be better to do:
Or even:
|
As I suggested, yes, though I suppose I was only looking at it as an improvement on the current alternative - rather than revisiting why it is how it is...
IIRC this API wasn't originally possible it was due to some issues w/ type completion/safety on object members not being correct, I think I left a comment about this as a reminder for a similar issue on interfaces, need to revisit if anything has changed here: It looks like the PR referenced there got merged, so maybe it is supported now? Will give it a shot and see if we can adjust/simplify the API here. I guess we could also make the assumption that if |
Just following up on this @tgriesser. What is the behavior today? Should we still be using |
I'd also like to follow up on this. What is the recommended approach? |
+1 |
Awesome @jasonkuhrt - How long are your sprints? Excited to see this getting worked on! 🙌 |
@jesperhalborglego two weeks. Note this issue is considered a stretch goal of our sprint :) |
Thinking about this.
|
Here is a revised spec following discussion with @Weakky
References |
Very nice analysis and writeup, and the proposed solution is great in my opinion 👏 |
One of Nexus' opinions originally was not to attempt to support At least in my experience, it felt like having two ways to do the same thing felt odd / distracting, and you were better off just implementing
This sounds good to me. I am trying to remember if there was a typings reason for having
Interested to hear thoughts re: feedback above on the value of implementing |
Thanks for the feedback @tgriesser!
I think the main point @Weakky raised was that If we all agree that it is OK for Nexus Schema to technically support all techniques then I see this discussion about what the best default is. Do you all see it the same way? I don't feel strongly personally about the central @Weakky thoughts? |
So most of my reasoning for adding
While everybody seems to be using Here's my humble question to you @tgriesser: Why are we placing the logic to discriminate different types in a single place when we have the opportunity to cleanly couple that to the types themselves? (Which enables a type to be used in any interface/union type, multiple times, without refactoring anything) With
|
Thanks for the great write up @Weakky. I'll wear my devil's advocate hat and share some thoughts. Also again to be clear I think we're merely discussing what the default enabled checks should be.
I misunderstood :)
I believe this problem is shared by both techniques. Either a central function runs that returns a type name or a little internal loop runs over all the
Overall I am leaning towards @Weakky's point of view here, that the default strategy should be --edit More discussion with @Weakky and I feel pretty strong now that |
I feel both approach should be allowed for maximum flexibility. |
@Sytten The docs should answer any questions you have. If not we need better docs. Let us know! https://github.com/graphql-nexus/schema/pull/602/files#diff-2e34d9dffe181b23833ccc9ee55d87eb6b175066626b0e21feeafd145d94efa5 |
Doc seems good! I am glad multiple strategies are allowed. |
I'm currently trying to build a graphql server that uses the Result Union's pattern described by @sachee, whereby fields that may error in normal operation when resolving them return Union type of something like
union PostResult = NotFound | Post
There's a video describing this pattern here: https://www.youtube.com/watch?v=GYBhHUGR1ZY
However, if you have:
Then you get an error telling you that
__typename
isn't a property ofitem
, even though your resolver for the field that uses this PostResult union can definitely return the__typename
field.I think the type assigned to the callback argument in
t.resolveType
should have the__typename
property available.For now, I'm able to work-around this by using
item['__typename']
but that's a pretty ugly hack.The text was updated successfully, but these errors were encountered: