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

Using None produces empty object for input types #200

Closed
madiganz opened this issue Apr 14, 2022 · 3 comments · Fixed by #202
Closed

Using None produces empty object for input types #200

madiganz opened this issue Apr 14, 2022 · 3 comments · Fixed by #202
Assignees
Labels
bug Something isn't working

Comments

@madiganz
Copy link

Description:

For input types that have a field that is another input type, when setting the field to None, it produces an empty object. This causes the GraphQL to fail when it needs to be an object with required properties, or null.

Reproducible example:

import sgqlc.types

test_schema = sgqlc.types.Schema()


class TestInput(sgqlc.types.Input):
    __schema__ = test_schema
    __field_names__ = ("field1",)

    field1 = sgqlc.types.Field("FooInput", graphql_name="field1")


class FooInput(sgqlc.types.Input):
    __schema__ = test_schema
    __field_names__ = ("name",)

    name = sgqlc.types.Field(
        sgqlc.types.non_null(sgqlc.types.String), graphql_name="name"
    )


input = TestInput(field1=None)

print(TestInput.__to_graphql_input__(input))

Output:
{field1: {}}

@barbieri barbieri self-assigned this Apr 18, 2022
@barbieri barbieri added the bug Something isn't working label Apr 18, 2022
@barbieri
Copy link
Member

@madiganz took me bit more than anticipated since the input handling was also broken in some other cases, such as passing [None] in a list of non-nullables wasn't raising an exception.

I hope I did cover all the cases in the doctests, also made the code more uniform to avoid inconsistencies.

Let me know if #202 works for you, then I can merge that PR. The GitHub actions confirmed it works in all supported Python versions.

@madiganz
Copy link
Author

@barbieri no problem and thanks for getting this done so quickly. Your PR looks good to me

@barbieri
Copy link
Member

https://pypi.org/project/sgqlc/16.0/ thanks!

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

Successfully merging a pull request may close this issue.

2 participants