@apollo/query-graphs
Advanced tools
Comparing version 2.3.4 to 2.4.0-alpha.0
# CHANGELOG for `@apollo/query-graphs` | ||
## 2.3.4 | ||
## 2.4.0-alpha.0 | ||
### Patch Changes | ||
- Updated dependencies [[`6e2d24b5`](https://github.com/apollographql/federation/commit/6e2d24b5491914316b9930395817f0c3780f181a)]: | ||
- @apollo/federation-internals@2.3.4 | ||
- Updated dependencies [[`6e2d24b5`](https://github.com/apollographql/federation/commit/6e2d24b5491914316b9930395817f0c3780f181a), [`1a555d98`](https://github.com/apollographql/federation/commit/1a555d98f2030814ebd5074269d035b7f298f71e)]: | ||
- @apollo/federation-internals@2.4.0-alpha.0 | ||
@@ -9,0 +9,0 @@ ## 2.3.3 |
@@ -1,6 +0,11 @@ | ||
import { OperationElement } from "@apollo/federation-internals"; | ||
import { OperationElement, Variable } from "@apollo/federation-internals"; | ||
export declare function isPathContext(v: any): v is PathContext; | ||
export type OperationConditional = { | ||
kind: 'include' | 'skip'; | ||
value: boolean | Variable; | ||
}; | ||
export declare function extractOperationConditionals(operation: OperationElement): OperationConditional[]; | ||
export declare class PathContext { | ||
readonly conditionals: [string, any][]; | ||
constructor(conditionals: [string, any][]); | ||
readonly conditionals: OperationConditional[]; | ||
constructor(conditionals: OperationConditional[]); | ||
isEmpty(): boolean; | ||
@@ -7,0 +12,0 @@ withContextOf(operation: OperationElement): PathContext; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.emptyContext = exports.PathContext = exports.isPathContext = void 0; | ||
exports.emptyContext = exports.PathContext = exports.extractOperationConditionals = exports.isPathContext = void 0; | ||
const federation_internals_1 = require("@apollo/federation-internals"); | ||
@@ -14,8 +14,16 @@ const deep_equal_1 = __importDefault(require("deep-equal")); | ||
exports.isPathContext = isPathContext; | ||
function addExtractedConditional(operation, directiveName, addTo) { | ||
const applied = operation.appliedDirectivesOf(directiveName); | ||
function extractOperationConditionals(operation) { | ||
const conditionals = []; | ||
addExtractedConditional(operation, 'skip', conditionals); | ||
addExtractedConditional(operation, 'include', conditionals); | ||
return conditionals; | ||
} | ||
exports.extractOperationConditionals = extractOperationConditionals; | ||
function addExtractedConditional(operation, kind, addTo) { | ||
const applied = operation.appliedDirectivesOf(kind); | ||
if (applied.length > 0) { | ||
(0, federation_internals_1.assert)(applied.length === 1, () => `${directiveName} shouldn't be repeated on ${operation}`); | ||
(0, federation_internals_1.assert)(applied.length === 1, () => `${kind} shouldn't be repeated on ${operation}`); | ||
const value = applied[0].arguments()['if']; | ||
addTo.push([directiveName, value]); | ||
(0, federation_internals_1.assert)(typeof value === 'boolean' || (0, federation_internals_1.isVariable)(value), () => `Invalid value ${value} found as condition of @${kind}`); | ||
addTo.push({ kind, value }); | ||
} | ||
@@ -34,5 +42,3 @@ } | ||
} | ||
const newConditionals = []; | ||
addExtractedConditional(operation, 'skip', newConditionals); | ||
addExtractedConditional(operation, 'include', newConditionals); | ||
const newConditionals = extractOperationConditionals(operation); | ||
return newConditionals.length === 0 | ||
@@ -47,3 +53,3 @@ ? this | ||
return '[' | ||
+ this.conditionals.map(([name, cond]) => `@${name}(if: ${cond})`).join(', ') | ||
+ this.conditionals.map(({ kind, value }) => `@${kind}(if: ${value})`).join(', ') | ||
+ ']'; | ||
@@ -50,0 +56,0 @@ } |
{ | ||
"name": "@apollo/query-graphs", | ||
"version": "2.3.4", | ||
"version": "2.4.0-alpha.0", | ||
"description": "Apollo Federation library to work with 'query graphs'", | ||
@@ -26,3 +26,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@apollo/federation-internals": "2.3.4", | ||
"@apollo/federation-internals": "2.4.0-alpha.0", | ||
"deep-equal": "^2.0.5", | ||
@@ -29,0 +29,0 @@ "ts-graphviz": "^1.5.4", |
import { | ||
assert, | ||
isVariable, | ||
OperationElement, | ||
Variable, | ||
} from "@apollo/federation-internals"; | ||
@@ -11,8 +13,21 @@ import deepEqual from "deep-equal"; | ||
function addExtractedConditional(operation: OperationElement, directiveName: string, addTo: [string, any][]) { | ||
const applied = operation.appliedDirectivesOf(directiveName); | ||
export type OperationConditional = { | ||
kind: 'include' | 'skip', | ||
value: boolean | Variable, | ||
} | ||
export function extractOperationConditionals(operation: OperationElement): OperationConditional[] { | ||
const conditionals: OperationConditional[] = []; | ||
addExtractedConditional(operation, 'skip', conditionals); | ||
addExtractedConditional(operation, 'include', conditionals); | ||
return conditionals; | ||
} | ||
function addExtractedConditional(operation: OperationElement, kind: 'include' | 'skip', addTo: OperationConditional[]) { | ||
const applied = operation.appliedDirectivesOf(kind); | ||
if (applied.length > 0) { | ||
assert(applied.length === 1, () => `${directiveName} shouldn't be repeated on ${operation}`) | ||
assert(applied.length === 1, () => `${kind} shouldn't be repeated on ${operation}`) | ||
const value = applied[0].arguments()['if']; | ||
addTo.push([directiveName, value]); | ||
assert(typeof value === 'boolean' || isVariable(value), () => `Invalid value ${value} found as condition of @${kind}`); | ||
addTo.push({ kind, value }); | ||
} | ||
@@ -26,5 +41,5 @@ } | ||
constructor( | ||
// A list of [<directiveName>, <ifCondition>] (say: [['include', true], ['skip', $foo]]) in | ||
// the reverse order in which they were applied (so the first element is the inner-most applied skip/include). | ||
readonly conditionals: [string, any][], | ||
// A list of conditionals (say: [{ kind 'include', value: 'true'}], [{ kind: 'skip', value: '$foo' }]]) in the reverse order in which they were applied (so | ||
// the first element is the inner-most applied skip/include). | ||
readonly conditionals: OperationConditional[], | ||
) { | ||
@@ -42,6 +57,3 @@ } | ||
const newConditionals: [string, any][] = []; | ||
addExtractedConditional(operation, 'skip', newConditionals); | ||
addExtractedConditional(operation, 'include', newConditionals); | ||
const newConditionals = extractOperationConditionals(operation); | ||
return newConditionals.length === 0 | ||
@@ -58,3 +70,3 @@ ? this | ||
return '[' | ||
+ this.conditionals.map(([name, cond]) => `@${name}(if: ${cond})`).join(', ') | ||
+ this.conditionals.map(({kind, value}) => `@${kind}(if: ${value})`).join(', ') | ||
+ ']'; | ||
@@ -61,0 +73,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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
567093
7686
2
+ Added@apollo/federation-internals@2.4.0-alpha.0(transitive)
- Removed@apollo/federation-internals@2.3.4(transitive)