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

Wrong implementation of GraphQL over WebSocket Error message #7706

Closed
enisdenjo opened this issue Oct 20, 2021 · 1 comment
Closed

Wrong implementation of GraphQL over WebSocket Error message #7706

enisdenjo opened this issue Oct 20, 2021 · 1 comment
Assignees
Labels
k/bug Something isn't working

Comments

@enisdenjo
Copy link

enisdenjo commented Oct 20, 2021

Version Information

Server Version: Hasura Cloud

Environment

Cloud

Keywords

graphql-ws,messages,error,websocket

What is the current behaviour?

The error message provides an object with the errors field set to an array of GraphQLErrors.

{
  "type": "error",
  "id": "1",
  "payload": {
    "errors": [
      {
        "extensions": {
          "path": "$.selectionSet.somefield",
          "code": "validation-failed"
        },
        "message": "field \"somefield\" not found in type: 'query_root'"
      }
    ]
  }
}

What is the expected behaviour?

The error message implements the GraphQL over WebSocket Error message.

{
  "type": "error",
  "id": "1",
- "payload": {
-   "errors": [
-     {
-       "extensions": {
-         "path": "$.selectionSet.somefield",
-         "code": "validation-failed"
-       },
-       "message": "field \"somefield\" not found in type: 'query_root'"
-     }
-   ]
- }
+ "payload": [
+   {
+     "extensions": {
+       "path": "$.selectionSet.somefield",
+       "code": "validation-failed"
+     },
+     "message": "field \"somefield\" not found in type: 'query_root'"
+   }
+ ]
}

How to reproduce the issue?

  1. Create a project on Hasura Cloud or use mine https://engaging-filly-31.hasura.app/v1/graphql
  2. Copy GraphQL API URL
  3. Connect using graphql-ws without setting the authorization header (you can use the GraphiQL ❤️ graphql-ws gist)
  4. Execute a query with invalid/missing fields
  5. Connection Closed: 4400 because the Error message is malformed

Screenshots or Screencast

Screenshot 2021-10-20 at 15 02 54

Any possible solutions?

  1. (recommended) Implement the GraphQL over WebSocket Error message when sending GraphQLErrors as presented above.
  2. Use the Next message to transmit an error as a part of the GraphQL's ExecutionResult like this:
{
- "type": "error",
+ "type": "next",
  "id": "1",
  "payload": {
    "errors": [
      {
        "extensions": {
          "path": "$.selectionSet.somefield",
          "code": "validation-failed"
        },
        "message": "field \"somefield\" not found in type: 'query_root'"
      }
    ]
  }
}

Additional info

This issue is quite critical for clients using graphql-ws because malformed messages result in immediate connection termination, as per the GraphQL over WebSocket Protocol.

Can you identify the location in the source code where the problem exists?

No.

If the bug is confirmed, would you be willing to submit a PR?

No, I am not familiar with Haskell.

@paritosh-08
Copy link
Contributor

Closed via a886da2

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

Successfully merging a pull request may close this issue.

3 participants