You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Bertrand Delacretaz (Jira)" <ji...@apache.org> on 2020/10/22 14:56:00 UTC

[jira] [Resolved] (SLING-9847) GraphQL query error responses do not conform to GraphQL specification

     [ https://issues.apache.org/jira/browse/SLING-9847?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bertrand Delacretaz resolved SLING-9847.
----------------------------------------
      Assignee: Bertrand Delacretaz
    Resolution: Fixed

Thank you for this contribution, makes sense, I have merged your PR.

> GraphQL query error responses do not conform to GraphQL specification
> ---------------------------------------------------------------------
>
>                 Key: SLING-9847
>                 URL: https://issues.apache.org/jira/browse/SLING-9847
>             Project: Sling
>          Issue Type: Bug
>          Components: GraphQL
>    Affects Versions: GraphQL Core 0.0.6
>            Reporter: Jabran Asghar
>            Assignee: Bertrand Delacretaz
>            Priority: Major
>             Fix For: GraphQL Core 0.0.8
>
>
> *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:*
> {code:java}
> Query
> {
>   articles {
>     items {
>       _path
>       author_DOES_NOT_EXIST
>     }
>   }
> }
> {code}
> (Note: author_DOES_NOT_EXIST field name is intentionally wrong.)
> *Current response:*
> {code:java}
> {
>   "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"
> }
> {code}
>  
> *Expected response:*
> {code:java}
> {
>   "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"
>       }
>     }
>   ]
> }
> {code}
> 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]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)