schema.graphql文件无法找到(节点graphql瑜伽)
我下面该怎么graphql教程我在哪里设置简单graphql服务器。
index.js
const { GraphQLServer } = require('graphql-yoga');
// 1
let links = [{
id: 'link-0',
url: 'www.howtographql',
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);
^
我的文件结构:
任何人都可以发现这个错误吗?
回答如下:你给的路径./schema.graphql
这使得node
查找文件在你运行它,而不是正确的位置,这是'src/schema.graphql'
的目录。
所以,你需要改变的路径:
//...
typeDefs: 'src/schema.graphql',
//...
schema.graphql文件无法找到(节点graphql瑜伽)
我下面该怎么graphql教程我在哪里设置简单graphql服务器。
index.js
const { GraphQLServer } = require('graphql-yoga');
// 1
let links = [{
id: 'link-0',
url: 'www.howtographql',
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);
^
我的文件结构:
任何人都可以发现这个错误吗?
回答如下:你给的路径./schema.graphql
这使得node
查找文件在你运行它,而不是正确的位置,这是'src/schema.graphql'
的目录。
所以,你需要改变的路径:
//...
typeDefs: 'src/schema.graphql',
//...