question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with Mutation

See original GitHub issue

Hello, 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:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jhggcommented, Nov 25, 2015

Hi @amitsaha - you are running into the no scalar leafs validation error.

This means your query is wrong.

0reactions
syrusakbarycommented, Nov 25, 2015

@amitsaha You can use #graphql #graphene #python 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found