def test_prints_string_field_with_multiple_args_last_is_default(): output = print_single_field_schema( GraphQLField( type=GraphQLString, args=OrderedDict( [ ("argOne", GraphQLArgument(GraphQLInt)), ("argTwo", GraphQLArgument(GraphQLString)), ("argThree", GraphQLArgument(GraphQLBoolean, default_value=False)), ] ), ) ) assert ( output == """ schema { query: Root } type Root { singleField(argOne: Int, argTwo: String, argThree: Boolean = false): String } """ )
def test_prints_string_field_with_multiple_args(): output = print_single_field_schema( GraphQLField( type=GraphQLString, args=OrderedDict( [ ("argOne", GraphQLArgument(GraphQLInt)), ("argTwo", GraphQLArgument(GraphQLString)), ] ), ) ) assert ( output == """ schema { query: Root } type Root { singleField(argOne: Int, argTwo: String): String } """ )
def test_prints_string_field_with_multiple_args(): output = print_single_field_schema( GraphQLField(type=GraphQLString, args=OrderedDict([('argOne', GraphQLArgument(GraphQLInt)), ('argTwo', GraphQLArgument(GraphQLString))]))) assert output == '''
def test_prints_string_field_with_multiple_args_last_is_default(): output = print_single_field_schema( GraphQLField(type=GraphQLString, args=OrderedDict([ ('argOne', GraphQLArgument(GraphQLInt)), ('argTwo', GraphQLArgument(GraphQLString)), ('argThree', GraphQLArgument(GraphQLBoolean, default_value=False)) ]))) assert output == '''
def test_prints_input_type(): InputType = GraphQLInputObjectType( name="InputType", fields={"int": GraphQLInputObjectField(GraphQLInt)}) Root = GraphQLObjectType( name="Root", fields={ "str": GraphQLField(GraphQLString, args={"argOne": GraphQLArgument(InputType)}) }, ) Schema = GraphQLSchema(Root) output = print_for_test(Schema) assert (output == """ schema { query: Root } input InputType { int: Int } type Root { str(argOne: InputType): String } """)
def get_args(): return { 'to': GraphQLArgument( type=GraphQLNonNull(GraphQLString), description='Value to default to', ), }
def _get_entities_field(self, entity_type: GraphQLUnionType) -> GraphQLField: return GraphQLField( GraphQLNonNull(GraphQLList(entity_type)), args={ "representations": GraphQLArgument( GraphQLNonNull(GraphQLList(GraphQLNonNull(self.Any))) ) }, resolve=self.entities_resolver, )
def test_prints_string_field_with_int_arg(): output = print_single_field_schema( GraphQLField(type=GraphQLString, args={"argOne": GraphQLArgument(GraphQLInt)})) assert (output == """ schema { query: Root } type Root { singleField(argOne: Int): String } """)
def test_prints_string_field_with_int_arg_with_default(): output = print_single_field_schema( GraphQLField( type_=GraphQLString, args={"argOne": GraphQLArgument(GraphQLInt, default_value=2)}, )) assert (output == """ schema { query: Root } type Root { singleField(argOne: Int = 2): String } """)
def test_prints_input_type(): InputType = GraphQLInputObjectType( name='InputType', fields={'int': GraphQLInputObjectField(GraphQLInt)}) Root = GraphQLObjectType( name='Root', fields={ 'str': GraphQLField(GraphQLString, args={'argOne': GraphQLArgument(InputType)}) }) Schema = GraphQLSchema(Root) output = print_for_test(Schema) assert output == '''
def test_prints_string_field_with_non_null_int_arg(): output = print_single_field_schema( GraphQLField( type=GraphQLString, args={'argOne': GraphQLArgument(GraphQLNonNull(GraphQLInt))})) assert output == '''
def test_prints_string_field_with_int_arg_with_default(): output = print_single_field_schema( GraphQLField( type=GraphQLString, args={'argOne': GraphQLArgument(GraphQLInt, default_value=2)})) assert output == '''
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) ) } ) MutationRootType = GraphQLObjectType( name='MutationRoot', fields={ 'writeTest': GraphQLField( type=QueryRootType,
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')), '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)
"context": GraphQLField( GraphQLObjectType( name="context", fields={ "session": GraphQLField(GraphQLString), "request": GraphQLField( GraphQLNonNull(GraphQLString), resolve=lambda obj, info: info.context["request"], ), }, ), resolve=lambda obj, info: info.context, ), "test": GraphQLField( type_=GraphQLString, args={"who": GraphQLArgument(GraphQLString)}, resolve=lambda obj, info, who="World": "Hello %s" % who, ), "characters": GraphQLField( type_=GraphQLString, args={"who": GraphQLArgument(GraphQLString)}, resolve=lambda obj, info, who="World": "Hello %s" % who, ), }, ) MutationRootType = GraphQLObjectType( name="MutationRoot", description="Root mutations", fields={ "writeTest": GraphQLField(type_=QueryRootType, resolve=lambda *_: QueryRootType),
def executeSQL(query, *args, **kwargs): con, conn = connection() con.execute(query, *args, **kwargs) result = con.fetchone() con.close() conn.close() gc.collect() return result QueryRootType = GraphQLObjectType( name='QueryRoot', fields={ 'getUser': GraphQLField(type=GraphQLString, args={'ident': GraphQLArgument(GraphQLInt)}, resolver=lambda obj, info, ident: executeSQL( "SELECT * FROM user WHERE iduser = %s", escape_string(str(ident)))), 'getNoteByParentId': GraphQLField(type=GraphQLString, args={'parent_id': GraphQLArgument(GraphQLInt)}, resolver=lambda obj, info, parent_id: executeSQL( "SELECT title FROM note_view WHERE parent_id = %s", escape_string(str(parent_id)))), 'getNotegroupById': GraphQLField(type=GraphQLString, args={ 'notegroup_id': GraphQLArgument(GraphQLInt), 'access_token': GraphQLArgument(GraphQLString) },
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( type=QueryRootType, resolver=lambda *_: QueryRootType ) } )
fields={ "session": GraphQLField(GraphQLString), "request": GraphQLField( GraphQLNonNull(GraphQLString), resolve=lambda obj, info: info.context["request"], ), }, ), resolve=lambda obj, info: info.context, ), "test": GraphQLField( type_=GraphQLString, args={"who": GraphQLArgument(GraphQLString)}, resolve=lambda obj, info, who=None: "Hello %s" % (who or "World"), ), }, ) MutationRootType = GraphQLObjectType( name="MutationRoot", fields={ "writeTest": GraphQLField(type_=QueryRootType, resolve=lambda *_: QueryRootType) }, ) Schema = GraphQLSchema(QueryRootType, MutationRootType)
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)