-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathschema.py
42 lines (36 loc) · 1.35 KB
/
schema.py
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
# -*- coding: utf-8 -*-
from graphql.type.definition import GraphQLArgument
from graphql.type.definition import GraphQLField
from graphql.type.definition import GraphQLNonNull
from graphql.type.definition import GraphQLObjectType
from graphql.type.scalars import GraphQLString
from graphql.type.schema import GraphQLSchema
def resolve_raises(*_):
raise Exception('Throws!')
QueryRootType = GraphQLObjectType(
name='QueryRoot',
fields={
'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
'request': GraphQLField(GraphQLNonNull(GraphQLString),
resolver=lambda obj, args, context, info: context.args.get('q')),
'context': GraphQLField(GraphQLNonNull(GraphQLString),
resolver=lambda obj, args, context, info: context),
'test': GraphQLField(
type=GraphQLString,
args={
'who': GraphQLArgument(GraphQLString)
},
resolver=lambda obj, args, context, info: 'Hello %s' % (args.get('who') or 'World')
)
}
)
MutationRootType = GraphQLObjectType(
name='MutationRoot',
fields={
'writeTest': GraphQLField(
type=QueryRootType,
resolver=lambda *_: QueryRootType
)
}
)
Schema = GraphQLSchema(QueryRootType, MutationRootType)