我正在遵循有关graphql的教程,其中我正在设置一个简单的graphql服务器。
index.js
SELECT customer.customer, request.field1, request.field2, contact.contact
FROM request
JOIN customer ON request.customer_id = customer.id
JOIN contact ON request.contact_id = contact.id
如您所见,创建GraphQLServer时,我正在引用我的架构文件。但是,当我运行服务器时,出现以下错误:
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`));
我的文件结构:
有人可以发现错误吗?
答案 0 :(得分:1)
您给了路径./schema.graphql
,使路径node
在运行文件的目录中寻找文件,而不是在正确的位置'src/schema.graphql'
。
因此您需要将路径更改为:
//...
typeDefs: 'src/schema.graphql',
//...