我有一个 GraphQL API,可以使用传统的解析函数正常工作。我的目标是消除N+1问题。
为此,我决定使用数据加载器。我已经完成了这些步骤以使应用程序运行:
defmodule Project.People do
# CRUD...
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
def query(queryable, _params) do
queryable
end
end
Run Code Online (Sandbox Code Playgroud)
context/1和添加plugins/0到架构模块并更新了查询解析器: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 | …Run Code Online (Sandbox Code Playgroud) 我们来描述一下问题:
mix phx.new{dev, test}.exs(我正在映射一个现有的数据库)mix phx.gen.context(它创建了一个迁移)的上下文我第一次尝试运行服务器,但它告诉我我有未部署的迁移。
there are pending migrations for repo: Some.Repo.
Try running `mix ecto.migrate` in the command line to migrate it
Run Code Online (Sandbox Code Playgroud)
然后我意识到我不需要它们,因为我已经有了数据库,所以我删除了迁移文件 ( /priv/repo/migrations/*) 并再次尝试。
现在mix ecto.migrations什么都不显示,但它没有删除服务器提示。然后我发现 ecto 在数据库中为迁移创建了一个额外的表,所以我检查了它,它是空的。
我放弃了它并尝试再次运行服务器,但显示了相同的消息。
为了确保这不是 Ecto 问题,我准备了测试并且它们运行得很好,唯一的问题是运行服务器时显示的迁移提示。
我还没有任何端点,因为我计划在验证模型正常工作后使用 GraphQL,但该消息令人困惑。
该迁移是否有任何隐藏文件,或者我是否遗漏了其他内容?
堆栈跟踪:
[error] #PID<0.451.0> running Some.Endpoint (connection #PID<0.449.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
** (Phoenix.Ecto.PendingMigrationError) there are pending migrations for repo: …Run Code Online (Sandbox Code Playgroud)