-
Notifications
You must be signed in to change notification settings - Fork 159
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
[Issue]: Scalar input fields on GraphQL datasource converted to strings #1314
Comments
Thanks for opening this issue @greemo JSON type fields are always parsed into a string, so 13 would become "13", this is the default behavior of WG. On your server "13" would be decoded (eg JSON.parse("13") again to 13. You can make the types more specific by using replaceCustomScalarTypeFields Does this answer your question? |
Hi @Pagebakers, thanks for the quick response. Why is parsing JSON into strings the default behaviour? This is effectively changing the interface of the backing service, meaning scalars cannot be used by any graphql server behind wundergraph. This severely limits the functionality of graphql. Is there a way to disable this behaviour? |
If your schema is as followed, we have no way of knowing which format you are expecting. With
In your server your custom JSON scalar would then parse the JSON value. Assuming it runs on Node.js: And it should all work as expected. |
Interesting. I'm having the same issue. When I define it as a JSON array (i.e. [JSON]), then the entire object is stringified: Is this expected behavior too? |
@Pagebakers thanks again for the time spent responding. I understand Wundergraph at the moment forwards a JSON string. I understand how to unpack JSON strings, however I'm expecting a raw JSON value as specified by the GraphQL spec whenever scalars are used. The GraphQL spec allows raw JSON values and by doing stringification, you make Wundergraph incompatible with all the GraphQL APIs that rely on receiving a raw JSON value.
You know the format is JSON. That's all you need. The reason Scalars exist is so formatted JSON can be passed around without intermediates needing to know the format. It is great that users can inform Wundergraph of the structure if the schema of the scalar is known in advance, but often the schema is not known in advance. That's why JSON exists. In this case, Wundergraph should not need to know what format is expected, just pass the JSON directly through. If a field is a scalar, and not defined in the replaceCustomScalarTypeFields entry, just pass the value through. |
I'm not sure what you mean with JSON string and raw JSON value, those seem to be the same things right? WunderGraph passing the JSON scalar value back to the GraphQL API as a JSON string (this is RAW JSON) which seems correct to me? Coming back to the number example. |
Hi @Pagebakers, By JSON String, I mean something surrounded by Maybe an example is helpful:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi @Pagebakers, did my last comment help with understanding the problem? |
Hi @Pagebakers, @StarpTech hope you guys had a great vacation over new year. Any chance of looking over this issue? If there's any more info I can help with, please let me know. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey, this is still a valid issue. Please don't close |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
Hi Guys,
There still seems to be an issue with Scalar support. Specifically with passing scalars through to GraphQL backends.
When a GraphQL backend has an schema (schema.graphql) such as:
And I add it to Wundergraph as a GraphQL api using the following in wundergraph.config.ts:
And define an operation in Wundergraph as follows:
Then I call it from the JSON-RPC interface, I see the following in the log:
As you can see, I pass
value
as an Int to the JSON-RPC interface, but when it is passed to my backend from Wundergraph, it is converted to a string.This should not be happening. Wundergraph should not be converting JSON inputs to strings to pass to the backends.
The desired outcome is the input entered at the Wundergraph JSON-RPC interface is passed as-is to the GraphQL backend.
Please also test with the GET requests - First with a URL decode on the parameters.
Reproduction
Please see above.
Using
"@wundergraph/sdk": "^0.179.1"
andnode v18.12.1 (npm v9.6.2)
The text was updated successfully, but these errors were encountered: