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

Empty String as As input variable #18

Closed
eMerzh opened this issue Dec 11, 2018 · 3 comments
Closed

Empty String as As input variable #18

eMerzh opened this issue Dec 11, 2018 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@eMerzh
Copy link

eMerzh commented Dec 11, 2018

Hello,
not sure if it's an issue or a question, but here it is,
i try to make a field with a non nullable String as an input field. And graphql-core-next is converting it to "None" which is not what i expected.
It seems to me, reading the spec, that it's allowed to pass "" as string argument and should be considered not null ... did i miss something ?

here is a reproducible code to show off the issue :

import asyncio
from graphql import graphql, parse, build_ast_schema


async def resolve_hello(obj, info, query):
    print(query)
    return f'world ==>{query}<=='

schema = build_ast_schema(parse("""
type Query {
    hello(query: String!): String
}
"""))

schema.get_type("Query").fields["hello"].resolve = resolve_hello

async def main():
    query = '{ hello(query: "") }'
    print('Fetching the result...')
    result = await graphql(schema, query)
    print(result)


loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()

thanks for the help 👍

@eMerzh
Copy link
Author

eMerzh commented Dec 11, 2018

interestingly, i've just noticed that it work as expected if i provide the value as variable and not inline
like this

import asyncio
from graphql import graphql, parse, build_ast_schema


async def resolve_hello(obj, info, query):
    print(query)
    return f'world ==>{query}<=='

schema = build_ast_schema(parse("""
type Query {
    hello(query: String!): String
}
"""))

schema.get_type("Query").fields["hello"].resolve = resolve_hello

async def main():
    query = 'query Space($z: String!) { hello(query: $z) }'
    print('Fetching the result...')
    result = await graphql(schema, query, variable_values={"z": ""} )
    print(result)


loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()

which let me thing to a bug 🤔

@Cito
Copy link
Member

Cito commented Dec 13, 2018

Thanks a lot for reporting. I can confirm this is a bug in the lexer.

@Cito Cito self-assigned this Dec 13, 2018
@Cito Cito added the bug Something isn't working label Dec 13, 2018
Cito added a commit that referenced this issue Dec 13, 2018
@Cito
Copy link
Member

Cito commented Dec 13, 2018

The above fix should solve this and will be included in the next release.

@Cito Cito closed this as completed Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants