Skip to content

Instantly share code, notes, and snippets.

@ssomnoremac
Created March 17, 2017 19:23
Show Gist options
  • Save ssomnoremac/2a679203d0f2d9a93d434464aec6fdee to your computer and use it in GitHub Desktop.
Save ssomnoremac/2a679203d0f2d9a93d434464aec6fdee to your computer and use it in GitHub Desktop.
mutation example graphene sqlAlchemy
...
class UpdatePersonName(graphene.Mutation):
class Input:
uuid = graphene.Int(required=True)
name = graphene.String(required=True)
person = graphene.Field(Person)
@classmethod
def mutate(cls, _, args, context, info):
uuid = args.get('uuid')
name = args.get('name')
query = Person.get_query(context).filter_by(uuid=uuid)
update = person.update({"name":name})
return UpdatePersonName(person=query.first())
class Query(graphene.ObjectType):
node = graphene.relay.Node.Field()
person = graphene.Field(Person, uuid = graphene.Int())
def resolve_person(self, args, context, info):
query = Person.get_query(context)
uuid = args.get('uuid')
return query.get(uuid)
class Mutation(graphene.ObjectType):
update_person_name = UpdatePersonName.Field()
schema = graphene.Schema(query=Query, mutation=Mutation, types=[Person])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment