找不到schema.graphql文件(节点graphql-yoga)

时间:2019-02-04 20:36:11

标签: javascript node.js graphql

我正在遵循有关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`));

我的文件结构:

enter image description here

有人可以发现错误吗?

1 个答案:

答案 0 :(得分:1)

您给了路径./schema.graphql,使路径node在运行文件的目录中寻找文件,而不是在正确的位置'src/schema.graphql'

因此您需要将路径更改为:

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