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

There is no documentation on how to use __json_dump_args__ ? #239

Open
sumeet30 opened this issue Jul 18, 2023 · 4 comments
Open

There is no documentation on how to use __json_dump_args__ ? #239

sumeet30 opened this issue Jul 18, 2023 · 4 comments
Assignees

Comments

@sumeet30
Copy link

I am facing problem with unicode characters (Like Chinese characters). its not getting converted to proper characters. I have found that we can use json_dump_args to pass ensure_ascii=False. How can i use this? any example will be really helpful?

@barbieri
Copy link
Member

Hi @sumeet30, can you clarify with a code example and error message? Are you talking about the codegen, generated code, operation execution? What's the transport/endpoint being used... all of those impact, we may need to check if encoding matches content-type, etc

@barbieri barbieri self-assigned this Jul 18, 2023
@sumeet30
Copy link
Author

Hi @barbieri This issue i am facing is with operation execution. I have generate code using Graphql schema file. Now when i am trying to perform operation execution, then the Chinese characters passed as input getting converted to codes.
Example: The input class object to operation like "Create(name=测试混乱, description=This is test, tags=['test'])" getting converted to below and passed to server.

mutation {
Template {
create(input: {name: "\u6d4b\u8bd5\u6df7\u4e71", description: "This is test",tags: ["test"]}) {
name
description
}
}
}

@sumeet30
Copy link
Author

@barbieri Could you please help?

@barbieri
Copy link
Member

@sumeet30 I'd recommend you to go with variables, it's not that good to pass the explicit values in your query, as the servers can't cache and so on. So please try with something like below, take a look at https://sgqlc.readthedocs.io/en/latest/sgqlc.types.html#sgqlc.types.Variable https://sgqlc.readthedocs.io/en/latest/sgqlc.endpoint.http.html#synchronous-http-endpoint and https://spec.graphql.org/October2021/#sec-Validation.Variables

from sgqlc.types import Variable

my_query = op.create(input=Variable('a'))
endpoint(my_query, variables={'a': {'name': '测试混乱', 'description': 'This is test', 'tags': ['test']}})  

This will send your document with input: $a and the actual value is sent in the JSON body, field variables, as in the HTTP GraphQL convention see https://graphql.org/learn/serving-over-http/#post-request

The __json_dump_args__ you must set on your scalars, so you'd need to change the String scalar, which is not that good.

However, what's the error the server is sending? The GraphQL document allows for unicode escaping, see https://spec.graphql.org/October2021/#StringCharacter

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