'Apollo Server unable to load interconnected schemas from URLs

I have a working Apollo Server implementation that loads multiple schemas. The schemas refer to each other but are separate files: one is types, other is query. The schemas come from another team and I have no control over them.

When I put both files in a local directory I can load them correctly with a wildcard.

const schema = await loadSchema(
    './schemas/*.graphqls',
    {
        loaders: [ new GraphQLFileLoader() ]
    });

If I try to load from multiple URLs though, Apollo tries to load each independently. If any one refers to any types in another schema, Apollo fails to load that schema. Ex.

const schema = await loadSchema(
    [
        'https://company.com/myapp/schemas/types.graphqls',
        'https://company.com/myapp/schemas/query.graphqls'
    ],
    {
            loaders: [ new UrlLoader() ] 
    });

The types.graphqls schema loads ok but query.graphqls fails to load. They can be basically broken down to:

# types.graphqls
type Store {
    id: ID!
    name: String!
}


# query.graphqls
type Query { 
    getStore(id: ID!): Store
}

But when I load them from the URLs I get this error:

Unknown type "Store".
    at assertValidSDL (/projects/mock-apollo-server/node_modules/graphql/validation/validate.js:135:11)
    at Object.buildASTSchema (/projects/mock-apollo-server/node_modules/graphql/utilities/buildASTSchema.js:44:34)
    at UrlLoader.load (/projects/mock-apollo-server/node_modules/@graphql-tools/url-loader/index.js:681:35)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /projects/mock-apollo-server/node_modules/@graphql-tools/load/index.js:75:39
    at async Promise.all (index 2)
    at async loadFile (/projects/mock-apollo-server/node_modules/@graphql-tools/load/index.js:73:9)
    at async /projects/mock-apollo-server/node_modules/@graphql-tools/load/index.js:386:25

Is there a way to get Apollo to load them or do I need to download each individually and pass to Apollo as a concatenated string?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source