Skip to content

Empty String as As input variable #18

Closed
@eMerzh

Description

@eMerzh

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 👍

Activity

eMerzh

eMerzh commented on Dec 11, 2018

@eMerzh
Author

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

Cito commented on Dec 13, 2018

@Cito
Member

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

self-assigned this
on Dec 13, 2018
added
bugSomething isn't working
on Dec 13, 2018
added a commit that references this issue on Dec 13, 2018
Cito

Cito commented on Dec 13, 2018

@Cito
Member

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

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Empty String as As input variable · Issue #18 · graphql-python/graphql-core