diff --git a/docs/types/mutations.rst b/docs/types/mutations.rst index 543f39b4..f8c76f35 100644 --- a/docs/types/mutations.rst +++ b/docs/types/mutations.rst @@ -48,7 +48,11 @@ So, we can finish our schema like this: class MyMutations(graphene.ObjectType): create_person = CreatePerson.Field() - schema = graphene.Schema(mutation=MyMutations) + # We must define a query for our schema + class Query(graphene.ObjectType): + person = graphene.Field(Person) + + schema = graphene.Schema(query=Query, mutation=MyMutations) Executing the Mutation ---------------------- diff --git a/graphene/types/schema.py b/graphene/types/schema.py index 0b6e9dac..29ead4a7 100644 --- a/graphene/types/schema.py +++ b/graphene/types/schema.py @@ -381,7 +381,7 @@ class Schema: questions about the types through introspection. Args: - query (Optional[Type[ObjectType]]): Root query *ObjectType*. Describes entry point for fields to *read* + query (Type[ObjectType]): Root query *ObjectType*. Describes entry point for fields to *read* data in your Schema. mutation (Optional[Type[ObjectType]]): Root mutation *ObjectType*. Describes entry point for fields to *create, update or delete* data in your API. diff --git a/graphene/types/tests/test_schema.py b/graphene/types/tests/test_schema.py index 7a1c299a..0c85e170 100644 --- a/graphene/types/tests/test_schema.py +++ b/graphene/types/tests/test_schema.py @@ -59,3 +59,12 @@ def test_schema_str(): def test_schema_introspect(): schema = Schema(Query) assert "__schema" in schema.introspect() + + +def test_schema_requires_query_type(): + schema = Schema() + result = schema.execute("query {}") + + assert len(result.errors) == 1 + error = result.errors[0] + assert error.message == "Query root type must be provided."