AppSync 查询因枚举失败

问题描述 投票:0回答:1

我是 AppSync 和 GraphQL 的新手,但我根据 SQL 表自动生成了以下架构。然后我尝试使用查询编辑器发送查询以将一些数据插入数据库,但是对于我们所在的表来说失败了定义了一个枚举字段。一旦我将 sql 数据库中的字段更改为 varchar,然后在此处更改它,它就可以正常工作。

input CreateManufacturerInput {
    active: Boolean!
    created: String
    category: manufacturer!
    updated: String
    id: Int
    name: String!
}

enum manufacturer {
    MAN_A
    MAN_B
    MAN_C
}
mutation MyMutation($name: String!, $category: manufacturer !, $active: Boolean!) {
  createManufacturer(input: {name: $name, category: $category, active: $active}) {
    id
  }
}

Query Variable:
{
  "name": "",
  "active": true,
  "category": "MAN_C" 
}

解析器代码是:

import { util } from '@aws-appsync/utils';
import { insert, createPgStatement, toJsonObject } from '@aws-appsync/utils/rds';



/**
 * Puts an item into the employees table using the supplied input.
 * @param {import('@aws-appsync/utils').Context} ctx the context
 * @returns {*} the request
 */
export function request(ctx) {
    const { input } = ctx.args;
    console.log("Custom Log | Input:", input, typeof input.category);
    const insertStatement = insert({
        table: 'manufacturer',
        values: input,
        returning: '*',
    });

    const pgst = createPgStatement(insertStatement);
    console.log(pgst, "SQL");
    return pgst;
}

/**
 * Returns the result or throws an error if the operation failed.
 * @param {import('@aws-appsync/utils').Context} ctx the context
 * @returns {*} the result
 */
export function response(ctx) {
    const { error, result } = ctx;
    if (error) {
        return util.appendError(error.message, error.type, result);
    }
    return toJsonObject(result)[0][0];
}

我得到的回应是:

{
  "data": {
    "createManufacturer": null
  },
  "errors": [
    {
      "path": [
        "createManufacturer"
      ],
      "data": null,
      "errorType": "400 Bad Request",
      "errorInfo": null,
      "locations": [
        {
          "line": 8,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "RDSHttp:{\"message\":\"ERROR: column \\\"category\\\" is of type manufacturer but expression is of type text; Hint: You will need to rewrite or cast the expression.; Position: 96; SQLState: 42804\"}"
    },
    {
      "path": [
        "createManufacturer",
        "id"
      ],
      "locations": null,
      "message": "Cannot return null for non-nullable type: 'Int' within parent 'Manufacturer' (/createManufacturer/id)"
    }
  ]
}
postgresql amazon-web-services graphql aws-appsync aws-appsync-resolver
1个回答
0
投票

您可以分享您用来触发突变的代码吗

© www.soinside.com 2019 - 2024. All rights reserved.