-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JSON object as String in query variables #262
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
Comments
Hey @sudheerj! I'm not really sure what you mean by passing JSON object as String - are you trying to execute a query with above JSON as variables? |
Exactly.I want to pass above JSON object as String query variable.It contains many operators and fields.The above expression is a direct Mongoose schema that works on DB.I don't want to pass it as InputObject. |
Let me try answering in a couple phases:
If what you wanted is to pass an object and convert it into a string later, it'll be difficult to achieve that as
FYI, you may already know this, but I did a quick google search and came up with a couple of example adapter libraries with GraphQL and Mongoose DB (e.g. graffiti-graphql), as well as some posts on what other people did to connect the two. For the last mark, this question is probably more suited for |
I should pass JSON object only because it contains mongoose operators which executed directly.You can observe $gt,$gte,$in,$nin etc so I'am expecting them as String instead on Input object. Do I need to pass filter args for Root query here? Other inputs will be passed to Model object
|
@asiandrummer's suggestion is a good one. You simply provide a string for your variable which happens to appear as JSON: {
"filter": "{ \"region\": \"APAC\", ... }"
} Within your application, you can first call JSON.parse() on the string variable to get your unstructured JSON object within your server. |
@leebyron the suggestion to escape quotes in a string is very cumbersome for large data and not a reasonable solution for this in my opinion. Given there is a JSONString input type, GraphiQL should support transforming the Object variable to JSONString. Defining custom Input Types is also not possible for my situation since this is for a mutation that needs to support multiple types and interfaces are not supported for input types. My work around for now is to do the hacky modification of my fetcher. This still has the problem of GraphiQL highlighting my variables saying, "Expected value of type JSONString". But I guess I can just ignore this since this is only used by our sys admins. For anyone else facing this same situation this is my fetcher:
I used a __stringify wrapper to avoid stringifying unintended objects. |
@nikordaris, JSONString is not part of the standard set of scalars and GraphiQL only supports the standard set, that's a custom scalar type added by your server. If you're sending complex unstructured JSON data as a string - I suggest calling JSON.stringify on the client before sending the query |
I have the same issue. I can submit the JSON just fine, but graphIQL complains that the type is supposed to be Json. |
upgrade flow, fix typings
hello @robross0606 - that is insomnia, i think you need to open a ticket with them! |
Another route to implementing this here and in insomnia would be via this initiative, and thus adopting the graphql spec for custom scalar URLs therein so, custom, non-spec scalars like |
Can you please guide on how to pass below JSON object as String
The text was updated successfully, but these errors were encountered: