GraphQL: directive for GraphQL+- custom resolver (e.g Geolocation)

Hey @machship-mm I have found the solution with @vardhanapoorv. We have to forward the headers to make it work. I have tested the query bellow:

type Test @remote {
  data: Q
}
type Q @remote {
  q: [TestR]
}
type TestR @remote {
  test: String
}

type Query {
		getCountry(query: String!): Test
		  @custom(
			http: {
			  url: "http://localhost:8080/query"
			  forwardHeaders:["Content-Type"]
			  method: "POST"
			  body: "{ query: $query }"
			})
	  }

That approach can be unsafe in some levels, so you should combine with @auth directive.

The GraphQL Query

query {
  getCountry(query: "{ q(func: has(test)) { test } }") {
     data {  q { test } }
  }
}

@michaelcompton @pawan @abhimanyusinghgaur

I know that we gonna support Geo queries, but this approach is good for any kind of special query.

Note: Now that we know that this type of query is possible. It would be interesting to be able to do the body in a more dynamic way. The parser prevents us from using static queries. And let only the values ​​to be dynamic.

1 Like