0

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:

  1. Converting swagger to graphql schema.
  2. Provide generated graphql schema as an input for express-graphql.
  3. GQLProxyBaseUrl is backend url for all petstore REST APIs.
zulekha
  • 313
  • 9
  • 17

1 Answers1

0

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

Vishnu Prasad
  • 190
  • 1
  • 8