[英]Graphql mutation query not working with express-graphql
I am new to graphql. 我是graphql的新手。 I am using express-graphql to generate graphql queries on REST APIs for petSore schema.
我正在使用express-graphql在用于petSore模式的REST API上生成graphql查询。 I am able to get the result for GET APIs using graphql Queries but I am unable to get response for POST/PUT APIs using Mutations .
我可以使用graphql 查询获得GET API的结果,但无法使用Mutations获得POST / PUT API的响应。 ) To create pet I am using mutation as,
)要创建宠物,我正在使用突变,
mutation {
addPet(body: {id: "111", name: "doggie", photoUrls:["http://localhost:3000/pics/doggie"]}) {
name,
id
}
}
While running this query on localhost:3000/graphql I am getting error on backend(nodejs error) as, 在localhost:3000 / graphql上运行此查询时,后端出现错误(nodejs错误),因为
uncaughtException: First argument must be a string or Buffer...
It would be great if someone help me to understand what I am doing wrong here... 如果有人帮助我了解我在这里做错了,那将是非常不错的...
Node.js code : 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);
};
The process which I have to follow is: 我必须遵循的过程是:
the mutation declaration is not added on the code. 突变声明未添加到代码中。 Please add the mutation
请添加突变
Provided link to know how to do mutation enter link description here 提供的链接以了解如何进行突变在此处输入链接描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.