Skip to content

Empty error list returned when there are none #111

Closed
@tcsavage

Description

@tcsavage

The GraphQL spec specifies that the errors entry in the result be non-empty if errors occurred, and should be absent entirely if no errors occurred. The graphql-core implementation returns an empty list if no errors occurred. This is an issue for compatibility with some GraphQL client libraries.

In my particular case, I have a GraphQL server using graphql-core, and a client using the Apollo JS library. There are times that Apollo thinks an error occurred when it did not, there was just an empty list of errors, when it expected an absent errors entry, null or similar. While this could certainly be fixed in Apollo, it wouldn't be a problem if graphql-core implemented the spec correctly.

I think graphql-core should return None instead of an empty list. While it's still not 100% true to the spec, it's certainly closer and would help solve issues like the above.

I have a patch which fixes this and I'd be happy to submit it if this is agreed to be a problem.


Minimal case:
Using graphql-core 1.0.1

from graphql import (
    graphql,
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLField,
    GraphQLString
)

schema = GraphQLSchema(
  query= GraphQLObjectType(
    name='RootQueryType',
    fields={
      'hello': GraphQLField(
        type= GraphQLString,
        resolver=lambda *_: 'world'
      )
    }
  )
)

query = '{ hello }'

result = graphql(schema, query)

print(result.errors)

Prints []
Expected None

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