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

Presenting Types as dictionaries does not include aliased fields #165

Open
simonrw opened this issue Aug 29, 2021 · 1 comment
Open

Presenting Types as dictionaries does not include aliased fields #165

simonrw opened this issue Aug 29, 2021 · 1 comment

Comments

@simonrw
Copy link

simonrw commented Aug 29, 2021

With the operation

op = Operation(Query, name="Foo")
op.foo(__alias__="bar").value
op.baz()
print(op)
# query Foo {
#   bar: {
#     value
#   }
#   baz
# }

and basic schema:

class Foo(Type):
    value = Field(str, graphql_name="value")

class Query(Type):
    foo = Field(Foo, graphql_name="foo")
    baz = Field(str, graphql_name="baz")

when I perform a query against this, which returns

{
  "data": {
    "baz": "value baz",
    "bar": {
        "value": "value test"
    }
  }
}

and try to convert the resulting type to dictionary:

print(op + endpoint(op))
# Query(bar=Foo(value=value test), baz=value baz)

print((op + endpoint(op)).__to_json_value__())
# {"baz": "value baz"}

the bar field is missing.

I don't know if there's a more suitable way of converting the resulting type to a dict. There is the __json_data__ field, which contains the response from the server, which does contain the baz field - is there a preferred way of doing this operation?

@simonrw simonrw changed the title Presenting Types as dictionaries does not include aliased fields. Presenting Types as dictionaries does not include aliased fields Aug 29, 2021
@grazzolini
Copy link

I have been hitting the same issue. Also it is worth to mention that json_data won't work with nested aliased fields. So, it returns the aliased fields for things only at the same level you're calling from.

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

No branches or pull requests

2 participants