带有苦艾酒的后端的其他正确GraphQL查询中的未知参数

时间:2019-04-30 19:42:13

标签: elixir graphql absinthe insomnia

我正在运行一个具有三个参数字段的苦艾查询,所有这些参数字段都是整数列表。

@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
        }
      ]
    }
  ]
}

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

按照约定,模式实体(如字段和参数)的名称写为camelCase,而elixer使用snake_caseabsinthe在这两种命名约定之间进行转换。根据{{​​3}}:

  

这定义了一个适配器,该适配器以其常规(在JS中)驼峰符号表示法支持GraphQL查询文档,同时允许使用常规(在Elixir中)下划线(snakecase)表示法定义架构,并根据需要转换名称,结果和错误消息

     

...

     

请注意,变量是面向客户的问题(它们可以作为参数提供),因此变量名称应与查询文档的约定(例如camelCase)相匹配。

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

arg :task_ids, list_of(:integer)

,它们将为您转换为camelCase