1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const intermediates_1 = require("./intermediates");
|
4 | const immutable_1 = require("immutable");
|
5 | const lodash_1 = require("lodash");
|
6 | const ExtendedFieldType = fragments => type => {
|
7 | switch (type.kind) {
|
8 | case "FragmentReference":
|
9 | case "InlineSelection":
|
10 | return exports.ExtendedFragmentOrSelection(fragments)(type);
|
11 | case "List":
|
12 | return intermediates_1.List(ExtendedFieldType(fragments)(type.ofType));
|
13 | case "Maybe":
|
14 | return intermediates_1.Maybe(ExtendedFieldType(fragments)(type.ofType));
|
15 | default:
|
16 | return type;
|
17 | }
|
18 | };
|
19 | const typesAreEqual = (lhs, rhs) => {
|
20 | switch (lhs.kind) {
|
21 | case "Enum":
|
22 | return lhs.kind == rhs.kind && lhs.name == rhs.name;
|
23 | case "Typename":
|
24 | return (lhs.kind == rhs.kind && lhs.possibleTypes.equals(rhs.possibleTypes));
|
25 | case "Scalar":
|
26 | return lhs.kind == rhs.kind && lhs.name == rhs.name;
|
27 | case "InlineSelection":
|
28 | return lhs.kind == rhs.kind && exports.extendedSelectionsAreEqual(lhs, rhs);
|
29 | case "Maybe":
|
30 | return lhs.kind == rhs.kind && typesAreEqual(lhs.ofType, rhs.ofType);
|
31 | case "List":
|
32 | return lhs.kind == rhs.kind && typesAreEqual(lhs.ofType, rhs.ofType);
|
33 | }
|
34 | };
|
35 | const nameAndField = fragments => field => [
|
36 | field.name,
|
37 | { type: ExtendedFieldType(fragments)(field.type), optional: false }
|
38 | ];
|
39 | exports.ExtendedSelection = (inlineSelection, fragments) => {
|
40 | return {
|
41 | kind: inlineSelection.kind,
|
42 | fields: immutable_1.Map(inlineSelection.possibleTypes.map((type) => [type, immutable_1.Map(inlineSelection.fields.map(nameAndField(fragments)))])).mergeDeep(...inlineSelection.intersections
|
43 | .map(exports.ExtendedFragmentOrSelection(fragments))
|
44 | .map(selection => selection.fields), ...inlineSelection.typeConditions
|
45 | .map(exports.ExtendedFragmentOrSelection(fragments))
|
46 | .map(selection => selection.fields), ...inlineSelection.booleanConditions
|
47 | .map(exports.ExtendedFragmentOrSelection(fragments))
|
48 | .map(selection => selection.fields))
|
49 | };
|
50 | };
|
51 | exports.ExtendedFragmentOrSelection = fragments => fragmentOrSelection => fragmentOrSelection.kind == "InlineSelection"
|
52 | ? exports.ExtendedSelection(fragmentOrSelection, fragments)
|
53 | : exports.ExtendedSelection(fragments[fragmentOrSelection.name], fragments);
|
54 | const mapsAreEqual = (lhs, rhs, compareValues) => immutable_1.Set(lhs.keySeq()).equals(immutable_1.Set(rhs.keySeq())) &&
|
55 | lodash_1.every(lhs.keySeq().toArray(), key => compareValues(lhs.get(key), rhs.get(key)));
|
56 | const extendedFieldsAreEqual = (lhs, rhs) => mapsAreEqual(lhs, rhs, (lhs, rhs) => mapsAreEqual(lhs, rhs, (lhs, rhs) => lhs.optional == rhs.optional && typesAreEqual(lhs.type, rhs.type)));
|
57 | exports.extendedSelectionsAreEqual = (lhs, rhs) => extendedFieldsAreEqual(lhs.fields, rhs.fields);
|
58 |
|
\ | No newline at end of file |