Example for InputFields and InputObjectTypes #398

Closed
marcovc opened this Issue Jan 2, 2017 · 3 comments

Projects

None yet

3 participants

@marcovc
marcovc commented Jan 2, 2017

The example in the docs here doesn't work.

I got
ValueError: Expected person_data to be Argument, but received InputField. Try using Argument(PersonInput).
and have no idea what it means.

@angieellis

Can you please paste your code for this?

@marcovc
marcovc commented Jan 4, 2017

Hi,
The code is the one from the documentation linked above.
Thanks
Marco

@m-charlton

The following code, from the given link, works fine (on my setup at least):

import graphene

class PersonInput(graphene.InputObjectType):
    name = graphene.String()
    age = graphene.Int()

class CreatePerson(graphene.Mutation):
    class Input:
        person_data = graphene.InputField(PersonInput)

    person = graphene.Field(lambda: Person)

    def mutate(self, args, context, info):
        p_data = args.get('person_data')

        name = p_data.get('name')
        age = p_data.get('age')

        person = Person(name=name, age=age)
        return CreatePerson(person=person)

However the next example, on the same page, fails:

1    import graphene
2
3    class LatLngInput(graphene.InputObjectType):
4        lat = graphene.Float()
5        lng = graphene.Float()
6
7    #A location has a latlng associated to it
8    class LocationInput(graphene.InputObjectType):
9        name = graphene.String()
10       latlng = graphene.InputField(LatLngInputType)

with this traceback:

Traceback (most recent call last):
  File "ex1.py", line 8, in <module>
    class LocationInput(graphene.InputObjectType):
  File "ex1.py", line 10, in LocationInput
    latlng = graphene.InputField(LatLngInputType)
NameError: name 'LatLngInputType' is not defined

It looks as if there is a typo on line 10: LatLngInputType should be LatLngInput,
or the class LatLngInputshould be LatLngInputType.

The error is in docs/types/mutations.rst.

I'm willing to make and test the change.

Python 2.7 environment as follows:

graphene==1.1.3
graphql-core==1.0.1
graphql-relay==0.4.5
promise==1.0.1
six==1.10.0
typing==3.5.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment