Ecmascript 6 使用es5导出graphql模式

Ecmascript 6 使用es5导出graphql模式,ecmascript-6,graphql,ecmascript-5,apollo,Ecmascript 6,Graphql,Ecmascript 5,Apollo,我正在编写一个使用graphql运行Express服务器的脚本。我正在使用ES5 以下是我的server.js代码(用于运行Express服务器): 下面是我的schema.js的代码 const {makeExecutableSchema, addMockFunctionsToSchema} = require('graphql-tools'); const typeDefs = `type Query { greeting: String } `; const schema = ma

我正在编写一个使用graphql运行Express服务器的脚本。我正在使用ES5

以下是我的server.js代码(用于运行Express服务器):

下面是我的schema.js的代码

const {makeExecutableSchema, addMockFunctionsToSchema} = require('graphql-tools');

const typeDefs = `type Query {
  greeting: String
}
`;

const schema = makeExecutableSchema({typeDefs});
addMockFunctionsToSchema({ schema });

module.exports = schema;
但我得到的是这样的信息:

错误:应为未定义的GraphQL架构

我无法找到我的错误所在

请注意,如果我将schema.js代码复制粘贴到server.js文件中,它会正常工作,就好像我没有正确导入(或导出)模式文件一样


我的错误在哪里

graphqlExpress
希望向其传递一个配置对象,该对象上的一个属性是
schema
。因此,您的代码应该如下所示:

app.use('/graphql', bodyParser.json(), graphqlExpress({
  schema: schemaTest,
}));
当前所做的是传入一个具有
schemaTest
属性的对象,但没有
schema
属性

app.use('/graphql', bodyParser.json(), graphqlExpress({
  schema: schemaTest,
}));