投稿

[GraphQL] 複数エラーを返す方法

Imitating this article [https://github.com/rmosolgo/graphql-ruby/issues/629#issuecomment-589877682], but in my case, path was said "unknown keyword" and removed from parameters like below:

[GraphQL] 複数エラーを返す方法

GraphQL-Rubyのresolverから、単一のエラーではなく複数のエラーをレスポンスに含めたいときに使う方法。context.add_errorを呼んだ回数だけエラーが積み上がり、それぞれGraphQL::ExecutionErrorとしてレスポンスのerrors配列に返る。参照元の記事とは異なり、使用しているバージョンではpathキーワード引数が未知のキーワードとしてエラーになったため外している。2023年時点の情報。

Solution

Imitating this article [https://github.com/rmosolgo/graphql-ruby/issues/629#issuecomment-589877682], but in my case, path was said “unknown keyword” and removed from parameters like below:

def resolve(**args)
  context.add_error(
    GraphQL::ExecutionError.new(
      "first error message.",
      extensions: {...}
    )
  )
  context.add_error(
    GraphQL::ExecutionError.new(
      "second error message.",
      extensions: {...}
    )
  )
end

トレンドのタグ