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

Automatically generated subscriptions seem to be wrong. #381

Open
hickscorp opened this issue Jan 17, 2025 · 4 comments
Open

Automatically generated subscriptions seem to be wrong. #381

hickscorp opened this issue Jan 17, 2025 · 4 comments

Comments

@hickscorp
Copy link
Contributor

hickscorp commented Jan 17, 2025

I have a simple subscription such as:

subscription UserUpdated($id: ID!, $bearerToken: String!) {
  userUpdated(bearerToken: $bearerToken, id: $id) {
    id
    email
    fullName
  }
}

Everything gets generated perfectly - and I can use different flavours of type-safe functions too... The problematic one seems to be Subscription$UserUpdated$Widget.

Server side when it's received, it looks like this:

[debug] ABSINTHE schema=PSWeb.Schema variables=%{"bearerToken" => "SOME_BEARER", "id" => "VXNlcjplM2Y0MTAxMC1iYjg2LTQwMmUtYjcxOS01YjMxOTgyOTBlNmY="}
---
subscription UserUpdated($id: ID!, $bearerToken: String!) {
  userUpdated(bearerToken: $bearerToken, id: $id) {
    id
    email
    fullName
    __typename
  }
  __typename # <--- NOTICE THIS
}
---

Therefore the server answers something like:

OperationException(linkException: UnknownException({type: error, id: d5963283-e488-4f6a-8803-899d2f1c1129, payload: [{message: Only one field is permitted on the root object when subscribing, locations: [{line: 1, column: 1}]}]}, stack:
), graphqlErrors: [])

The variables and most of the document are correct - but notice that there's an extra typename - that goes against the GQL standard unless I'm mistaken. There can only be one root field per sub.

I tried playing with build option (Eg addTypename: false) it fixed the problem, but would like to keep __typename whenever possible as it's a good discriminator for runtime typechecks...

Am I missing something?

EDIT Apologies I forgot the spec / reference and for this particular case here.

Copy link

👋 @hickscorp
Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible.
Please make sure you have provided enough context.

This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.

@mvarendorff
Copy link

@hickscorp
Copy link
Contributor Author

@mvarendorff I am answering from my phone, so I looked at the link you attached and I feel silly for even having raised the issue.

I apologize.

I will try it when I have access to the computer and report back. Thanks a bunch for "googling better than me" 👍

@hickscorp
Copy link
Contributor Author

hickscorp commented Jan 20, 2025

Hi there again @mvarendorff ,

I have tried what you suggested and I can confirm that it works.
I apologize for completelly missing this out from the docs...
So I made a small PR which will hopefully help other people: #382

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