Skip to content

Automatically generated subscriptions seem to be wrong. #381

@hickscorp

Description

@hickscorp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions