I also tried escaping the json to string but that ...
# prisma-whats-new
m
I also tried escaping the json to string but that also failed
"deviceTokens": "{\"type\":\"fcm\",\"token\":\"bar\"}"
d
This works for me:
"json": "{\"property\":\"json\"}"
As does your escaped version. What error do you get when using that?
m
with the escaped version I get
Syntax error while parsing GraphQL query. Invalid input \"\"{\"type\"\", expected Value or Argument
btw I’m passing the info into a schema extension function - does getting it from event.data cause some additional parsing that I need to account for?
e.g. event.data.deviceTokens
d
It looks like it does work different with schema extension functions
This works for me in that case:
Copy code
{
  "json": {
    "test": "value"
  }
}
(The query variables section of the playground shows a tooltip for an error but the mutation actually executes the schema extension fine)
This is definitely a bug though - we should expect to format JSON in the same way whether it is going to a built in query/mutation or to a schema extension
Actually, on testing again, your original JSON works for me for both normal mutations and schema extensions, so I'm not sure why you the error you did with it
Here's the variables I am using in the playground:
Copy code
{
  "json": {
    "type": "fcm",
    "token": "bar"
  }
}
This works for both a simple mutation and a schema extension function
Schema extension:
type TestJsonPayload{ json: Json! } extend type Mutation { TestJson(json:Json!): TestJsonPayload }
n
@dankent @monkeybonkey this looks like a bug in schema extensions, could you please provide a reproducible bug report here: https://github.com/graphcool/api-bugs/issues/?
ahh just saw this:
This works for both a simple mutation and a schema extension function
d
Yes, something else must have been going on for @monkeybonkey because it is working okay for me in both use cases
There is one bug that I do see - when I use the unescaped json in the variables (which works) , there is an error tooltip in the variables panel with "Expected value of type json"
If I put the json value in a string and escape it, the error tooltip disappears so the variables are apparently correct but then the mutation won't work
That bug has already been reported: https://github.com/graphcool/console/issues/874
m
ok let me strip down my example to something that might be easy to reproduce on your end
ah I see, I’m using the parameter in the function in a mutation and it’s failing at
deviceTokens:${event.data.deviceTokens}
since it interprets it as object object
I tried JSON.stringify but it didn’t like it either , do I need to JSON.parse it or is there a toJson function of some sort that I should be using?
here’s a condensed example
Copy code
const fromEvent = require('graphcool-lib').fromEvent
const api = graphcool.api('simple/v1')

return api.request(`
      mutation {
        createFoo(
          someJson: ${event.data.someJson}
        ){
          id
          someJson
        }
      }`)
ok I figured it out - rather than putting in the query string itself, I just declared a json variable and passed it in to the mutation that way… thanks - I got it sorted it out now