-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathschema.py
More file actions
45 lines (35 loc) · 1.13 KB
/
schema.py
File metadata and controls
45 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from graphql import (
GraphQLArgument,
GraphQLField,
GraphQLNonNull,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
)
def resolve_thrower(*_args):
raise Exception("Throws!")
def resolve_request(_obj, info):
return info.context.get("q")
def resolve_context(_obj, info):
return str(info.context)
QueryRootType = GraphQLObjectType(
name="QueryRoot",
fields={
"thrower": GraphQLField(GraphQLNonNull(GraphQLString), resolve=resolve_thrower),
"request": GraphQLField(GraphQLNonNull(GraphQLString), resolve=resolve_request),
"context": GraphQLField(GraphQLNonNull(GraphQLString), resolve=resolve_context),
"test": GraphQLField(
type_=GraphQLString,
args={"who": GraphQLArgument(GraphQLString)},
resolve=lambda obj, info, who="World": "Hello %s" % who,
),
},
)
MutationRootType = GraphQLObjectType(
name="MutationRoot",
fields={
"writeTest": GraphQLField(type_=QueryRootType, resolve=lambda *_: QueryRootType)
},
)
schema = GraphQLSchema(QueryRootType, MutationRootType)
invalid_schema = GraphQLSchema()