繁体   English   中英

GraphQL突变查询不适用于Express-GraphQL

[英]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);
 };

我必须遵循的过程是:

  1. 将swagger转换为graphql模式。
  2. 提供生成的graphql模式作为express-graphql的输入。
  3. GQLProxyBaseUrl是所有petstore REST API的后端URL。

突变声明未添加到代码中。 请添加突变

提供的链接以了解如何进行突变在此处输入链接描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM