【问题标题】:Nodes GraphQL Mutation returning NULL返回 NULL 的节点 GraphQL 突变
【发布时间】:2021-04-01 06:29:55
【问题描述】:

我正在使用普通的 sql 查询,当我尝试通过突变向数据库中添加某些内容时,我可以在控制台中看到结果,但 graphql 游乐场返回 null

这里是 type.js

const XXXType = new GraphQLObjectType({
  name: "XXXType",
  description: "This represents XXX user",
  fields: () => ({
    id: { type: GraphQLInt },
    xxx_id: { type: GraphQLInt },
    xxx1_id: { type: GraphQLInt },
    xxx2_id: { type: GraphQLInt },
    is_deleted: { type: GraphQLBoolean },
  }),
});

这是我使用类型的突变

const XXXType = require("../Types/XXXType");
const deleted = require("../Types/deleted");
const DataLayer = require("../../random/random");
const addEditXXX = {
  type: XXXType,
  description: "Associate with XXX",
  args: {
    id: { type: GraphQLInt },
    xxx_id: { type: GraphQLInt },
    xxx1_id: { type: GraphQLInt },
    xxx2_id: { type: GraphQLInt },
  },
  async resolve(parent, args) {
    let errormessage = null;
    let params = {};
    params.body = {
      uid: args.xxx,
      pid: args.xxx1,
      utid: args.xxx2,
      id: args.id,
    };
    var res = null;
    res = await DataLayer.xxx_yyy_add(params);
    console.log("res", res.data);
    return res;
  },
};

【问题讨论】:

  • 变异结果类型....记录res.data,返回res ?记录数据的形状和所需的类型?

标签: node.js graphql


【解决方案1】:

已修复,问题是结果一直返回数组。

【讨论】:

    猜你喜欢
    • 2019-06-28
    • 2020-12-22
    • 2019-11-25
    • 2019-08-20
    • 2021-06-25
    • 2023-01-09
    • 1970-01-01
    • 2020-09-21
    • 2018-06-18
    相关资源
    最近更新 更多