@apollo/query-graphs
Advanced tools
Comparing version 2.0.2-alpha.0 to 2.0.2-alpha.1
# CHANGELOG for `@apollo/query-graphs` | ||
## 2.0.2-alpha.1 | ||
- Fix bug where planning a query with `@require` impacts the plans of followup queries [PR #1783](https://github.com/apollographql/federation/pull/1783). | ||
## v2.0.1 | ||
@@ -4,0 +8,0 @@ |
@@ -788,4 +788,6 @@ "use strict"; | ||
} | ||
debug.group(() => `Checking conditions ${conditions} on edge ${edge}`); | ||
const resolution = conditionResolver(edge, context, excludedEdges, excludedConditions); | ||
if (!resolution.satisfied) { | ||
debug.groupEnd('Conditions are not satisfied'); | ||
return exports.unsatisfiedConditionsResolution; | ||
@@ -799,7 +801,10 @@ } | ||
&& (!pathTree || pathTree.isAllInSameSubgraph())) { | ||
debug.log('@requires conditions are satisfied, but validating post-require key.'); | ||
const postRequireKeyCondition = getLocallySatisfiableKey(path.graph, edge.head); | ||
if (!postRequireKeyCondition) { | ||
debug.groupEnd('Post-require conditions cannot be satisfied'); | ||
return { ...exports.unsatisfiedConditionsResolution, unsatisfiedConditionReason: UnsatisfiedConditionReason.NO_POST_REQUIRE_KEY }; | ||
} | ||
} | ||
debug.groupEnd('Conditions satisfied'); | ||
return resolution; | ||
@@ -806,0 +811,0 @@ } |
@@ -48,2 +48,3 @@ "use strict"; | ||
constructor(index, head, tail, transition, conditions) { | ||
var _a; | ||
this.index = index; | ||
@@ -53,3 +54,3 @@ this.head = head; | ||
this.transition = transition; | ||
this._conditions = conditions; | ||
this._conditions = (_a = conditions === null || conditions === void 0 ? void 0 : conditions.clone()) === null || _a === void 0 ? void 0 : _a.freeze(); | ||
} | ||
@@ -81,6 +82,7 @@ get conditions() { | ||
addToConditions(newConditions) { | ||
if (!this._conditions) { | ||
this._conditions = new federation_internals_1.SelectionSet(this.head.type); | ||
} | ||
this._conditions = this._conditions | ||
? this._conditions.clone() | ||
: new federation_internals_1.SelectionSet(this.head.type); | ||
this._conditions.mergeIn(newConditions); | ||
this._conditions.freeze(); | ||
} | ||
@@ -87,0 +89,0 @@ toString() { |
{ | ||
"name": "@apollo/query-graphs", | ||
"version": "2.0.2-alpha.0", | ||
"version": "2.0.2-alpha.1", | ||
"description": "Apollo Federation library to work with 'query graphs'", | ||
@@ -26,3 +26,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@apollo/federation-internals": "^2.0.2-alpha.0", | ||
"@apollo/federation-internals": "^2.0.2-alpha.1", | ||
"deep-equal": "^2.0.5", | ||
@@ -37,3 +37,3 @@ "ts-graphviz": "^0.16.0" | ||
}, | ||
"gitHead": "077f496095196016643728e4829495408b391115" | ||
"gitHead": "7fcf0f23509f0d62fdb017c8e74a861cb304915d" | ||
} |
@@ -153,3 +153,11 @@ import { | ||
) { | ||
this._conditions = conditions; | ||
// Edges are meant to be immutable once a query graph is fully built. More precisely, | ||
// the whole query graph must be immutable once constructed since the query planner reuses | ||
// it for buiding multiple plans. | ||
// To ensure it/avoid hard-to-find bugs, we freeze the conditions (and because the caller might | ||
// not expect that this method freezes its input, we clone first), which ensure that if we add | ||
// them to another selection set during query planning, they will get automatically cloned first | ||
// (and thus this instance will not be modified). This fixes #1750 in particular and should | ||
// avoid such issue in the future. | ||
this._conditions = conditions?.clone()?.freeze(); | ||
} | ||
@@ -193,6 +201,11 @@ | ||
addToConditions(newConditions: SelectionSet) { | ||
if (!this._conditions) { | ||
this._conditions = new SelectionSet(this.head.type as CompositeType); | ||
} | ||
// As mentioned in the ctor, we freeze the conditions to avoid unexpected modifications once a query | ||
// graph has bee fully built (this method is called _during_ the building, so can still mutate the | ||
// edge freely). Which means we need to clone any existing conditions (so we can modify them), and need | ||
// to re-freeze the result afterwards. | ||
this._conditions = this._conditions | ||
? this._conditions.clone() | ||
: new SelectionSet(this.head.type as CompositeType); | ||
this._conditions.mergeIn(newConditions); | ||
this._conditions.freeze(); | ||
} | ||
@@ -199,0 +212,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
508726
6508