Comments (13)
@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.
If your schema is as followed, we have no way of knowing which format you are expecting.
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.
from wundergraph.
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
https://docs.wundergraph.com/docs/guides/extend-json-fields-with-more-specific-types#step-2-extending-the-graph-ql-schema-with-our-custom-type
Does this answer your question?
from wundergraph.
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?
from wundergraph.
If your schema is as followed, we have no way of knowing which format you are expecting.
With customJSONScalars
the value input now accepts any valid JSON encodable value, that is then encoded into a JSON string. eg JSON.stringify(13) becomes "13".
type Mutation {
setValue (id: Int!, value: JSON!): Boolean
}
In your server your custom JSON scalar would then parse the JSON value.
Assuming it runs on Node.js:
JSON.parse("13") becomes 13.
And it should all work as expected.
from wundergraph.
Interesting. I'm having the same issue. When I define it as a JSON array (i.e. [JSON]), then the entire object is stringified:
["{"key":"realm","value":"something"}","{"key":"$filter","value":"(UniqueName eq 'CR3640')"}"]
Is this expected behavior too?
from wundergraph.
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. 13
is not a valid JSON value but "13"
is.
from wundergraph.
Hi @Pagebakers,
By JSON String, I mean something surrounded by "
characters. By raw JSON values, I mean anything that is valid JSON.
Raw JSON values are obviously strings at the HTTP level as a HTTP string does not require a "
character.
Maybe an example is helpful:
13
is valid json, and is a JSON integer, not a JSON string. https://www.json.org/json-en.html, https://jsonlint.com/
"13"
is also valid JSON, but is a JSON string. It is a stringified JSON integer.
{"foo": 3}
is valid JSON, and is a JSON object
"{\"foo\": 3}"
is valid JSON, it is a JSON string. It is not a JSON object. It is a stringified JSON object.
from wundergraph.
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.
from wundergraph.
Hi @Pagebakers, did my last comment help with understanding the problem?
from wundergraph.
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.
from wundergraph.
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.
from wundergraph.
Hey, this is still a valid issue. Please don't close
from wundergraph.
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.
from wundergraph.
Related Issues (20)
- [Issue]: Live queries are not working when running server in debug mode (SvelteKit) HOT 2
- [Issue]: InputValidationError returns text/plain but should return application/json HOT 4
- [Issue]: Nextjs token based auth is not secure HOT 5
- Support for @tanstack/react-query v5 HOT 2
- Generated graphql Operations ignore the default values set in OAS Schema definition
- [Issue]: TestServer start timeout artificially limited to maximum of 60s HOT 1
- Object literal may only specify known properties, and 'type' does not exist in type 'JSONSchema7' HOT 5
- [Issue]: Nextjs App Router Migration Problem HOT 5
- introspect.graphql does not work for Contetnful GQL Schema HOT 3
- [Issue]: NextJS 14 failing to run useQuery calls that are Live Queries HOT 5
- Remove dependency on terminate package HOT 1
- [Issue]: Unable to get headers in revalidate hook HOT 1
- [Issue]: Crash in Subscriptions after publishing an event to NATS. HOT 6
- [Issue]: wunderctl start from `@wundergraph/sdk:0.177.0` always returning `stack` property for operation errors HOT 1
- [Issue]: Unable to access user object in hooks HOT 2
- [Issue]: Client fails to build when calling a GraphQL operation with an @internal directive from a TS Operation HOT 1
- Support ability to include Tags in the OpenAPI spec generation HOT 1
- Decimal / Numeric Postgres fields return null value in operations
- [Issue]: Wundergraph is unresponsive when run in a Codepsaces environment
- NextJS next-auth test app not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wundergraph.