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

bug: 'errors' property is never populated for GraphQL subscriptions #914

Closed
raindrop23 opened this issue Mar 7, 2022 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@raindrop23
Copy link

Expected behavior

When I receive an event in the Response Stream for a GraphQL subscription, I expect the errors property to be non-empty if an error occurred for any field during the execution of the GraphQL operation.

Actual behavior

The errors property is always empty.

Steps to reproduce

These steps are based on a slightly modified version of https://github.com/Netflix/dgs-examples-kotlin .

1

Get a local copy of raindrop23/dgs-examples-kotlin@d44060a . (That commit is the only change I made after forking dgs-examples-kotlin.)

2

Start the GraphQL web service locally.

3

Install websocat. (Here are installation instructions.)

4

Run this command:

websocat ws://localhost:8080/subscriptions --protocol graphql-ws -v

5

Paste in the following line:

{"type":"connection_init"}

Paste it in as a full line, so that the cursor goes to the start of the next line.

6

Paste in the following line:

{"id":"5","type":"start","payload":{"query":"subscription { reviewAdded(showId: 1) {  ipAddress starScore username  } }"}}

Again, paste it in as a full line.

7

In a local web browser, access GraphiQL at http://localhost:8080/graphiql. Enter the following GraphQL operation and execute it.

mutation {
  addReview(review: {
    showId: 1
    username: "user1"
    starScore: 5
  }) {
    __typename
  }
}

8

Look at the terminal where websocat is running. Observe that the review has appeared as an event in the Response Stream. Observe that the value of ipAddress is "1.1.1.1".

9

Return to GraphiQL. Slightly edit the value of username and starScore to produce the following operation, then execute it.

mutation {
  addReview(review: {
    showId: 1
    username: "user2"
    starScore: 1
  }) {
    __typename
  }
}

10

In the output of the local GraphQL web service, observe that a stack trace has appeared, preceded by the message "Exception while executing data fetcher for /reviewAdded/ipAddress: null". (That message is because an exception was thrown on this line of code.)

11

Look at the terminal where websocat is running. Observe that the review has appeared as an event in the Response Stream. Observe that the value of ipAddress is null. Observe also that the value of the errors property is an empty array.

Discussion

Further to the last step: it's clear from the GraphQL specification that errors should be non-empty. Section 6.2.3.2 says:

  1. Let errors be any field errors produced while executing the selection set.

Clean-up

You can terminate the websocat process by typing Control-C.

@raindrop23 raindrop23 added the bug Something isn't working label Mar 7, 2022
@berngp
Copy link
Contributor

berngp commented Mar 8, 2022

Thanks for reporting with such a detail set of instructions.

@jord1e
Copy link
Contributor

jord1e commented Mar 8, 2022

Shouldn't

Be

- val message = OperationMessage(GQL_DATA, DataPayload(er.getData()), id)
+ val message = OperationMessage(GQL_DATA, DataPayload(er.getData(), er.getErrors()), id)
// or Kotlin probably:
+ val message = OperationMessage(GQL_DATA, DataPayload(er.getData(), er.errors), id)

See line 70

data class DataPayload(
@JsonProperty("data")
val data: Any?,
@JsonProperty("errors")
val errors: List<Any>? = emptyList()
) : MessagePayload

SSE does have it

@srinivasankavitha
Copy link
Contributor

Yes, that is the issue. We will fix this in the upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants