Hi. Having a specific issue inserting data where one of the fields is jsonb (or json). I keep getting the error:
{'errors': [{'extensions': {'path': '$.query', 'code': 'validation-failed'}, 'message': 'not a valid graphql query'}]}
where the generated sgqlc mutation looks like:
op = Operation(mutation_root)
op.insert_task_one(
object=dict(
created_by=10,
project_id=1,
method_kwargs={"some": "data"},
)
).id()
op
>>
mutation {
insert_task_one(object: {created_by: 10, method_kwargs: {"some": "data"}, project_id: 1}) {
id
}
}
At first glance the error seems to come from the auto-generated jsonb from the schema-derived sgqlc types.
class jsonb(sgqlc.types.Scalar):
__schema__ = schema
Building the mutation, when the jsonb field is encountered, it is dumped with json.dumps, which , of course, retains quoted dictionary keys as above. When I copy the failing query into iQL and fix the json keys to omit quotes the mutation works, e.g., changing to this is working:
mutation {
insert_task_one(object: {created_by: 10, method_kwargs: {some: "data"}, project_id: 1}) {
id
}
}
This could be implemented by adding the following lines to the end of types.Scalar.__to_graphql_input__() - no idea how robust/performant this would be..
if isinstance(value, dict):
import re
out = re.sub(r'"(.*?)"(?=:)', r'\1', out)
return out
Dropping to the variable paradigm also works, though there is another quirk there on the renaming of the variable name in the mutation - if I wanted to use my schema's naming method_kwargs is automatically changed to methodKwargs in sqglc's variable setup, but the same processing is not applied to the dictionary given to the endpoint.
I guess the question is should I expect the direct usage of jsonb in my insert_task_one mutation to work? Could it work? Would this be reasonable to add?
Otherwise, thanks for the terrific project! Much appreciated
Hi. Having a specific issue inserting data where one of the fields is jsonb (or json). I keep getting the error:
where the generated sgqlc mutation looks like:
At first glance the error seems to come from the auto-generated
jsonbfrom the schema-derived sgqlc types.Building the mutation, when the jsonb field is encountered, it is dumped with
json.dumps, which , of course, retains quoted dictionary keys as above. When I copy the failing query intoiQLand fix the json keys to omit quotes the mutation works, e.g., changing to this is working:This could be implemented by adding the following lines to the end of
types.Scalar.__to_graphql_input__()- no idea how robust/performant this would be..Dropping to the variable paradigm also works, though there is another quirk there on the renaming of the variable name in the mutation - if I wanted to use my schema's naming
method_kwargsis automatically changed tomethodKwargsin sqglc's variable setup, but the same processing is not applied to the dictionary given to the endpoint.I guess the question is should I expect the direct usage of jsonb in my
insert_task_onemutation to work? Could it work? Would this be reasonable to add?Otherwise, thanks for the terrific project! Much appreciated