From ecd11ccc1e53d965e355742e9fef19bc9286522e Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Mon, 29 Jun 2020 15:53:53 +0100 Subject: [PATCH] Revert 1213 update mutation docs (#1214) * Revert "Update requirement for Query type in mutation docs (#1213)" This reverts commit a9625dac0ed07d5fb35adc83cbc41387755f080f. * Add test to check that Query type must be defined --- docs/types/mutations.rst | 6 +++++- graphene/types/schema.py | 2 +- graphene/types/tests/test_schema.py | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) 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."