gpt4 book ai didi

javascript - 找不到 schema.graphql 文件( Node graphql-yoga)

转载 作者:太空宇宙 更新时间:2023-11-03 22:05:49 25 4
gpt4 key购买 nike

我正在按照 how to graphql 教程设置一个简单的 graphql 服务器。

index.js

const { GraphQLServer } = require('graphql-yoga');

// 1
let links = [{
id: 'link-0',
url: 'www.howtographql.com',
description: 'Fullstack tutorial for GraphQL'
}];

const resolvers = {
Query: {
info: () => `This is the API of a Hackernews Clone`,
// 2
feed: () => links,
},
// 3
Link: {
id: (parent) => parent.id,
description: (parent) => parent.description,
url: (parent) => parent.url,
}
};

// 3
const server = new GraphQLServer({
typeDefs:'./schema.graphql',
resolvers,
});

server.start(() => console.log(`Server is running on http://localhost:4000`));

如您所见,我在创建 GraphQLServer 时引用了我的架构文件。但是,当我运行服务器时,出现以下错误:

/Users/BorisGrunwald/Desktop/programmering/Javascript/GraphQL/hackernews-node/node_modules/graphql-yoga/dist/index.js:418
throw new Error("No schema found for path: " + schemaPath);
^

我的文件结构:

enter image description here

有人能发现错误吗?

最佳答案

您提供了路径./schema.graphql,这使得node在您运行它的目录中查找文件,而不是正确的位置 'src/schema.graphql'

所以你需要将路径更改为:

//...
typeDefs: 'src/schema.graphql',
//...

关于javascript - 找不到 schema.graphql 文件( Node graphql-yoga),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54523945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com