-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
RFC exporting variables between queries
This RFC calls for the ability to "export" variables from one query into another.
This allows a single server call to be made and outputs from one query to be fed into
others as variables.
So given:
query A {
hero
{
id @export(as:"droidId")
name
friends @export(as:"r2d2Friends")
{
name @export(as:"friendNames")
}
}
}
query B($droidId : String!) {
droid (id : $droidId ) {
name
}
}
Output values from operation A would be exported as the variables named "droidId", "r2d2Friends", and "friendNames"
The operation B would be detected to be dependent on operation A and would be executed after operation A completes. It would receive the
value of "droidId" as a variable from operation A
Multiple operation support
This RFC is dependent on #375, that is the ability to execute multiple operations in one server interaction
Variable arity
There are design questions around variable arity. In the example above the "droidId" exported variable can be thought of as a singleton value because the surrounding types are not lists types.
Where as "r2d2Friends" can be thought of as a list value because the surrounding types are list values and hence multiple exported variable values are possible.
One can imagine in certain cases some one might want map like semantics so that "the first / last" value of a list is considered a singleton value.
Naming could be used to indicate behaviour say, for example where plural export names imply a list while singlar variable names imply a singleton value. eg: "droidId" would always be considered a singleton value where as "friendNames" would always be considered a list value.
This is a great discussion point we think.
Consumer Supplied Variable Values
If the consumer caller supplies their own variable values, these will be passed to each operation. The exported variables will be placed into the variables map and will overwrite any existing variables with the same name key.
Exported Variable Value Validation
Validation of the variable values would follow the same rules as consumer supplied variable values.
Validation errors would be placed on each operation execution result
Current implementations
Sangria has this capability today https://sangria-graphql.org/learn/#batch-executor and graphql-java has a PR exploring the idea graphql-java/graphql-java#808
These are based on the ideas presented in a Facebook presentation about capabilities used within Facebook today.
We would love to see the Facebook learnings represented back out to the greater graphql community.