Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about mutation document #1162

Closed
sydoluciani opened this issue Mar 24, 2020 · 2 comments · Fixed by #1213
Closed

Question about mutation document #1162

sydoluciani opened this issue Mar 24, 2020 · 2 comments · Fixed by #1213

Comments

@sydoluciani
Copy link

sydoluciani commented Mar 24, 2020

Document says:

We must define a query for our schema

https://docs.graphene-python.org/en/latest/types/mutations/#quick-example

But removing Query class, not causing problem and following code runs with no error:

import graphene

class Person(graphene.ObjectType):
    user_name = graphene.String()
    age = graphene.Int()

class CreatePerson(graphene.Mutation):
    class Arguments:
        name = graphene.String()

    ok = graphene.Boolean()
    person = graphene.Field(lambda: Person)

    def mutate(self, info, name):
        person = Person(user_name=name)
        ok = True
        return CreatePerson(person=person, ok=ok)

class MyMutations(graphene.ObjectType):
    make_person = CreatePerson.Field()

schema = graphene.Schema(mutation=MyMutations)

query_str = """
    mutation myFirstMutation {
        makePerson(name: "Peter") {
            person {
                __typename
                userName
            }
            ok
        }
    }
"""

result = schema.execute(query_str)
print(result.data)

Is it a document error ?

@sydoluciani sydoluciani changed the title Questions about mutation Question about mutation document Mar 24, 2020
@stale
Copy link

stale bot commented Jun 22, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added wontfix and removed wontfix labels Jun 22, 2020
@jkimbo
Copy link
Member

jkimbo commented Jun 24, 2020

@sydoluciani you're right it does look like query is optional. I'll update the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants