Skip to content

How to make a required argument? #1173

Answered by maarcingebala
jmn asked this question in Q&A
Discussion options

You must be logged in to vote

@jmn You should use required=True e.g.:

class Query(graphene.ObjectType):
    product = graphene.Field(
        Product, id=graphene.Argument(graphene.ID, required=True),
        description='Lookup a product by ID.')

Now when I query for the product field in the API I need to pass the id argument, as it is required to actually determine which object I should return in my resolver.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zbyte64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #557 on April 14, 2021 20:09.