def as_graphql(self): if self.name in self.types_dict: return self.types_dict[self.name] typ = GraphQLObjectType(self.name, { 'hasNextPage': GraphQLField( GraphQLNonNull(GraphQLBoolean), ), 'hasPreviousPage': GraphQLField( GraphQLNonNull(GraphQLBoolean), ), }) self.types_dict[self.name] = typ return typ
def test_executor_defer_failure(): class Data(object): def promise(self): return fail(Exception('Something bad happened! Sucks :(')) def notPromise(self): return 'i should work' DataType = GraphQLObjectType( 'DataType', { 'promise': GraphQLField(GraphQLNonNull(GraphQLString)), 'notPromise': GraphQLField(GraphQLString), }) doc = ''' query Example { promise notPromise } ''' schema = GraphQLSchema(query=DataType) executor = Executor() result = executor.execute(schema, doc, Data(), operation_name='Example') assert result.called result = result.result assert result.data is None formatted_errors = list(map(format_error, result.errors)) assert formatted_errors == [{ 'locations': [dict(line=3, column=9)], 'message': "Something bad happened! Sucks :(" }]
def test_synchronous_executor_doesnt_support_defers(): class Data(object): def promise(self): return succeed('i shouldn\'nt work') def notPromise(self): return 'i should work' DataType = GraphQLObjectType( 'DataType', { 'promise': GraphQLField(GraphQLNonNull(GraphQLString)), 'notPromise': GraphQLField(GraphQLString), }) doc = ''' query Example { promise notPromise } ''' schema = GraphQLSchema(query=DataType) executor = Executor([SynchronousExecutionMiddleware()]) result = executor.execute(schema, doc, Data(), operation_name='Example') assert not isinstance(result, Deferred) assert result.data is None formatted_errors = list(map(format_error, result.errors)) assert formatted_errors == [{ 'locations': [dict(line=3, column=9)], 'message': 'You cannot return a Deferred from a resolver ' 'when using SynchronousExecutionMiddleware' }]
def get_edge_type(self): entity_name = super(EntitySetType, self).name name = "%sEdge" % entity_name if name in self.types_dict: return self.types_dict[name] edge_type = GraphQLObjectType(name, { 'node': GraphQLField(self.node_type), 'cursor': GraphQLField(GraphQLNonNull(GraphQLString)) }) self.types_dict[name] = edge_type return edge_type
def build(cls): self = cls() output_fields = self.get_output_fields() output_fields.update( {'clientMutationId': GraphQLField(GraphQLNonNull(GraphQLString))}) output_type = GraphQLObjectType(self.name + 'Payload', fields=output_fields) input_fields = self.get_input_fields() input_fields.update({ 'clientMutationId': GraphQLInputObjectField(GraphQLNonNull(GraphQLString)) }) input_arg = GraphQLArgument( GraphQLNonNull( GraphQLInputObjectType(name=self.name + 'Input', fields=input_fields))) return GraphQLField(output_type, args={ 'input': input_arg, }, resolver=self._resolver)
''', [ fields_conflict('deepField', [ ('x', 'a and b are different fields') ], L(4, 13), L(7, 13), L(5, 17), L(8, 17)) ], sort_list=False) StringBox = GraphQLObjectType('StringBox', {'scalar': GraphQLField(GraphQLString)}) IntBox = GraphQLObjectType('IntBox', {'scalar': GraphQLField(GraphQLInt)}) NonNullStringBox1 = GraphQLObjectType( 'NonNullStringBox1', {'scalar': GraphQLField(GraphQLNonNull(GraphQLString))}) NonNullStringBox2 = GraphQLObjectType( 'NonNullStringBox2', {'scalar': GraphQLField(GraphQLNonNull(GraphQLString))}) BoxUnion = GraphQLUnionType( 'BoxUnion', [StringBox, IntBox, NonNullStringBox1, NonNullStringBox2], resolve_type=lambda *_: StringBox) Connection = GraphQLObjectType( 'Connection', { 'edges': GraphQLField( GraphQLList( GraphQLObjectType(
def global_id_field(): return GraphQLField( GraphQLNonNull(GraphQLID), description='The ID of an object', resolver=lambda obj, *_: id(obj), )