[英]Express-graphql "Cannot read property 'collection' of undefined" with mongodb while runing mutation & query
[英]Graphql mutation query not working with express-graphql
我是graphql的新手。 我正在使用express-graphql在用于petSore模式的REST API上生成graphql查询。 我可以使用graphql 查询获得GET API的结果,但无法使用Mutations获得POST / PUT API的响应。 )要创建宠物,我正在使用突变,
mutation {
addPet(body: {id: "111", name: "doggie", photoUrls:["http://localhost:3000/pics/doggie"]}) {
name,
id
}
}
在localhost:3000 / graphql上运行此查询时,后端出现错误(nodejs错误),因为
uncaughtException: First argument must be a string or Buffer...
如果有人帮助我了解我在这里做错了,那将是非常不错的...
Node.js代码:
'use strict';
var graphqlHTTP = require('express-graphql');
var graphQLSchema = require('swagger-to-graphql');
var pathToSwaggerSchema = require('./schema.json');
module.exports = function(server) {
var router = server.loopback.Router();
router.get('/', server.loopback.status());
graphQLSchema(pathToSwaggerSchema).then(schema => {
server.use('/graphql', graphqlHTTP((req) => {
return {
schema: schema,
context: {
GQLProxyBaseUrl: 'http://localhost:3000/api/v2/',
},
graphiql: true,
};
}));
}).catch(e => {
throw e;
});
server.use(router);
};
我必须遵循的过程是:
突变声明未添加到代码中。 请添加突变
提供的链接以了解如何进行突变在此处输入链接描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.