小编Pir*_*nha的帖子

如何在 Absinthe GraphQL 请求中接受 JSON

我试图在我的 graphql 实现中接收一串 JSON,但是我定义的用于处理 JSON 的自定义标量不断出现错误。

我已经定义了一个自定义标量来正确地将 JSON 序列化为 elixir 映射。在我的代码到达自定义标量的解析阶段之前,我收到错误数据类型无效。我正在尝试使用https://github.com/absinthe-graphql/absinthe/wiki/Scalar-Recipes#json-using-jason来创建标量,但是我已经修改为使用 Poison 而不是 Jason。

我的 absinthe mutator 使用我创建的 :json 标量类型。

@desc "Update user"
field :update_user, type: :user do
  arg(:email, :string)
  arg(:password, :string)
  arg(:first_name, :string)
  arg(:last_name, :string)
  arg(:age, :integer)
  arg(:client_store, :json)

  resolve(handle_errors(&Resolvers.User_Resolver.update_user/3))
end
Run Code Online (Sandbox Code Playgroud)

我的标量定义和 graphql 模式定义

    scalar :json, name: "Json" do
        description("""
        The `Json` scalar type represents arbitrary json string data, represented as UTF-8
        character sequences. The Json type is most often used to represent a free-form
        human-readable json …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework absinthe

5
推荐指数
1
解决办法
1077
查看次数

标签 统计

absinthe ×1

elixir ×1

phoenix-framework ×1