Help with Mutation
See original GitHub issueHello, I am trying to experiment with a simple mutation, here is my schema:
import graphene
class Person(graphene.ObjectType):
name = graphene.String()
age = graphene.Float()
id = graphene.Int()
# Database of Person(s)
p1 = Person()
p2 = Person()
p1.id = 1
p1.age = 34
p1.name = 'Jack'
p2.id = 2
p2.age = 31
p2.name = 'Adam'
persons = [p1, p2]
class Query(graphene.ObjectType):
# Create a field on which we can query and the attributes
# we allow to query on
person = graphene.Field(Person, id=graphene.Int())
def resolve_person(self, args, info):
for p in persons:
if p.id == args.get('id'):
return p
class UpdatePerson(graphene.Mutation):
# Result field
# XXX: This doesn't work
# person = graphene.Field(Person)
# This does work
person = graphene.String()
# The input fields
class Input:
name = graphene.String()
id = graphene.Int()
@classmethod
def mutate(cls, instance, args, info):
name = args.get('name')
for p in persons:
if p.id == args.get('id'):
p.name = name
return UpdatePerson(person=p.name)
class UpdatePersonMutation(graphene.ObjectType):
updatePerson = graphene.Field(UpdatePerson)
schema = graphene.Schema(query=Query, mutation=UpdatePersonMutation)
In UpdatePerson
above, when I have the person field as person = graphene.Field(Person)
, ( and correspondingly return UpdatePerson(person=p)
), upon sending a mutation query, I get: [GraphQLError('Field "person" of type "Person" must have a sub selection.',)]
.
Any suggestions as to what I am doing wrong?
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How viruses mutate and what can be done about it - JHU Hub
Well, first, viruses have a mutation rate that's much, much higher than humans or other animals, and they replicate at a rate that's...
Read more >How do virus mutations happen, and what do they mean?
A mutation can help the virus gain traits that better help it reproduce quickly or adhere better to the surface of human cells....
Read more >Challenge 4: How do mutations cause viral evolution?
Mutations involve changes to the sequence of an organism's genetic code. As you have learned, viruses typically mutate more rapidly than human cells...
Read more >Genetic Mutations: Overview & Types - Cleveland Clinic
Genetic mutations could lead to genetic conditions like cancer, or they could help humans better adapt to their environment over time.
Read more >Genetic Mutation | Learn Science at Scitable - Nature
Genetic mutation is the basis of species diversity among beetles, ... developed to help estimate rates of different types of mutations in various...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @amitsaha - you are running into the no scalar leafs validation error.
This means your query is wrong.
@amitsaha You can use #graphql #graphene #python 😃