我的 GraphQL 查询如下所示:
{
p1: property(someArgs: "some_value") {
id
nestedField {
id
moreNestedField {
id
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在服务器端,我使用 Apollo Server。我有一个用于 的解析器,以及用于和property的其他解析器。我需要检索嵌套解析器上的值。我尝试使用解析器上的可用资源来执行此操作:nestedFieldmoreNestedFieldsomeArgscontext
property: (_, {someArgs}, ctx) => {
ctx.someArgs = someArgs;
// Do something
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为上下文在所有解析器之间共享,因此如果我property的查询有多个,则上下文值不会很好。
我还尝试在嵌套解析器上使用path可用的。info我可以去现场property,但我在这里没有争论......
我还尝试添加一些数据info,但它没有在嵌套解析器上共享。
在所有解析器上添加参数不是一个选项,因为它会使查询变得非常臃肿并且编写起来很麻烦,我不希望这样。
有什么想法吗?
谢谢!
我正在使用纱线工作区运行 Node.js monorepo 项目。文件结构如下所示:
workspace_root
node_modules
package.json
apps
appA
node_modules
package.json
appB
node_modules
package.json
libs
libA
dist
node_modules
package.json
Run Code Online (Sandbox Code Playgroud)
所有应用程序都是独立的,但它们都需要libA
我正在使用 docker-compose 运行所有这些应用程序。我的问题是如何正确处理所有依赖项,因为我不希望node_modules文件夹与主机同步。在本地,当我yarn install在工作区根目录下运行时,它会为所有项目安装所有依赖项,并填充不同的node_modules. 在 docker-compose 中,理想情况下,每个应用程序都不应该知道其他应用程序。
到目前为止,我的方法有效但并不理想,而且可扩展性不强。
version: "3.4"
services:
# The core is in charge of installing dependencies for ALL services. Each service must for wait the core, and then
# just do their job, not having to handle install.
appA:
image: node:14-alpine
volumes: # We must load every volumes …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的集合:
{
"_id" : ObjectId("5783051796a90cd8098fc3e0"),
"name" : "Org 1",
"locations" : [
{
"name" : "loc 1",
"_id" : ObjectId("57831ac2febcceaf173e81ab"),
"address" : {
"coordinates" : [
172.6034932,
-43.5333797
]
}
},
{
"name" : "loc 2",
"_id" : ObjectId("5783436dc57b8d6248c9c196"),
"address" : {
"coordinates" : [
172.6034977,
-43.5335158
]
}
},
{
"name" : "loc 3",
"_id" : ObjectId("5783439bc57b8d6248c9c197"),
"address" : {
"coordinates" : [
168.6626435,
-45.0311622
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
有一个2dsphere索引locations.address.coordinates
我正在使用aggreagatewithgeonear来查询这些文档: …