REST Connectors to call other GraphQL APIs?

Is it possible to use REST connectors to make calls to other GraphQL APIs?

I was attempting experimenting with this, and conceptually it seems like it should work, but I’m repeatedly running into Invalid body errors when trying to structure the request using http.body in my @connect setup.

Example:

type MyType {
  id: ID!
  name: String
}

type Query {
  myType(id: ID!): MyType
    @connect(
      source: "other-graphql-service"
      http: {
        POST: "/graphql"
        body: """
        query: myQuery(id: $args.id) { id }
        """
      }
      selection: """
        ... omitted
      """
    )
}

Solved!

The answer is to use literals (docs):

type MyType {
  id: ID!
  name: String
}

type Query {
  myType(id: ID!): MyType
    @connect(
      source: "other-graphql-service"
      http: {
        POST: "/graphql"
        body: """
        $({
            query: "query ($id: ID!) {
                myField(id: $id) {
                    id
                    name
                }
            }",
            variables: {
              id: $args.id
            }
        })
        """
      }
      selection: """
        ... omitted
      """
    )
}
2 Likes

Interesting, glad you could get this working. What is the use case for using the Router to make the HTTP request and selection mapping rather than instead composing the subgraph in like a regular GraphQL server. Is it mostly for type renaming?

This particular subgraph was the result of schema generated from protobuf annotations and the output wasn’t meeting the subgraph federation spec yet.

This approach allowed us to validate some questions earlier in our development cycle. The eventual goal would be federation.