Skip to content
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

WrapFields Incompatibility with Subscriptions #2282

Closed
tylermenezes opened this issue Nov 26, 2020 · 14 comments
Closed

WrapFields Incompatibility with Subscriptions #2282

tylermenezes opened this issue Nov 26, 2020 · 14 comments

Comments

@tylermenezes
Copy link

It seems like adding a WrapFields transform to a schema causes all emitted queries to include the following root selection:

{ kind: 'Field', name: { kind: 'Name', value: '__typename' } }

This causes all subscriptions to fail (because of the restriction against having more than one root field in a subscription). This is true even though the WrapFields transform isn't wrapping anything related to a Subscription.

Am I doing something totally wrong here, or is there a known way around this? If it's a new bug I can try to come up with a stand-alone reproduction.

@yaacovCR
Copy link
Collaborator

Thanks for pointing out. Definitely a bug.

@yaacovCR
Copy link
Collaborator

Minimal reproduction in form of PR with failing test or separate repo would be extremely helpful

@yaacovCR
Copy link
Collaborator

Related: graphql/graphql-js#2861

@yaacovCR
Copy link
Collaborator

Related: graphql/graphql-spec#776

@yaacovCR
Copy link
Collaborator

@tylermenezes

are you able to confirm working with the alpha versions in linked PR: #2292 (comment)

@yaacovCR
Copy link
Collaborator

thanks again for reporting!

@tylermenezes
Copy link
Author

I'll take a look first thing tomorrow morning, thank you as usual for quickly fixing what I assume are really obscure bugs.

@tylermenezes
Copy link
Author

Was this if statement supposed to be:

      if (
        (this.subscriptionTypeName && parentTypeName !== this.subscriptionTypeName)
        && (this.dataTransformer != null || this.errorsTransformer != null)
      ) {

As-is, it doesn't work because this.errorsTransformer is a function when called in WrapFields, which is causing the if statement to always return true. If I change it like that, it works 😄

(I'll be honest that I don't fully understand this code still, so I might be misinterpreting what this statement is supposed to do.)

Thank you again for your help with this!

@yaacovCR
Copy link
Collaborator

Yes, that was it, seems I had speed over accuracy/tests on this one. But if you are able to submit PR I can merge

@tylermenezes
Copy link
Author

Will do. I am troubleshooting another issue which I don't think is related, but I want to confirm that first.

@yaacovCR
Copy link
Collaborator

In terms of what the code is doing, we are annotating every object with type name in order to get a fully type result....

That way we can traverse the results and unwrap fields as necessary no matter how nested deeply they are....

With this work around, we assume that if type name is not available it is because it is The root subscription type which is impossible to annotate with type name

@tylermenezes
Copy link
Author

Thank you! The issue I was debugging was just from upgrading from graphql-tools 6 to 7. Submitted the PR here: #2299

And thank you for the help in understanding this! For the past 5 years my main job has not been as a developer (I work for a tech education nonprofit), but I hope to actually read the GraphQL spec over the winter holidays so I can understand more about how this all works.

@yaacovCR
Copy link
Collaborator

Second attempt has been released!

@tylermenezes
Copy link
Author

Working for me! Thank you once again! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants