Skip to content

Commit ecd11cc

Browse files
authored
Revert 1213 update mutation docs (#1214)
* Revert "Update requirement for Query type in mutation docs (#1213)" This reverts commit a9625da. * Add test to check that Query type must be defined
1 parent 324df19 commit ecd11cc

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/types/mutations.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ So, we can finish our schema like this:
4848
class MyMutations(graphene.ObjectType):
4949
create_person = CreatePerson.Field()
5050
51-
schema = graphene.Schema(mutation=MyMutations)
51+
# We must define a query for our schema
52+
class Query(graphene.ObjectType):
53+
person = graphene.Field(Person)
54+
55+
schema = graphene.Schema(query=Query, mutation=MyMutations)
5256
5357
Executing the Mutation
5458
----------------------

graphene/types/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class Schema:
381381
questions about the types through introspection.
382382
383383
Args:
384-
query (Optional[Type[ObjectType]]): Root query *ObjectType*. Describes entry point for fields to *read*
384+
query (Type[ObjectType]): Root query *ObjectType*. Describes entry point for fields to *read*
385385
data in your Schema.
386386
mutation (Optional[Type[ObjectType]]): Root mutation *ObjectType*. Describes entry point for
387387
fields to *create, update or delete* data in your API.

graphene/types/tests/test_schema.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,12 @@ def test_schema_str():
5959
def test_schema_introspect():
6060
schema = Schema(Query)
6161
assert "__schema" in schema.introspect()
62+
63+
64+
def test_schema_requires_query_type():
65+
schema = Schema()
66+
result = schema.execute("query {}")
67+
68+
assert len(result.errors) == 1
69+
error = result.errors[0]
70+
assert error.message == "Query root type must be provided."

0 commit comments

Comments
 (0)