@luvio/graphql 0.142.2 → 0.142.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  function createFragmentMap(documentNode) {
4
2
  const fragments = {};
5
3
  documentNode.definitions.forEach((node) => {
@@ -130,9 +128,4 @@ function getOperationFromDocument(document, operationName) {
130
128
  return operations[0]; // If a named operation is not provided, we return the first one
131
129
  }
132
130
 
133
- exports.buildQueryTypeStringKey = buildQueryTypeStringKey;
134
- exports.buildQueryTypeStructuredKey = buildQueryTypeStructuredKey;
135
- exports.createFragmentMap = createFragmentMap;
136
- exports.getOperationFromDocument = getOperationFromDocument;
137
- exports.serializeFieldArguments = serializeFieldArguments;
138
- exports.serializeOperationNode = serializeOperationNode;
131
+ export { buildQueryTypeStringKey, buildQueryTypeStructuredKey, createFragmentMap, getOperationFromDocument, serializeFieldArguments, serializeOperationNode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/graphql",
3
- "version": "0.142.2",
3
+ "version": "0.142.4",
4
4
  "description": "GraphQL utilities for Luvio GraphQL adapter support",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,11 +9,11 @@
9
9
  },
10
10
  "license": "MIT",
11
11
  "exports": {
12
- "require": "./dist/luvioGraphql.js",
13
- "import": "./dist/luvioGraphql.mjs"
12
+ "types": "./dist/types/main.d.ts",
13
+ "import": "./dist/luvioGraphql.js",
14
+ "default": "./dist/luvioGraphql.js"
14
15
  },
15
- "main": "./dist/luvioGraphql.js",
16
- "module": "./dist/luvioGraphql.mjs",
16
+ "module": "./dist/luvioGraphql.js",
17
17
  "types": "dist/types/main.d.ts",
18
18
  "files": [
19
19
  "dist/"
@@ -27,8 +27,8 @@
27
27
  "test:size": "luvioBundlesize"
28
28
  },
29
29
  "dependencies": {
30
- "@luvio/engine": "^0.142.2",
31
- "@luvio/graphql-parser": "^0.142.2"
30
+ "@luvio/engine": "^0.142.4",
31
+ "@luvio/graphql-parser": "^0.142.4"
32
32
  },
33
33
  "volta": {
34
34
  "extends": "../../../package.json"
@@ -1,131 +0,0 @@
1
- function createFragmentMap(documentNode) {
2
- const fragments = {};
3
- documentNode.definitions.forEach((node) => {
4
- if (node.kind === 'FragmentDefinition') {
5
- fragments[node.name.value] = node;
6
- }
7
- });
8
- return fragments;
9
- }
10
-
11
- function serializeFieldArguments(argumentNodes, variables) {
12
- const mutableArgumentNodes = Object.assign([], argumentNodes);
13
- return `args__(${mutableArgumentNodes
14
- .sort((a, b) => {
15
- const aName = a.name.value.toUpperCase();
16
- const bName = b.name.value.toUpperCase();
17
- return aName < bName ? -1 : aName > bName ? 1 : 0;
18
- })
19
- .map((node) => serializeArgNode(node, variables))
20
- .join('::')})`;
21
- }
22
- function serializeArgNode(argumentNode, variables) {
23
- const argName = argumentNode.name.value;
24
- return `${argName}:${serializeValueNode(argumentNode.value, variables)}`;
25
- }
26
- function serializeValueNode(valueNode, variables) {
27
- switch (valueNode.kind) {
28
- case 'BooleanValue':
29
- return valueNode.value + '';
30
- case 'IntValue':
31
- case 'FloatValue':
32
- case 'EnumValue':
33
- case 'StringValue':
34
- return valueNode.value;
35
- case 'ListValue': {
36
- const mutableValueNodeList = Object.assign([], valueNode.values);
37
- return mutableValueNodeList
38
- .sort((a, b) => {
39
- const aVal = serializeValueNode(a, variables).toUpperCase();
40
- const bVal = serializeValueNode(b, variables).toUpperCase();
41
- return aVal < bVal ? -1 : aVal > bVal ? 1 : 0;
42
- })
43
- .map((val, i) => `${serializeValueNode(val, variables)}[${i}]`)
44
- .join(',');
45
- }
46
- case 'Variable': {
47
- const variableValue = variables[valueNode.name.value];
48
- return typeof variableValue === 'string'
49
- ? variableValue
50
- : JSON.stringify(variableValue);
51
- }
52
- case 'NullValue':
53
- return 'null';
54
- case 'ObjectValue': {
55
- const mutableFieldNodeList = Object.assign([], valueNode.fields);
56
- return mutableFieldNodeList
57
- .sort((a, b) => {
58
- const aName = a.name.value.toUpperCase();
59
- const bName = b.name.value.toUpperCase();
60
- return aName < bName ? -1 : aName > bName ? 1 : 0;
61
- })
62
- .map((field) => field.name.value + ':' + serializeValueNode(field.value, variables))
63
- .join(',');
64
- }
65
- }
66
- }
67
-
68
- function serializeOperationNode(operationNode, variables, fragmentMap) {
69
- return `${serializeSelectionSet(operationNode.selectionSet, variables, fragmentMap)}`;
70
- }
71
- function serializeSelectionSet(selectionSetNode, variables, fragmentMap) {
72
- return `${selectionSetNode.selections
73
- .map((selection) => serializeSelectionNode(selection, variables, fragmentMap))
74
- .join()}`;
75
- }
76
- /**
77
- *
78
- * @description This function takes a GraphQL SelectionNode from an AST and serializes it in a stable way, so we can
79
- * use it for property names and Store keys.
80
- * @param selectionNode
81
- * @param variables
82
- * @param fragmentMap
83
- * @returns string
84
- */
85
- function serializeSelectionNode(selectionNode, variables, fragmentMap) {
86
- switch (selectionNode.kind) {
87
- case 'Field': {
88
- const hasArguments = selectionNode.arguments !== undefined && selectionNode.arguments.length > 0;
89
- const argumentSuffix = hasArguments
90
- ? `__${serializeFieldArguments(selectionNode.arguments, variables)}`
91
- : '';
92
- return `${selectionNode.name.value}${argumentSuffix}`;
93
- }
94
- case 'FragmentSpread': {
95
- const fragment = fragmentMap[selectionNode.name.value];
96
- return fragment === undefined
97
- ? selectionNode.name.value
98
- : serializeSelectionSet(fragment.selectionSet, variables, fragmentMap);
99
- }
100
- case 'InlineFragment':
101
- return serializeSelectionSet(selectionNode.selectionSet, variables, fragmentMap);
102
- }
103
- }
104
- function buildQueryTypeStringKey(args) {
105
- const { keyPrefix, schemaName, queryTypeName, operationNode, variables, fragmentMap } = args;
106
- return `${keyPrefix}::${schemaName}::${queryTypeName}[${serializeOperationNode(operationNode, variables, fragmentMap)}]`;
107
- }
108
- // TODO: W-13079691 - Need to take another pass at what we want to do for structured keys
109
- function buildQueryTypeStructuredKey(args) {
110
- const { luvio, keyPrefix, schemaName, queryTypeName, operationNode, variables, fragmentMap } = args;
111
- return luvio.buildStructuredKey(keyPrefix, queryTypeName, {
112
- schemaName,
113
- operation: serializeOperationNode(operationNode, variables, fragmentMap),
114
- });
115
- }
116
-
117
- /**
118
- * @description Spec compliant way to retrieve the correct Operation from the Document that Luvio should operate on. https://spec.graphql.org/June2018/#sec-Named-Operation-Definitions
119
- * @param document
120
- * @param operationName
121
- * @returns The Operation in the GraphQL document we should use for the current call.
122
- */
123
- function getOperationFromDocument(document, operationName) {
124
- const operations = document.definitions.filter((def) => def.kind === 'OperationDefinition');
125
- if (operationName) {
126
- return operations.find((def) => def.name !== undefined && def.name.value === operationName);
127
- }
128
- return operations[0]; // If a named operation is not provided, we return the first one
129
- }
130
-
131
- export { buildQueryTypeStringKey, buildQueryTypeStructuredKey, createFragmentMap, getOperationFromDocument, serializeFieldArguments, serializeOperationNode };