Actually, yeah! this is possible. This way we can use it directly with @custom! As, the GraphQL variables will be replaced inside the “variables” in JSON. It’s cool!
We will need to modify the query slightly like:
type Query{
getGeo(name: String!, v1: String!, v2: String!): GeoObject @custom(http:{
url: "https://localhost:8080/query"
method: "POST",
body: "{ query: \"query q($name: string) { q(func: eq(name, $name)) { uid name } }\", variables: {$a: $v1, $b: $v2, $name: $name }}"
})
}
Earlier, I was thinking about only replacing variables directly in “query”, but that wouldn’t have been possible as the “query” value is string which contains the actual query, and we don’t parse variables from inside a string. But with this variable approach, it is possible to directly call dgraph.
Yes, this is what I was saying wouldn’t work as the variable can’t be replaced if it is present inside a string. But, in the other approach, it will work because GraphQL can identify the variables in that case and replace them with their value. Then, dgraph will receive the correct JSON and it will all work!
No middlewares required now!
Thanks @MichelDiz.