Mike Lyons
Mike Lyons

Reputation: 26088

Building GraphQL services in isolation with apollo-federation

I'm currently trying to test 1 service's graphql endpoint that will eventually be apart of an apollo-federation/gateway graphql server. This service will extend a type in an existing service in the existing federated graph.

If I want to test my service in isolation with the apollo-federation & gateway, is there a way to do that while still using @extends and @external in my graphql schema? Currently the gateway throws: UnhandledPromiseRejectionWarning: Error: Unknown type: "SomeTypeInAnotherServer", which makes sense as there's no type to extend, but can I ignore this validation somehow?

Upvotes: 2

Views: 882

Answers (2)

Dan Crews
Dan Crews

Reputation: 3637

Your question looks like you're trying to do development, but the answer you gave looks like you're specifically doing testing. I don't know if that's where you ended up because of tooling, or if that was your actual question, but this is the answer I have for people doing development:

If you're just running one of the services, you can still make queries against it, just do so in the way ApolloGateway would. Say for example, you have a person-service and a place-service, and People can visit many places:

Person Service

type Person @key(fields: "id") {
  id: ID!
  name: String
}

type Query {
  person(id: ID): Person # Assuming this is the only entry-point
}

Place Service

type Place {
  id: ID!
  name: String
}

extend type Person @key(fields: "id") {
  id: ID!
  placesVisited: [Place]
}

Now you can make the following query to the place-service:

query ($_representations: [_Any!]!) {
  _entities(representations:$_representations) {
    ... on Person {
      id
      placesVisited {
        id
        name
      }
    }
  }
}

and here is your input:

{
  "_representations": [{
    "__typename": "Person",
    "id": "some-id-of-some-person"
  }]
}

Upvotes: 0

Mike Lyons
Mike Lyons

Reputation: 26088

as @xadm posted in a comment, you can achieve this with https://github.com/xolvio/federation-testing-tool which solves my problem.

Upvotes: 1

Related Questions