Remote schema stitching with latest versions of Apollo and GraphQL tools

515 Views Asked by At

i'm having a hard time figuring out the problem with my setup. I have been looking at the documentations but between apollo and graphql-tools the APIs changed frequently.

When i run this script, the console says "Error: Query root type must be provided."

import { ApolloServer } from "apollo-server";
import { loadSchema } from "@graphql-tools/load";
import { UrlLoader } from "@graphql-tools/url-loader";
import { stitchSchemas } from "@graphql-tools/stitch";
import fetch from "node-fetch";
import dotenv from "dotenv";

dotenv.config({ path: "../.env" });

async function startServer() {
  const shopifySchema = await loadSchema(process.env.SHOPIFY_STOREFRONT_URL, {
    loaders: [new UrlLoader()],
    headers: {
      "X-Shopify-Storefront-Access-Token":
        process.env.SHOPIFY_STOREFRONT_API_TOKEN,
    },
    fetch,
  });

  const contentfulSchema = await loadSchema(process.env.CONTENTFUL_API_URL, {
    loaders: [new UrlLoader()],
    headers: {
      Authorization: `Bearer ${process.env.CONTENTFUL_API_TOKEN}`,
    },
    fetch,
  });

  const gatewaySchema = stitchSchemas({
    subschemas: [{ schema: shopifySchema }, { schema: contentfulSchema }],
  });

  const server = new ApolloServer({ schema: gatewaySchema });

  return await server.listen();
}

startServer().then(({ url }) => {
  console.log(` Server ready at ${url}`);
});

These are my dependencies:

{
    "@graphql-tools/load": "^7.3.2",
    "@graphql-tools/schema": "^8.2.0",
    "@graphql-tools/stitch": "^8.3.1",
    "@graphql-tools/url-loader": "^7.2.0",
    "apollo-server": "^3.4.0",
    "dotenv": "^10.0.0",
    "graphql": "^15.6.1",
    "node-fetch": "^3.0.0"
}

Anyone knows what could be wrong with this?

1

There are 1 best solutions below

1
Lorenzo Rivosecchi On

Ok, i have found out that my url endpoints were just incorrect. I'll leave the question open in case might be useful to someone.