I am new to graphql. I am using express-graphql to generate graphql queries on REST APIs for petSore schema. 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 . ) 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,
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 :
'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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.