Repository navigation
|
Don't know if this is expected or not, but when I have an input type as a field on another input type, I cannot set it after initialization class TestInput(sgqlc.types.Input):
__schema__ = test_schema
__field_names__ = ("field1", "field2")
field1 = sgqlc.types.Field("FooInput", graphql_name="field1")
field2 = sgqlc.types.Field(sgqlc.types.list_of("BarInput"), graphql_name="field2")
class FooInput(sgqlc.types.Input):
__schema__ = test_schema
__field_names__ = ("name")
name = sgqlc.types.Field(String, graphql_name="name")
class BarInput(sgqlc.types.Input):
__schema__ = test_schema
__field_names__ = ("name")
name = sgqlc.types.Field(String, graphql_name="name")# This works as expected
test = TestInput(
field1=schema.FooInput(name: "test1"),
field2=[schema.BarInput(name: "test2")]
)
test.field1 = schema.FooInput(name: "updated") # This does nothing if field1 was not set above
test.field2.append(schemaBarInput(name: "added")) # This does nothing |
Answered by
barbieri
Apr 13, 2022
Replies: 1 comment 6 replies
|
In your examples, please note that The input types are meant to be used as a single, immutable construction as they will get the fields and convert to the GraphQL format, it's a difficult task to wrap every mutable type, so it's not done. In your second example It's possible to be added, but an effort I can't do right now (patches are welcome 😀) |
6 replies
Answer selected by
madiganz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your examples, please note that
("name")is the same as"name"(a string, not a tuple). You should use a tuple, then you need a trailing,as in("name",).The input types are meant to be used as a single, immutable construction as they will get the fields and convert to the GraphQL format, it's a difficult task to wrap every mutable type, so it's not done. In your second example
test.field2is a simplelisttype, and mutating it won't update the GraphQL-converted data structure (it's only done in the constructor).It's possible to be added, but an effort I can't do right now (patches are welcome 😀)