GaryDevenay
GaryDevenay

Reputation: 2415

Apollo: Extending type from remote schema

I currently have multiple GraphQL services running Apollo and have created a "Gateway" service that uses remote schema stitching in order to give me a single endpoint for access.

Within my Gateway service I am looking to extend the remote types to create references between the stitched schemas.

const linkTypeDefs = `
    extend type User {
        profile: Profile
    }

    extend type Profile {
        user: User
    }`;

const schema = mergeSchemas({
    schemas: [userSchema, profileSchema, linkTypeDefs],
    resolvers: /* Resolvers */
});

However I seem to be getting the following error:

GraphQLError: Cannot extend type "User" because it does not exist in the existing schema.

I have double checked and the type "User" and "Profile" exist and I can query them from the Gateway Graphiql.

Are there any particular steps I need to take in order to extend types merged from a remote schema?

Upvotes: 5

Views: 1299

Answers (1)

GaryDevenay
GaryDevenay

Reputation: 2415

I eventually resolved this by realising that userSchema and profileSchema were both returning a promise.

I awaited these return values and that resolved the issue for me.

Upvotes: 2

Related Questions