Hey, I have a question for the following use case:...
# apollo-kotlin
s
Hey, I have a question for the following use case: We have a mutation, where one of its parameters is supposed to be an arbitrary Json object that the backend expects as-is. The problem we have now is that when we pass this Json text (as a String type) as a parameter, the raw text is altered by having the quotes escaped. If we pass it as a JSONObject type it itself is automatically wrapped in the query in another object therefore the backend doesn’t like that since it’s not of the format it’s expecting. Is there something simple that we can look into to get this going or does it sound like the solution might be a bit more involved for this use case?
m
Looks like you need a custom scalar for this
If your parameter is of string type, I'm pretty sure you can't escape the escapes
If you have no control at all over the backend, you can certainly do something by defining your own HttpRequestComposer that transforms the string back to a json object in the post body but that's hackish
s
Okay, String is out of the question without that hack, that’s fine let’s explore the other option first. By custom scalar I suppose you mean a custom type in our schema, where we then can provide our own implementation in the codebase of how it gets mapped from and to our local Kotlin object from that custom scalar? Probably should look into this to start with I assume. I’ll look into it and probably come back for more questions 😄
👌 1
👍 1
m
Just double checking, assuming your parameter is a json like this:
Copy code
{
  "key": "value"
}
What you want is the post data to look like this, right?
Copy code
{
  "query": "...",
  "variables": {
    "param": {
      "key": "value"
    }
  }
}
And not
Copy code
{
  "query": "...",
  "variables": {
    "param": "{ \"key\": \"value\" }"
  }
}
Right?
If that's the case, yep, a custom scalar type in your schema is the way to go
🙌 1