return IntroduceShipMutation( shipId=newShip.id, factionId=factionId, ) shipMutation = mutation_with_client_mutation_id( 'IntroduceShip', input_fields={ 'shipName': GraphQLInputObjectField( GraphQLNonNull(GraphQLString) ), 'factionId': GraphQLInputObjectField( GraphQLNonNull(GraphQLID) ) }, output_fields={ 'ship': GraphQLField( shipType, resolver=lambda payload, *_: getShip(payload.shipId) ), 'faction': GraphQLField( factionType, resolver=lambda payload, *_: getFaction(payload.factionId) ) }, mutate_and_get_payload=mutate_and_get_payload ) # This is the type that will be the root of our mutations, and the # entry point into performing writes in our schema. # # This implements the following type system shorthand:
factionId = data.get('factionId') newShip = createShip(shipName, factionId) return IntroduceShipMutation( shipId=newShip.id, factionId=factionId, ) shipMutation = mutation_with_client_mutation_id( 'IntroduceShip', input_fields={ 'shipName': GraphQLInputObjectField(GraphQLNonNull(GraphQLString)), 'factionId': GraphQLInputObjectField(GraphQLNonNull(GraphQLID)) }, output_fields={ 'ship': GraphQLField(shipType, resolver=lambda payload, *_: getShip(payload.shipId)), 'faction': GraphQLField( factionType, resolver=lambda payload, *_: getFaction(payload.factionId)) }, mutate_and_get_payload=mutate_and_get_payload) # This is the type that will be the root of our mutations, and the # entry point into performing writes in our schema. # # This implements the following type system shorthand: # type Mutation { # introduceShip(input IntroduceShipInput!): IntroduceShipPayload # }
# noinspection PyPep8Naming def mutate_and_get_payload(_info, shipName, factionId, **_input): new_ship = create_ship(shipName, factionId) return IntroduceShipMutation(shipId=new_ship.id, factionId=factionId) shipMutation = mutation_with_client_mutation_id( "IntroduceShip", input_fields={ "shipName": GraphQLInputField(GraphQLNonNull(GraphQLString)), "factionId": GraphQLInputField(GraphQLNonNull(GraphQLID)), }, output_fields={ "ship": GraphQLField( shipType, resolve=lambda payload, _info: get_ship(payload.shipId) ), "faction": GraphQLField( factionType, resolve=lambda payload, _info: get_faction(payload.factionId) ), }, mutate_and_get_payload=mutate_and_get_payload, ) # This is the type that will be the root of our mutations, and the # entry point into performing writes in our schema. # # This implements the following type system shorthand: # type Mutation { # introduceShip(input IntroduceShipInput!): IntroduceShipPayload # }
from graphql.type import (GraphQLSchema, GraphQLObjectType, GraphQLInt, GraphQLField, GraphQLInputObjectField) from graphql_relay.mutation.mutation import ( mutation_with_client_mutation_id, ) class Result(object): def __init__(self, result, clientMutationId=None): self.clientMutationId = clientMutationId self.result = result simpleMutation = mutation_with_client_mutation_id( 'SimpleMutation', input_fields={}, output_fields={'result': GraphQLField(GraphQLInt)}, mutate_and_get_payload=lambda *_: Result(result=1)) simpleMutationWithThunkFields = mutation_with_client_mutation_id( 'SimpleMutationWithThunkFields', input_fields=lambda: {'inputData': GraphQLInputObjectField(GraphQLInt)}, output_fields=lambda: {'result': GraphQLField(GraphQLInt)}, mutate_and_get_payload=lambda args, *_: Result(result=args.get('inputData') )) simplePromiseMutation = mutation_with_client_mutation_id( 'SimplePromiseMutation', input_fields={}, output_fields={'result': GraphQLField(GraphQLInt)}, mutate_and_get_payload=lambda *_: Promise.resolve(Result(result=1)))
from graphql_relay.mutation.mutation import ( mutation_with_client_mutation_id, ) class Result(object): def __init__(self, result, clientMutationId=None): self.clientMutationId = clientMutationId self.result = result simpleMutation = mutation_with_client_mutation_id( 'SimpleMutation', input_fields={}, output_fields={ 'result': GraphQLField(GraphQLInt) }, mutate_and_get_payload=lambda *_: Result(result=1) ) simpleMutationWithThunkFields = mutation_with_client_mutation_id( 'SimpleMutationWithThunkFields', input_fields=lambda: { 'inputData': GraphQLInputObjectField(GraphQLInt) }, output_fields=lambda: { 'result': GraphQLField(GraphQLInt) }, mutate_and_get_payload=lambda args, *_: Result(result=args.get('inputData')) )