例如,我想在以下模式中调用前端的inserted_on时间戳created_at:
defmodule MyAppWeb.Schema.AccountTypes do
use Absinthe.Schema.Notation
object :user do
field :id, :id
field :email, :string
field :inserted_on, :datetime
end
end但我不确定如何设置Ecto <-> Absinthe映射。我应该只向我的Ecto模式添加一个虚拟字段吗?
发布于 2018-01-24 18:18:33
一种选择是在Ecto模式中为数据库字段使用:source选项,这样您就可以使用自己的内部名称:
defmodule MyAppWeb.Schema.AccountTypes do
use Absinthe.Schema.Notation
object :user do
field :id, :id
field :email, :string
field :created_at, :datetime, source: :inserted_on
end
end但最好的选择可能是在查询宏中设置适当的字段名:
defmodule My.Schema do
use Absinthe.Schema
query do
field :created_at, :string do
resolve &MyResolver.inserted_on/3
end
end。。或者使用您自己的数据类型而不是字符串。
https://stackoverflow.com/questions/48363943
复制相似问题