def get_args(): return { 'to': GraphQLArgument( type=GraphQLNonNull(GraphQLString), description='Value to default to', ), }
GraphQLObjectType, ) from graphql.type.scalars import GraphQLString from graphql.type.schema import GraphQLSchema def resolve_raises(*_): raise Exception("Throws!") # Sync schema QueryRootType = GraphQLObjectType( name="QueryRoot", fields={ "thrower": GraphQLField(GraphQLNonNull(GraphQLString), resolve=resolve_raises), "request": GraphQLField( GraphQLNonNull(GraphQLString), resolve=lambda obj, info: info.context["request"].args.get("q"), ), "context": GraphQLField( GraphQLObjectType( name="context", fields={ "session": GraphQLField(GraphQLString), "request": GraphQLField( GraphQLNonNull(GraphQLString),
) from graphql.type.scalars import GraphQLString from graphql.type.schema import GraphQLSchema def resolve_raises(*args): # pylint: disable=unused-argument raise Exception("Throws!") # Sync schema QueryRootType = GraphQLObjectType( name='QueryRoot', fields={ 'thrower': GraphQLField( GraphQLNonNull(GraphQLString), resolver=resolve_raises, ), 'request': GraphQLField( GraphQLNonNull(GraphQLString), resolver=lambda obj, info, *args: \ info.context['request'].query.get('q'), ), 'context': GraphQLField( GraphQLNonNull(GraphQLString), resolver=lambda obj, info, *args: info.context, ), 'test': GraphQLField( type=GraphQLString, args={'who': GraphQLArgument(GraphQLString)}, # resolver=lambda obj, args, context, info: \
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, 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, info: info.context.params.get('q')), 'context': GraphQLField(GraphQLNonNull(GraphQLString), resolver=lambda obj, info: info.context), 'test': GraphQLField( type=GraphQLString, args={ 'who': GraphQLArgument(GraphQLString) }, resolver=lambda obj, info, who='World': 'Hello %s' % who ) } ) MutationRootType = GraphQLObjectType( name='MutationRoot', fields={ 'writeTest': GraphQLField(
IntBox = GraphQLObjectType( "IntBox", fields=lambda: { "scalar": GraphQLField(GraphQLInt), "deepBox": GraphQLField(IntBox), "unrelatedField": GraphQLField(GraphQLString), "listStringBox": GraphQLField(GraphQLList(StringBox)), "stringBox": GraphQLField(StringBox), "intBox": GraphQLField(IntBox), }, interfaces=[SomeBox], ) NonNullStringBox1 = GraphQLInterfaceType( "NonNullStringBox1", {"scalar": GraphQLField(GraphQLNonNull(GraphQLString))}, resolve_type=lambda *_: StringBox, ) NonNullStringBox1Impl = GraphQLObjectType( "NonNullStringBox1Impl", { "scalar": GraphQLField(GraphQLNonNull(GraphQLString)), "deepBox": GraphQLField(StringBox), "unrelatedField": GraphQLField(GraphQLString), }, interfaces=[SomeBox, NonNullStringBox1], ) NonNullStringBox2 = GraphQLInterfaceType( "NonNullStringBox2",
raise ValueError("Throws!") def resolve_request(_obj, info): return info.context.get("q") def resolve_context(_obj, info): return str(info.context) def resolve_test(_obj, _info, who="World"): return "Hello {}".format(who) NonNullString = GraphQLNonNull(GraphQLString) QueryRootType = GraphQLObjectType( name="QueryRoot", fields={ "error": GraphQLField(NonNullString, resolver=resolve_error), "request": GraphQLField(NonNullString, resolver=resolve_request), "context": GraphQLField(NonNullString, resolver=resolve_context), "test": GraphQLField( GraphQLString, {"who": GraphQLArgument(GraphQLString)}, resolver=resolve_test,
GraphQLNonNull, GraphQLObjectType, ) from graphql.type.scalars import GraphQLString from graphql.type.schema import GraphQLSchema def resolve_raises(*_): raise Exception("Throws!") # Sync schema QueryRootType = GraphQLObjectType( name="QueryRoot", fields={ "thrower": GraphQLField(GraphQLNonNull(GraphQLString), resolve=resolve_raises,), "request": GraphQLField( GraphQLNonNull(GraphQLString), resolve=lambda obj, info, *args: info.context["request"].query.get("q"), ), "context": GraphQLField( GraphQLNonNull(GraphQLString), resolve=lambda obj, info, *args: info.context["request"], ), "test": GraphQLField( type_=GraphQLString, args={"who": GraphQLArgument(GraphQLString)}, resolve=lambda obj, info, who=None: "Hello %s" % (who or "World"), ), }, )
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType from graphql.type.scalars import GraphQLString, GraphQLInt from graphql.type.schema import GraphQLSchema def resolve_raises(*_): raise Exception("Throws!") QueryRootType = GraphQLObjectType( name='QueryRoot', fields={ 'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises), 'context': GraphQLField( type=GraphQLNonNull(GraphQLString), resolver=lambda self, info, **kwargs: info.context), 'test': GraphQLField( type=GraphQLNonNull(GraphQLString), resolver=lambda self, info: 'Hello World' ), 'test_args': GraphQLField( type=GraphQLNonNull(GraphQLString), args={'name': GraphQLArgument(GraphQLString)}, resolver=lambda self, info, **kwargs: 'Hello {}'.format(kwargs.get("name")) ), 'test_def_args': GraphQLField( type=GraphQLString, args={'name': GraphQLArgument(GraphQLString),}, resolver=lambda self, info, name="World": 'Hello {}'.format(name) )
IntBox = GraphQLObjectType( 'IntBox', fields=lambda: { 'scalar': GraphQLField(GraphQLInt), 'deepBox': GraphQLField(IntBox), 'unrelatedField': GraphQLField(GraphQLString), 'listStringBox': GraphQLField(GraphQLList(StringBox)), 'stringBox': GraphQLField(StringBox), 'intBox': GraphQLField(IntBox), }, interfaces=[SomeBox] ) NonNullStringBox1 = GraphQLInterfaceType('NonNullStringBox1', { 'scalar': GraphQLField(GraphQLNonNull(GraphQLString)), }, resolve_type=lambda *_: StringBox) NonNullStringBox1Impl = GraphQLObjectType('NonNullStringBox1Impl', { 'scalar': GraphQLField(GraphQLNonNull(GraphQLString)), 'deepBox': GraphQLField(StringBox), 'unrelatedField': GraphQLField(GraphQLString) }, interfaces=[SomeBox, NonNullStringBox1]) NonNullStringBox2 = GraphQLInterfaceType('NonNullStringBox2', { 'scalar': GraphQLField(GraphQLNonNull(GraphQLString)) }, resolve_type=lambda *_: StringBox) NonNullStringBox2Impl = GraphQLObjectType('NonNullStringBox2Impl', { 'scalar': GraphQLField(GraphQLNonNull(GraphQLString)), 'unrelatedField': GraphQLField(GraphQLString),
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType from graphql.type.scalars import GraphQLString, GraphQLBoolean from graphql.type.schema import GraphQLSchema Query = GraphQLObjectType( name='Query', fields={ 'testString': GraphQLField( GraphQLNonNull(GraphQLString), resolver=lambda root, args, context, info: 'string returned') }) Subscription = GraphQLObjectType( name='Subscription', fields={ 'test_subscription': GraphQLField(type=GraphQLNonNull(GraphQLString), resolver=lambda root, args, context, info: root), 'test_filter_sub': GraphQLField(type=GraphQLNonNull(GraphQLString), args={'filter_bool': GraphQLArgument(GraphQLBoolean)}, resolver=lambda root, args, context, info: 'SUCCESS'), }) Schema = GraphQLSchema(Query, subscription=Subscription)