Absinthe和Dataloader之间的集成对我来说是非常新的,所以欢迎任何帮助。
我遇到了以下错误:
** (FunctionClauseError) no function clause matching in anonymous fn/3 in Absinthe.Resolution.Helpers.dataloader/2我的PostType
defmodule MyApp.Schema.Types.PostType do
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
object :post_type do
field(:id, :id)
field(:title, :string)
field(:body, :string)
field(:published, :boolean)
field :user, :user_type, resolve: dataloader(:user)
end
input_object :post_input_type do
field(:title, non_null(:string))
field(:body, non_null(:string))
field(:published, non_null(:boolean))
end
end架构突变:
@desc "Create a post"
field :create_post, type: :post_type do
arg(:input, non_null(:post_input_type))
middleware(Authorize, :any)
resolve(&Resolvers.PostResolver.create_post/3)
end解析器:
def create_post(_, %{input: input}, %{context: %{current_user: current_user}}) do
Map.merge(input, %{user_id: current_user.id})
|> Blog.create_post()
end发布于 2020-07-15 20:07:07
dataloader帮助器的第一个参数应该是模块,而不是原子。
为了说明起见,我假设您的User模块是在MyApp.Accounts.User中定义的,并且您有一个名为accounts.ex的文件。
在accounts.ex中,您应该拥有以下内容:
def data() do
Dataloader.Ecto.new(Repo)
end然后更改帖子类型中的用户字段,以使用以下内容:
field :user, :user_type, resolve: dataloader(User)如果它仍然不起作用,我可以提供更多帮助。我目前正在尝试使用Absinthe构建一个应用程序,所以它在我的脑海中还很新鲜。
https://stackoverflow.com/questions/62746082
复制相似问题