Пример #1
0
    return IntroduceShipMutation(
        shipId=newShip.id,
        factionId=factionId,
    )

shipMutation = mutationWithClientMutationId(
    'IntroduceShip',
    inputFields={
        'shipName': GraphQLField(
            GraphQLNonNull(GraphQLString)
        ),
        'factionId': GraphQLField(
            GraphQLNonNull(GraphQLID)
        )
    },
    outputFields={
        'ship': GraphQLField(
            shipType,
            resolver=lambda payload, *_: getShip(payload.shipId)
        ),
        'faction': GraphQLField(
            factionType,
            resolver=lambda payload, *_: getFaction(payload.factionId)
        )
    },
    mutateAndGetPayload=mutateAndGetPayload
)

# 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:
Пример #2
0
    GraphQLField
)

from graphql_relay.mutation.mutation import (
    mutationWithClientMutationId,
)

class Result(object):
    def __init__(self, result, clientMutationId=None):
        self.clientMutationId = clientMutationId
        self.result = result

simpleMutation = mutationWithClientMutationId(
    'SimpleMutation',
    inputFields= {},
    outputFields= {
        'result': GraphQLField(GraphQLInt)
    },
    mutateAndGetPayload= lambda *_: Result(result=1)
)

mutation = GraphQLObjectType(
    'Mutation',
    fields= {
        'simpleMutation': simpleMutation
    }
)

schema = GraphQLSchema(
    query= mutation,
    mutation= mutation
)