- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 GraphQL api,使用传统的解析函数可以很好地工作。我的目标是消除 N+1 问题。
为此,我决定使用 Dataloader。我已经完成了这些步骤,据说可以让应用程序运行:
defmodule Project.People do
# CRUD...
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
def query(queryable, _params) do
queryable
end
end
context/1
和 plugins/0
到 Schema 模块并更新了查询的解析器:defmodule ProjectWeb.GraphQL.Schema do
use Absinthe.Schema
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias ProjectWeb.GraphQL.Schema
alias Project.People
import_types(Schema.Types)
query do
@desc "Get a list of all people."
field :people, list_of(:person) do
resolve(dataloader(People))
end
# Other queries...
end
def context(context) do
loader =
Dataloader.new()
|> Dataloader.add_source(People, People.data())
Map.put(context, :loader, loader)
end
def plugins, do: [Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults()]
end
:person
对象看起来像这样:
@desc "An object that defines a person."
object :person do
field :id, :id
field :birth_date, :date
field :first_name, :string
field :last_name, :string
field :pesel, :string
field :second_name, :string
field :sex, :string
# field :addresses, list_of(:address) do
# resolve(fn parent, _, _ ->
# addresses = Project.Repo.all(Ecto.assoc(parent, :addresses))
# {:ok, addresses}
# end)
# description("List of addresses that are assigned to this person.")
# end
# field :contacts, list_of(:contact) do
# resolve(fn parent, _, _ ->
# contacts = Project.Repo.all(Ecto.assoc(parent, :contacts))
# {:ok, contacts}
# end)
# description("List of contacts that are assigned to this person.")
# end
end
注释部分是在没有数据加载器的情况下工作且不会导致问题的解析器。
{
people {
id
}
}
我明白了:
Request: POST /graphiql
** (exit) an exception was raised:
** (Dataloader.GetError) The given atom - :people - is not a module.
This can happen if you intend to pass an Ecto struct in your call to
`dataloader/4` but pass something other than a struct.
我没有完全理解错误消息,因为我确实将模块传递给
dataloader/1
我找不到解决方案。可能是什么情况?
最佳答案
我已经设法让它工作了——方法如下:
数据加载器本身并不知道从数据库中提取什么,它只了解关联。因此dataloader(People)
只能是 object
的一部分 block ,而不是 query
堵塞。
换句话说:
defmodule ProjectWeb.GraphQL.Schema do
use Absinthe.Schema
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias ProjectWeb.GraphQL.Schema
alias Project.People
import_types(Schema.Types)
query do
@desc "Get a list of all people."
field :people, list_of(:person) do
resolve(&StandardPerson.resolver/2)
end
# Other queries...
end
def context(context) do
loader =
Dataloader.new()
|> Dataloader.add_source(People, People.data())
Map.put(context, :loader, loader)
end
def plugins, do: [Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults()]
end
和
@desc "An object that defines a person."
object :person do
field :id, :id
field :birth_date, :date
field :first_name, :string
field :last_name, :string
field :pesel, :string
field :second_name, :string
field :sex, :string
field :addresses, list_of(:address) do
resolve(dataloader(People))
description("List of addresses that are assigned to this person.")
end
field :contacts, list_of(:contact) do
resolve(dataloader(People))
description("List of contacts that are assigned to this person.")
end
end
关于graphql - 我怎样才能让苦艾酒和 Dataloader 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64826080/
我目前遇到以下情况,我想使用 DataLoader 批处理 numpy 数组: import numpy as np import torch import torch.utils.data as d
我现在正在使用 Pytorch 运行 Python 程序。我使用我自己的数据集,而不是 torch.data.dataset .我从从特征提取中提取的泡菜文件下载数据。但是出现以下错误: Traceb
问题 我有以下问题: 我想使用 pytorchs DataLoader(以类似于 here 的方式)但我的设置有点不同: 在我的数据文件夹中,我有不同街道情况的图像(让我们称它们为 image_tot
我已经通过这个 pytorch api 通过设置 download=True 下载了 ImageNet 数据集。但我无法遍历数据加载器。 错误说“'DataLoader' 对象不支持索引” train
我了解 dataLoader 如何使用简单的键工作: import DataLoader from 'dataloader'; import myService from './services/se
当遍历 PyTorch 数据加载器时,例如 # define dataset, dataloader train_data = datasets.ImageFolder(data_dir + '/tr
当遍历 PyTorch 数据加载器时,例如 # define dataset, dataloader train_data = datasets.ImageFolder(data_dir + '/tr
我正在使用 graphql 和 mongodb (mongoose) 构建一个快速 JS 应用程序。我正在使用 facebooks Dataloader 来批处理和缓存请求。 除了这个用例,它工作得很
查看 DataLoader library ,它是如何缓存和批处理请求的? 指令以下列方式指定用法: var DataLoader = require('dataloader') var userLo
shuffle = False时,不打乱数据顺序 shuffle = True,随机打乱 ?
关于Pytorch中怎么自定义Dataset数据集类、怎样使用DataLoader迭代加载数据,这篇官方文档已经说得很清楚了,这里就不在赘述。 现在的问题:有的时候,特别对于NLP任务来说,输入的
最近在学pytorch,在使用数据分批训练时在导入数据是使用了 DataLoader 在参数 num_workers的设置上使程序出现运行没有任何响应的结果 ,看看代码
有一个bug在 PyTorch/Numpy 中,当使用 DataLoader 并行加载批处理时(即设置 num_workers > 1),每个 worker 使用相同的 NumPy 随机种子,导致任何
我有以下错误。 Expected: /home/ubuntu/.pycharm_helpers/pydev/pydevd_attach_to_process/attach_linux_amd64.so
有一个bug在 PyTorch/Numpy 中,当与 DataLoader 并行加载批次时(即设置 num_workers > 1 ),每个 worker 使用相同的 NumPy 随机种子,导致应用的
我有一个 GraphQL api,使用传统的解析函数可以很好地工作。我的目标是消除 N+1 问题。 为此,我决定使用 Dataloader。我已经完成了这些步骤,据说可以让应用程序运行: 我将这两个函
当我创建一个 PyTorch DataLoader 并开始迭代时——我得到了一个非常慢的第一个纪元(x10--x30 比所有下一个纪元都慢)。此外,此问题仅出现在来自 Kaggle 的 Google
我有非常常见的 GraphQL 架构,如下所示(伪代码): Post { commentsPage(skip: Int, limit: Int) { total: Int item
有没有办法将DataLoader作为列表处理?我的想法是,我想对隐式图像对进行洗牌,而不将洗牌设置为 True 基本上,我有 10 个场景,每个场景包含 100 个序列,因此它们在目录中表示为 '1_
我需要用我训练的卷积神经网络的数据测试结果编写一个文件。数据包括语音数据采集。文件格式需要是“文件名,预测”,但我很难提取文件名。我这样加载数据: import torchvision from to
我是一名优秀的程序员,十分优秀!