Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-9847

GraphQL query error responses do not conform to GraphQL specification

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • GraphQL Core 0.0.6
    • GraphQL Core 0.0.8
    • GraphQL
    • None

    Description

      Problem:
      Currently, the DefaultQueryExecutor.execute method does not let GraphQL query execution errors pass on to result. After executing GraphQL query, any errors are accumulated as strings and wrapped into an exception [0]. This causes errors to be omitted from GraphQL response, as the result is never returned [1].

      As a consequence, The GraphQL client receives a cryptic error response, which is

      • not conformed to GraphQL specs
      • not useful, as it does not give a hint what actually went wrong

      Proposed solution:
      An exception in such a case should not be thrown, rather errors should be returned as part of the GraphQL result, conforming to GraphQL specs [2].

      Example:

      Query
      {
        articles {
          items {
            _path
            author_DOES_NOT_EXIST
          }
        }
      }
      

      (Note: author_DOES_NOT_EXIST field name is intentionally wrong.)

      Current response:

      {
        "message": "Failed to execute 'text' on 'Response': body stream already read",
        "stack": "TypeError: Failed to execute 'text' on 'Response': body stream already read\n    at https://<host-url>/graphiql.html:64:29"
      }
      

       

      Expected response:

      {
        "errors": [
          {
            "message": "Validation error of type FieldUndefined: Field 'author_DOES_NOT_EXIST' in type 'ArticleModel' is undefined @ 'articles/items/author_DOES_NOT_EXIST'",
            "locations": [
              {
                "line": 5,
                "column": 7
              }
            ],
            "extensions": {
              "classification": "ValidationError"
            }
          }
        ]
      }
      

      Which is more meaningful, and conformed to GraphQL errors scpecification [2].

      [0] https://github.com/apache/sling-org-apache-sling-graphql-core/blob/90f579888ed3450a625e7bdbbbbf9b7d599f14b6/src/main/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutor.java#L148

      [1] https://github.com/apache/sling-org-apache-sling-graphql-core/blob/90f579888ed3450a625e7bdbbbbf9b7d599f14b6/src/main/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutor.java#L152

      [2] http://spec.graphql.org/June2018/#sec-Errors

      Attachments

        Issue Links

          Activity

            People

              bdelacretaz Bertrand Delacretaz
              jasghar Jabran Asghar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: