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

Support nullable types in graphene #1356

Closed
wyajunjun opened this issue Aug 10, 2021 · 6 comments
Closed

Support nullable types in graphene #1356

wyajunjun opened this issue Aug 10, 2021 · 6 comments

Comments

@wyajunjun
Copy link

Is your feature request related to a problem? Please describe.
Do we have null type in graphene? The example, the default value of mode is null is not pass null value,

mutation{ insertModel(input:{ modelName: "model1" })
but some cases we need to pass null, the return error is "Syntax Error GraphQL (4:63) Unexpected Name "null"
mutation{ insertModel(input:{ modelName: "model1" mode: null })

Describe the solution you'd like
GraphQL supports null values, can graphene also support that? graphql/graphql-spec#83

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@wyajunjun
Copy link
Author

@jkimbo @Speedy1991 Can you help answer the questions?

@jkimbo
Copy link
Member

jkimbo commented Aug 11, 2021

@wyajunjun what version of graphene are you using?

@Speedy1991
Copy link

As far I know - I don't use graphene anymore - you can just say required=False and in your resolver you do something like this: input.get('mode', None)

@wodCZ
Copy link

wodCZ commented Aug 11, 2021

You have to pass the null as a variable, not inlined in the GraphQL query.

CleanShot 2021-08-11 at 15 47 15

vs

CleanShot 2021-08-11 at 15 48 23

It's a best practice to pass all the variables as graphql variables, and that's how client side is usually implemented. But when using GraphiQL it tends to inline the variables in the query, which is not supported (but probably is valid from the specs point of view).

@jkimbo
Copy link
Member

jkimbo commented Aug 14, 2021

@wodCZ you're correct that in Graphene v2 that is the way to get it to work. However in Graphene v3, because it's using graphql-core v3, you can use null in the query directly: https://replit.com/@jkimbo/Graphene-v3#main.py

@alex-grover
Copy link

it is possible that the issue is the missing comma in the input? {modelName: "model1" mode: null}

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

No branches or pull requests

6 participants