我很难弄清楚我的设置有什么问题。我一直在看文档,但在apollo和graphql-tools之间,API经常变化。
当我运行此脚本时,控制台显示“错误:必须提供查询根类型。”
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}`);
});以下是我的依赖项:
{
"@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"
}有人知道这会有什么问题吗?
发布于 2021-10-14 16:36:46
好吧,我发现我的url端点是不正确的。我会把这个问题留下来,以防对某些人有用。
https://stackoverflow.com/questions/69573605
复制相似问题