带有 Absinthe 后端的正确 GraphQL 查询中的未知参数

Unknown argument in an otherwise correct GraphQL query with Absinthe backend

我是 运行 一个 Absinthe 查询,具有三个参数字段,它们都是整数列表。

@desc "Fetches resolutions of Taiga ids"
field :taiga_ids, :taiga_entities do
  arg :usIds, list_of(:integer)
  arg :taskIds, list_of(:integer)
  arg :issueIds, list_of(:integer)

  resolve &Resolvers.Bridges.fetch_taiga_ids/3
end

object :taiga_entities do
  field :uss, list_of(:taiga_us)
  field :tasks, list_of(:taiga_task)
  field :issues, list_of(:taiga_issue)
end

我也在使用 Insomnia 发送查询并处理结果。据我所知,一切都写得正确,类型得到尊重,参数输入正确。

{
  taigaIds(usIds: [1914], taskIds: [], issueIds: [7489]) {
    uss {
      id
      ref
      subject
    }
    issues {
      id
      ref
      subject
    }
  } 
}

但我收到以下错误,这些错误毫无意义。

{
  "errors": [
    {
      "message": "Unknown argument \"usIds\" on field \"taigaIds\" of type \"RootQueryType\".",
      "locations": [
        {
          "line": 2,
          "column": 0
        }
      ]
    },
    {
      "message": "Unknown argument \"taskIds\" on field \"taigaIds\" of type \"RootQueryType\".",
      "locations": [
        {
          "line": 2,
          "column": 0
        }
      ]
    },
    {
      "message": "Unknown argument \"issueIds\" on field \"taigaIds\" of type \"RootQueryType\".",
      "locations": [
        {
          "line": 2,
          "column": 0
        }
      ]
    }
  ]
}

知道为什么吗?

按照惯例,字段和参数等模式实体的名称写成 camelCase,而 elixer 使用 snake_caseabsinthe 在这两种命名约定之间进行转换。根据 docs:

This defines an adapter that supports GraphQL query documents in their conventional (in JS) camelcase notation, while allowing the schema to be defined using conventional (in Elixir) underscore (snakecase) notation, and tranforming the names as needed for lookups, results, and error messages

...

Note variables are a client-facing concern (they may be provided as parameters), so variable names should match the convention of the query document (eg, camelCase).

换句话说,像这样定义你的参数:

arg :task_ids, list_of(:integer)

它们将为您转换为 camelCase