File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,11 @@ So, we can finish our schema like this:
48
48
class MyMutations (graphene .ObjectType ):
49
49
create_person = CreatePerson.Field()
50
50
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)
52
56
53
57
Executing the Mutation
54
58
----------------------
Original file line number Diff line number Diff line change @@ -381,7 +381,7 @@ class Schema:
381
381
questions about the types through introspection.
382
382
383
383
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*
385
385
data in your Schema.
386
386
mutation (Optional[Type[ObjectType]]): Root mutation *ObjectType*. Describes entry point for
387
387
fields to *create, update or delete* data in your API.
Original file line number Diff line number Diff line change @@ -59,3 +59,12 @@ def test_schema_str():
59
59
def test_schema_introspect ():
60
60
schema = Schema (Query )
61
61
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."
You can’t perform that action at this time.
0 commit comments