理解 Sangria-graphql 执行器
Understanding Sangria-graphql Executor
目前,我正在使用 playframework 学习 Sangria-graphql 并学习 here 的教程。我理解 Executor Executor.execute(schema, query, new ProductRepo)
接受模式、查询和上下文。另一方面,当我浏览演示示例代码时,我发现了 Executor 的使用,其中还提供了 operationName 和 Variables。例如,
Executor.execute(SchemaDefinition.StarWarsSchema, queryAst, new CharacterRepo,
operationName = operation,
variables = variables getOrElse Json.obj(),
deferredResolver = DeferredResolver.fetchers(SchemaDefinition.characters),
maxQueryDepth = Some(10))
.map(Ok(_))
我不太明白。如果变量意味着我们查询的争论,那么查询它自己包含查询参数,例如以下查询中的id
。
{
human(id: "1000") {
name
height(unit: FOOT)
}
}
此外,operationName 为什么以及如何在这种情况下有益?那么,任何人都可以向我解释一下它以及客户端如何为这些 operationName 和变量提供查询请求。
在这种情况下,变量的含义不同于参数(例如您的 id: "1000"
)。
看看documentation of variables in GraphQL。
同样适用于 operationName
:documentation for this
目前,我正在使用 playframework 学习 Sangria-graphql 并学习 here 的教程。我理解 Executor Executor.execute(schema, query, new ProductRepo)
接受模式、查询和上下文。另一方面,当我浏览演示示例代码时,我发现了 Executor 的使用,其中还提供了 operationName 和 Variables。例如,
Executor.execute(SchemaDefinition.StarWarsSchema, queryAst, new CharacterRepo,
operationName = operation,
variables = variables getOrElse Json.obj(),
deferredResolver = DeferredResolver.fetchers(SchemaDefinition.characters),
maxQueryDepth = Some(10))
.map(Ok(_))
我不太明白。如果变量意味着我们查询的争论,那么查询它自己包含查询参数,例如以下查询中的id
。
{
human(id: "1000") {
name
height(unit: FOOT)
}
}
此外,operationName 为什么以及如何在这种情况下有益?那么,任何人都可以向我解释一下它以及客户端如何为这些 operationName 和变量提供查询请求。
在这种情况下,变量的含义不同于参数(例如您的 id: "1000"
)。
看看documentation of variables in GraphQL。
同样适用于 operationName
:documentation for this