如何在 Absinthe 中使用时间戳? (凤凰1.3)

How can I use timestamps in Absinthe? (Phoenix 1.3)

我对 phoenix 1.3 + absinthe 有疑问。

我试试这个代码:

schema "urls" do
  field :path, :string

  timestamps()
 end

object :url do
  field :id, :id
  field :path, :string
  field :inserted_at, :datetime
end

它与 idpath 一起工作,但它与 inserted_at 一起工作失败:

Inserted_at :datetime is not defined in your schema.          

Types must exist if referenced.   


lib/absinthe/schema.ex:230: Absinthe.Schema.__after_compile__/2     
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6                     
(elixir) lib/kernel/parallel_compiler.ex:121: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

datetime 不是 Absinthe 的一部分 default scalar types that GraphQL comes with. Here you can find out how to build custom scalar types with Absinthe. Luckily datetime scalar type 已经是 Absinthe 的一部分,您唯一需要做的就是导入它:

import_types Absinthe.Type.Custom