Skip to content

Commit a05127c

Browse files
Tests pass
1 parent ba38230 commit a05127c

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

http-ts/tests/behaviour/steps/analyze.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,9 @@ import {
1313
Reducer,
1414
PipelineAnnotations,
1515
VariableAnnotations,
16+
FetchAnnotations,
1617
FunctionAnnotations,
1718
} from "../../../dist/index.cjs";
18-
// import {QueryConstraintAny, QueryVertex} from "../../../src";
19-
// import {
20-
// FunctionReturnStructure,
21-
// FunctionStructure,
22-
// PipelineAnnotations,
23-
// PipelineStage,
24-
// PipelineStructure,
25-
// Reducer, VariableAnnotations
26-
// } from "../../../src/analyze";
2719

2820

2921
When('get answers of typeql analyze', async function (query: string) {
@@ -83,10 +75,11 @@ Then('analyzed preamble annotations contains:', function (expectedFunctor: strin
8375
const found = preambleFunctors.some(actual =>
8476
normalizeFunctorForCompare(actual) === normalizedExpected
8577
);
86-
assert.ok(found, `Expected to find functor in preamble: ${normalizedExpected}\nFound: ${preambleFunctors.join('\n')}`);});
78+
assert.ok(found, `Expected to find functor in preamble: ${normalizedExpected}\nFound: ${preambleFunctors.join('\n')}`);
79+
});
8780

8881
Then('analyzed fetch annotations are:', function (expectedFunctor: string) {
89-
assert.ok(false, "Implement me")
82+
encodeFetchAnnotations(analyzed.annotations.fetch);
9083
});
9184

9285
function normalizeFunctorForCompare(functor: string): string {
@@ -260,9 +253,9 @@ function encodePipelineStage(stage: PipelineStage, encoder: FunctorEncoder): str
260253
variant,
261254
encoder.encodeAsList(stage.variables.map(v => encodeVariable(v, encoder)))
262255
);
263-
case "sort":{
256+
case "sort": {
264257
const sortVariables = stage.variables.map(v => encoder.makeFunctor(
265-
v.ascending? "Asc" : "Desc",
258+
v.ascending ? "Asc" : "Desc",
266259
encodeVariable(v.variable, encoder),
267260
));
268261
return encoder.makeFunctor(variant, encoder.encodeAsList(sortVariables));
@@ -372,7 +365,7 @@ function encodeConjunctionAnnotations(conjunctionIndex: number, encoder: Functor
372365
const variableAnnotations = Object.keys(conjunctionAnnotations.variableAnnotations).map(v => {
373366
const annotations = conjunctionAnnotations.variableAnnotations[v];
374367
return [encodeVariable(v, encoder), encodeVariableAnnotations(annotations, encoder)]
375-
}).sort().map(([k,v]) => `${k} : ${v}`);
368+
}).sort().map(([k, v]) => `${k} : ${v}`);
376369
return encoder.makeFunctor(
377370
"And",
378371
"{" + variableAnnotations.join(",") + "}",
@@ -418,3 +411,19 @@ function encodeFunctionAnnotations(structure: FunctionStructure, annotations: Fu
418411
encodePipelineAnnotations(structure.body, encoder)
419412
);
420413
}
414+
415+
function encodeFetchAnnotations(fetch: FetchAnnotations): string {
416+
switch (fetch.tag) {
417+
case "list": {
418+
const inner = encodeFetchAnnotations(fetch.elements);
419+
return `List(${inner})`;
420+
}
421+
case "object": {
422+
const kv = fetch.possibleFields.map(inner => `${inner.key}: ${encodeFetchAnnotations(inner)}`);
423+
return "{" + kv.join(",") + "}";
424+
}
425+
case "value":
426+
return "[" + fetch.valueTypes.join(",") + "]";
427+
}
428+
throw new Error("Unknown fetch annotations variant");
429+
}

0 commit comments

Comments
 (0)