gpt4 book ai didi

elixir - 如何在苦艾酒中使用时间戳? ( Phoenix 1.3)

转载 作者:行者123 更新时间:2023-12-01 23:07:35 25 4
gpt4 key购买 nike

我对 phoenix 1.3 + 苦艾酒有疑问。

我尝试这段代码:

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

最佳答案

日期时间 不是 default scalar types 的一部分GraphQL 附带的。 Here您可以了解如何使用 Absinthe 构建自定义标量类型。幸运的是datetime scalar type已经是 Absinthe 的一部分,为了使用它,您唯一需要做的就是导入它:

import_types Absinthe.Type.Custom

关于elixir - 如何在苦艾酒中使用时间戳? ( Phoenix 1.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45577500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com