@luvio/compiler 0.95.0 → 0.97.1

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.
Files changed (137) hide show
  1. package/dist/codegen/adapter/adapter-key-builder.js +1 -1
  2. package/dist/codegen/adapter/adapter-key-builder.js.map +1 -1
  3. package/dist/codegen/adapter/adapter-network.js +1 -1
  4. package/dist/codegen/adapter/adapter-network.js.map +1 -1
  5. package/dist/codegen/adapter/adapter-notify-change.js +2 -2
  6. package/dist/codegen/adapter/adapter-notify-change.js.map +1 -1
  7. package/dist/codegen/adapter/adapter-param-type-check.js +2 -2
  8. package/dist/codegen/adapter/adapter-param-type-check.js.map +1 -1
  9. package/dist/codegen/adapter/adapter-prepare-request.js +1 -1
  10. package/dist/codegen/adapter/adapter-prepare-request.js.map +1 -1
  11. package/dist/codegen/adapter/create-resource-params.js +21 -6
  12. package/dist/codegen/adapter/create-resource-params.js.map +1 -1
  13. package/dist/codegen/adapter/delete/adapter-network.js +1 -1
  14. package/dist/codegen/adapter/delete/adapter-network.js.map +1 -1
  15. package/dist/codegen/adapter/graphql/adapter-config-transformer.js +8 -2
  16. package/dist/codegen/adapter/graphql/adapter-config-transformer.js.map +1 -1
  17. package/dist/codegen/adapter/graphql/adapter-fragment.d.ts +4 -0
  18. package/dist/codegen/adapter/graphql/adapter-fragment.js +24 -0
  19. package/dist/codegen/adapter/graphql/adapter-fragment.js.map +1 -0
  20. package/dist/codegen/adapter/graphql/adapter-resource-error.d.ts +4 -0
  21. package/dist/codegen/adapter/graphql/adapter-resource-error.js +33 -0
  22. package/dist/codegen/adapter/graphql/adapter-resource-error.js.map +1 -0
  23. package/dist/codegen/adapter/graphql/adapter-resource-success.d.ts +4 -0
  24. package/dist/codegen/adapter/graphql/adapter-resource-success.js +35 -0
  25. package/dist/codegen/adapter/graphql/adapter-resource-success.js.map +1 -0
  26. package/dist/codegen/adapter/graphql/adapter-type-check.d.ts +5 -0
  27. package/dist/codegen/adapter/graphql/adapter-type-check.js +52 -0
  28. package/dist/codegen/adapter/graphql/adapter-type-check.js.map +1 -0
  29. package/dist/codegen/adapter/graphql/index.js +5 -5
  30. package/dist/codegen/adapter/graphql/index.js.map +1 -1
  31. package/dist/codegen/adapter/patch-post/adapter-network.js +1 -1
  32. package/dist/codegen/adapter/patch-post/adapter-network.js.map +1 -1
  33. package/dist/codegen/adapter/util.d.ts +0 -1
  34. package/dist/codegen/adapter/util.js +1 -34
  35. package/dist/codegen/adapter/util.js.map +1 -1
  36. package/dist/codegen/adapter-tests/expected-responses.js +1 -1
  37. package/dist/codegen/graphql/directive/defaults/include-apply-to-selection.js +1 -1
  38. package/dist/codegen/graphql/directive/defaults/skip-apply-to-selection.js +1 -1
  39. package/dist/codegen/graphql/directive/util.js +2 -2
  40. package/dist/codegen/graphql/directive/util.js.map +1 -1
  41. package/dist/codegen/graphql/interface/index.js +2 -0
  42. package/dist/codegen/graphql/interface/index.js.map +1 -1
  43. package/dist/codegen/graphql/interface/ingest.js +1 -1
  44. package/dist/codegen/graphql/interface/ingest.js.map +1 -1
  45. package/dist/codegen/graphql/interface/select.js +1 -1
  46. package/dist/codegen/graphql/interface/type-cache-keys.d.ts +5 -0
  47. package/dist/codegen/graphql/interface/type-cache-keys.js +36 -0
  48. package/dist/codegen/graphql/interface/type-cache-keys.js.map +1 -0
  49. package/dist/codegen/graphql/type/constants.d.ts +7 -3
  50. package/dist/codegen/graphql/type/constants.js +8 -4
  51. package/dist/codegen/graphql/type/constants.js.map +1 -1
  52. package/dist/codegen/graphql/type/convert.d.ts +6 -0
  53. package/dist/codegen/graphql/type/convert.js +174 -0
  54. package/dist/codegen/graphql/type/convert.js.map +1 -0
  55. package/dist/codegen/graphql/type/generateTypeUtil.js +73 -112
  56. package/dist/codegen/graphql/type/generateTypeUtil.js.map +1 -1
  57. package/dist/codegen/graphql/type/index.js +4 -0
  58. package/dist/codegen/graphql/type/index.js.map +1 -1
  59. package/dist/codegen/graphql/type/ingest.d.ts +3 -3
  60. package/dist/codegen/graphql/type/ingest.js +76 -110
  61. package/dist/codegen/graphql/type/ingest.js.map +1 -1
  62. package/dist/codegen/graphql/type/interface.js +1 -1
  63. package/dist/codegen/graphql/type/interface.js.map +1 -1
  64. package/dist/codegen/graphql/type/key.js +4 -3
  65. package/dist/codegen/graphql/type/key.js.map +1 -1
  66. package/dist/codegen/graphql/type/query-transformer.js +10 -10
  67. package/dist/codegen/graphql/type/query-transformer.js.map +1 -1
  68. package/dist/codegen/graphql/type/select.d.ts +1 -1
  69. package/dist/codegen/graphql/type/select.js +117 -74
  70. package/dist/codegen/graphql/type/select.js.map +1 -1
  71. package/dist/codegen/graphql/type/type-cache-keys.d.ts +9 -0
  72. package/dist/codegen/graphql/type/type-cache-keys.js +182 -0
  73. package/dist/codegen/graphql/type/type-cache-keys.js.map +1 -0
  74. package/dist/codegen/graphql/type/type-from-field.d.ts +6 -0
  75. package/dist/codegen/graphql/type/type-from-field.js +66 -0
  76. package/dist/codegen/graphql/type/type-from-field.js.map +1 -0
  77. package/dist/codegen/graphql/union/index.js +2 -0
  78. package/dist/codegen/graphql/union/index.js.map +1 -1
  79. package/dist/codegen/graphql/union/ingest.js +1 -1
  80. package/dist/codegen/graphql/union/ingest.js.map +1 -1
  81. package/dist/codegen/graphql/union/select.js +1 -1
  82. package/dist/codegen/graphql/union/type-cache-keys.d.ts +5 -0
  83. package/dist/codegen/graphql/union/type-cache-keys.js +36 -0
  84. package/dist/codegen/graphql/union/type-cache-keys.js.map +1 -0
  85. package/dist/codegen/graphql/utils/types.js +1 -1
  86. package/dist/codegen/resource/composite/ingest-success-child-resource-params.js +1 -1
  87. package/dist/codegen/resource/composite/ingest-success-child-resource-params.js.map +1 -1
  88. package/dist/codegen/resource/composite/ingest-success.js +1 -1
  89. package/dist/codegen/resource/composite/ingest-success.js.map +1 -1
  90. package/dist/codegen/resource/composite/response-child-cache-keys.js +3 -3
  91. package/dist/codegen/resource/composite/response-child-cache-keys.js.map +1 -1
  92. package/dist/codegen/resource/composite/select-child-resource-params.js +2 -2
  93. package/dist/codegen/resource/composite/select-child-resource-params.js.map +1 -1
  94. package/dist/codegen/resource/evict-success.js +1 -1
  95. package/dist/codegen/resource/evict-success.js.map +1 -1
  96. package/dist/codegen/resource/graphql/ingest-error.js +5 -2
  97. package/dist/codegen/resource/graphql/ingest-error.js.map +1 -1
  98. package/dist/codegen/resource/graphql/ingest-success.js +9 -4
  99. package/dist/codegen/resource/graphql/ingest-success.js.map +1 -1
  100. package/dist/codegen/resource/graphql/key-builder.d.ts +2 -1
  101. package/dist/codegen/resource/graphql/key-builder.js +12 -3
  102. package/dist/codegen/resource/graphql/key-builder.js.map +1 -1
  103. package/dist/codegen/resource/graphql/response-cache-keys.js +5 -3
  104. package/dist/codegen/resource/graphql/response-cache-keys.js.map +1 -1
  105. package/dist/codegen/resource/graphql/select.js +9 -6
  106. package/dist/codegen/resource/graphql/select.js.map +1 -1
  107. package/dist/codegen/resource/ingest-error.js +1 -1
  108. package/dist/codegen/resource/ingest-error.js.map +1 -1
  109. package/dist/codegen/resource/ingest-success.js +2 -2
  110. package/dist/codegen/resource/ingest-success.js.map +1 -1
  111. package/dist/codegen/resource/key-builder.js +2 -2
  112. package/dist/codegen/resource/key-builder.js.map +1 -1
  113. package/dist/codegen/resource/response-cache-keys.js +6 -6
  114. package/dist/codegen/resource/response-cache-keys.js.map +1 -1
  115. package/dist/codegen/shape/graphql/index.js +2 -2
  116. package/dist/codegen/shape/graphql/index.js.map +1 -1
  117. package/dist/codegen/shape/graphql/key-builder.js +1 -1
  118. package/dist/codegen/shape/graphql/key-builder.js.map +1 -1
  119. package/dist/codegen/shape/graphql/shape-cache-keys.d.ts +3 -0
  120. package/dist/codegen/shape/graphql/shape-cache-keys.js +59 -0
  121. package/dist/codegen/shape/graphql/shape-cache-keys.js.map +1 -0
  122. package/dist/codegen/shape/graphql/shape-ingest.js +10 -6
  123. package/dist/codegen/shape/graphql/shape-ingest.js.map +1 -1
  124. package/dist/codegen/shape/graphql/shape-select.js +9 -6
  125. package/dist/codegen/shape/graphql/shape-select.js.map +1 -1
  126. package/dist/codegen/shape/shape-cache-keys.js +6 -6
  127. package/dist/codegen/shape/shape-cache-keys.js.map +1 -1
  128. package/dist/codegen/shape/shape-keybuilder.js +10 -9
  129. package/dist/codegen/shape/shape-keybuilder.js.map +1 -1
  130. package/dist/codegen/shape/shape-utils-ingest.js +1 -1
  131. package/dist/codegen/shape/shape-utils-ingest.js.map +1 -1
  132. package/dist/codegen/shape/shape-utils.js +17 -1
  133. package/dist/codegen/shape/shape-utils.js.map +1 -1
  134. package/dist/codegen/shared/constants.d.ts +3 -0
  135. package/dist/codegen/shared/constants.js +4 -1
  136. package/dist/codegen/shared/constants.js.map +1 -1
  137. package/package.json +4 -4
@@ -18,34 +18,34 @@ function generateTypeUtil(graphqlResource, metadata, importContext) {
18
18
  throw new Error('Invalid GraphQL Schema. You must include a Query Type.');
19
19
  }
20
20
  const queryTypeName = queryType.name;
21
- const queryTransformerImport = importContext.importGraphQLArtifact('types', queryTypeName, 'getQueryTransformerForField');
22
- const queryTransformerForTypeImport = importContext.importGraphQLArtifact('types', queryTypeName, 'getQueryTransformerForType');
23
- const arrayIsArrayUtilsIdentifier = importContext.importTypeUtil('ArrayIsArray');
24
- // TODO: W-11246519 improve readability of the applyMinimumFields function by replacing the AST visitor with
25
- // manual node traversal
21
+ const getQueryTransformHelperForFieldImport = importContext.importGraphQLArtifact('types', queryTypeName, 'getQueryTransformHelperForField');
22
+ const getQueryTransformHelperForTypeImport = importContext.importGraphQLArtifact('types', queryTypeName, 'getQueryTransformHelperForType');
26
23
  return (0, imports_1.resolveImports)((0, deindent_1.default) `
27
24
  export type ${constants_3.GRAPHQL_VARIABLES_IDENTIFIER} = Record<string, any>;
28
25
  export type ${constants_3.GRAPHQL_FRAGMENT_MAP_IDENTIFIER} = Record<string, ${constants_2.LUVIO_GRAPHQL_FRAGMENT_DEFINITION_NODE_IMPORT}>;
29
26
  export interface ${constants_3.GRAPHQL_STATE_INTERFACE_IDENTIFIER}<D = unknown> {
30
27
  data: D,
31
- variables: ${constants_3.GRAPHQL_VARIABLES_IDENTIFIER},
32
- fragments: ${constants_3.GRAPHQL_FRAGMENT_MAP_IDENTIFIER},
33
28
  path: ${constants_1.ADAPTER_INGEST_PATH_INTERFACE_IDENTIFIER},
29
+ variables: ${constants_3.GRAPHQL_VARIABLES_IDENTIFIER},
30
+ fragments: ${constants_3.GRAPHQL_FRAGMENT_MAP_IDENTIFIER}
31
+ }
32
+
33
+ export interface ${constants_3.GRAPHQL_INGEST_STATE_INTERFACE_IDENTIFIER}<D> extends ${constants_3.GRAPHQL_STATE_INTERFACE_IDENTIFIER}<D> {
34
34
  ${constants_2.LUVIO_IDENTIFIER}: ${constants_2.LUVIO_IMPORT},
35
35
  ${constants_2.LUVIO_STORE_IDENTIFIER}: ${constants_2.LUVIO_STORE_IMPORT},
36
36
  ${constants_3.TIMESTAMP_IDENTIFIER}: number
37
37
  };
38
38
 
39
- export interface QueryTransformerFunction {
40
- (fieldId: string): ${constants_3.QUERY_TRANSFORMER_IDENTIFIER} | undefined;
39
+ export interface GetQueryTransformHelperFunction {
40
+ (fieldId: string): ${constants_3.QUERY_TRANSFORM_HELPER_IDENTIFIER} | undefined;
41
41
  }
42
42
 
43
43
  export interface GetMinimumFieldsFunction {
44
44
  (): ${constants_2.LUVIO_GRAPHQL_FIELD_NODE_IMPORT}[];
45
45
  }
46
46
 
47
- export interface ${constants_3.QUERY_TRANSFORMER_IDENTIFIER} {
48
- ${constants_3.GET_QUERY_TRANSFORMER_FOR_FIELD_IDENTIFIER}: QueryTransformerFunction,
47
+ export interface ${constants_3.QUERY_TRANSFORM_HELPER_IDENTIFIER} {
48
+ ${constants_3.GET_QUERY_TRANSFORM_HELPER_FOR_FIELD_IDENTIFIER}: GetQueryTransformHelperFunction,
49
49
  ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER}: GetMinimumFieldsFunction
50
50
  }
51
51
 
@@ -56,7 +56,7 @@ function generateTypeUtil(graphqlResource, metadata, importContext) {
56
56
  }
57
57
 
58
58
  export function ${constants_3.SERIALIZE_FIELD_ARGUMENTS_IDENTIFIER}(argumentNodes: Readonly<${constants_2.LUVIO_GRAPHQL_ARGUMENT_NODE_IMPORT}[]>, variables: ${constants_3.GRAPHQL_VARIABLES_IDENTIFIER}): string {
59
- const mutableArgumentNodes = Object.assign([], argumentNodes);
59
+ const mutableArgumentNodes = Object.assign([] as ${constants_2.LUVIO_GRAPHQL_ARGUMENT_NODE_IMPORT}[], argumentNodes);
60
60
  return \`args__(\${mutableArgumentNodes.sort(
61
61
  (a, b) =>{
62
62
  const aName = a.name.value.toUpperCase()
@@ -80,19 +80,19 @@ function generateTypeUtil(graphqlResource, metadata, importContext) {
80
80
  case("StringValue"):
81
81
  return valueNode.value
82
82
  case("ListValue"):
83
- const mutableValueNodeList = Object.assign([], valueNode.values);
83
+ const mutableValueNodeList = Object.assign([] as ${constants_2.LUVIO_GRAPHQL_VALUE_NODE_IMPORT}[], valueNode.values);
84
84
  return mutableValueNodeList.sort(
85
85
  (a, b) =>{
86
- const aName = a.name.value.toUpperCase()
87
- const bName = b.name.value.toUpperCase()
88
- return aName < bName ? -1 : (aName > bName) ? 1 : 0
86
+ const aVal = serializeValueNode(a, variables).toUpperCase()
87
+ const bVal = serializeValueNode(b, variables).toUpperCase()
88
+ return aVal < bVal ? -1 : (aVal > bVal) ? 1 : 0
89
89
  }).map((val, i) => serializeValueNode(val, variables) + \`[\${i}]\`).join(',')
90
90
  case("Variable"):
91
91
  return variables[valueNode.name.value] + "" //TODO: Is this correct serialization for object type variables?
92
92
  case("NullValue"):
93
93
  return "null";
94
94
  case("ObjectValue"):
95
- const mutableFieldNodeList = Object.assign([], valueNode.fields);
95
+ const mutableFieldNodeList = Object.assign([] as ${constants_2.LUVIO_GRAPHQL_OBJECT_FIELD_NODE_IMPORT}[], valueNode.fields);
96
96
  return mutableFieldNodeList.sort(
97
97
  (a, b) =>{
98
98
  const aName = a.name.value.toUpperCase()
@@ -105,104 +105,65 @@ function generateTypeUtil(graphqlResource, metadata, importContext) {
105
105
  export const TTL = ${(0, utils_1.getShapeTtl)(metadata.rootTtl, (_a = graphqlResource.returnShape) === null || _a === void 0 ? void 0 : _a.id, metadata.shapeTtls)};
106
106
 
107
107
  export function ${constants_3.APPLY_MINIMUM_FIELDS_TO_QUERY_IDENTIFIER} (query: ${constants_2.LUVIO_GRAPHQL_DOCUMENT_NODE_IMPORT}): ${constants_2.LUVIO_GRAPHQL_DOCUMENT_NODE_IMPORT} {
108
- const queryTransformerStack: ${constants_3.QUERY_TRANSFORMER_IDENTIFIER}[] = [];
109
- const visitor: ${constants_2.LUVIO_GRAPHQL_AST_VISITOR_IMPORT} = {
110
- OperationDefinition: {
111
- enter(node) {
112
- if (node.operation === 'query') {
113
- queryTransformerStack.push({
114
- ${constants_3.GET_QUERY_TRANSFORMER_FOR_FIELD_IDENTIFIER}: ${queryTransformerImport},
115
- ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER}: () => {return []}
116
- });
117
- }
118
- },
119
- },
120
- Field: {
121
- enter(node) {
122
- if (node.selectionSet?.selections !== undefined) {
123
- const { ${constants_3.GET_QUERY_TRANSFORMER_FOR_FIELD_IDENTIFIER} } = queryTransformerStack[queryTransformerStack.length - 1];
124
- const queryTransformer = ${constants_3.GET_QUERY_TRANSFORMER_FOR_FIELD_IDENTIFIER}(node.name.value);
125
- if (queryTransformer === undefined) {
126
- throw new Error("Invalid field in query '" + node.name.value
127
- + "' at line: " + node.name.loc?.startToken.line
128
- + " column: " + node.name.loc?.startToken.column);
129
- }
130
- queryTransformerStack.push(queryTransformer);
131
- }
132
- },
133
- leave(node) {
134
- if (node.selectionSet?.selections !== undefined) {
135
- queryTransformerStack.pop();
136
- }
137
- }
138
- },
139
- InlineFragment: {
140
- enter(node, _key, parentFields) {
141
- if (node.typeCondition !== undefined && node.typeCondition !== null) {
142
- const queryTransformer = ${queryTransformerForTypeImport}(node.typeCondition.name.value)
143
- if (queryTransformer === undefined) {
144
- throw new Error("Invalid type in query fragment '" + node.typeCondition.name.value
145
- + "' at line: " + node.typeCondition.name.loc?.startToken.line
146
- + " column: " + node.typeCondition.name.loc?.startToken.column);
147
- }
148
- const { ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER} } = queryTransformer;
108
+ query.definitions.forEach(queryDefinitionNode => {
109
+ if (queryDefinitionNode.kind === 'OperationDefinition' && queryDefinitionNode.operation === 'query') {
110
+ injectSelectionSet(queryDefinitionNode.selectionSet, {
111
+ ${constants_3.GET_QUERY_TRANSFORM_HELPER_FOR_FIELD_IDENTIFIER}: ${getQueryTransformHelperForFieldImport},
112
+ ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER}: () => { return [] }
113
+ });
114
+ }
115
+ })
116
+ return query;
117
+ }
149
118
 
150
- // create a wrapper for the getMinimumFields function that filters
151
- // out any fields already present via encapsulation in the parent fields
152
- let wrappedGetMinimumFields = ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER};
153
- if (${arrayIsArrayUtilsIdentifier}(parentFields)) {
154
- wrappedGetMinimumFields = ():${constants_2.LUVIO_GRAPHQL_FIELD_NODE_IMPORT}[] => {
155
- return ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER}().filter((field) => {
156
- const fieldIsAlreadyPresent = parentFields.some(parentField => {
157
- return parentField.kind == 'Field' && parentField.name.value === field.name.value;
158
- });
159
- return !fieldIsAlreadyPresent;
160
- });
161
- };
162
- }
163
- queryTransformerStack.push({
164
- ...queryTransformer,
165
- ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER}: wrappedGetMinimumFields
166
- });
167
- }
168
- },
169
- leave(node) {
170
- if (node.typeCondition !== undefined) {
171
- queryTransformerStack.pop();
172
- }
119
+ export function injectSelectionSet (selectionSetNode: ${constants_2.LUVIO_GRAPHQL_SELECTION_SET_NODE_IMPORT}, queryTransformHelper: ${constants_3.QUERY_TRANSFORM_HELPER_IDENTIFIER}|undefined) {
120
+ const { selections } = selectionSetNode;
121
+ if (queryTransformHelper === undefined ||
122
+ queryTransformHelper === null ||
123
+ selections === undefined ||
124
+ selections === null) {
125
+ return;
126
+ }
127
+
128
+ const { getMinimumFields, getQueryTransformHelperForField } = queryTransformHelper;
129
+
130
+ // Call the function to get the minimum fields for this node, filtering out any
131
+ // fields that are already present in the selection.
132
+ const minimumFields = getMinimumFields().filter(field => {
133
+ const fieldIsAlreadyPresent = selections.some(selection => {
134
+ return selection.kind === 'Field' && (selection.name.value === field.name.value);
135
+ });
136
+ return !fieldIsAlreadyPresent;
137
+ });
138
+
139
+ selectionSetNode.selections = [...selections, ...minimumFields];
140
+
141
+ selectionSetNode.selections.forEach(selection => {
142
+ if (selection.kind === 'Field' && selection.selectionSet) {
143
+ const fieldTransformHelper = getQueryTransformHelperForField(selection.name.value);
144
+ injectSelectionSet(selection.selectionSet, fieldTransformHelper);
145
+ }
146
+ if (selection.kind === 'InlineFragment' && selection.selectionSet && selection.typeCondition) {
147
+ // create a wrapper for the getMinimumFields function that filters
148
+ // out any fields already present via encapsulation in the parent fields
149
+ const fieldTransformHelper = ${getQueryTransformHelperForTypeImport}(selection.typeCondition.name.value);
150
+ if (fieldTransformHelper === undefined) {
151
+ return;
173
152
  }
174
- },
175
- SelectionSet: {
176
- enter(node, _key, _parent) {
177
- // No changes if no selections.
178
- const { selections } = node;
179
- if (!selections) {
180
- return;
181
- }
182
-
183
- // This node is always entered after a Field node. A query transformer for this node was pushed
184
- // onto the stack when that Field node was entered. The query transformer provides a function
185
- // to get the minimum fields for this node.
186
- const { ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER} } = queryTransformerStack[queryTransformerStack.length - 1];
187
-
188
- // Call the function to get the minimum fields for this node, filtering out any
189
- // fields that are already present in the selection.
190
- const minimumFields = ${constants_3.GET_MINIMUM_FIELDS_IDENTIFIER}().filter(field => {
191
- const fieldIsAlreadyPresent = selections.some(selection => {
192
- return selection.kind === 'Field' && (selection.name.value === field.name.value);
153
+ const wrappedGetMinimumFields = ():${constants_2.LUVIO_GRAPHQL_FIELD_NODE_IMPORT}[] => {
154
+ return fieldTransformHelper.getMinimumFields().filter((field) => {
155
+ const fieldIsAlreadyPresent = selectionSetNode.selections.some(parentField => {
156
+ return parentField.kind === 'Field' && parentField.name.value === field.name.value;
193
157
  });
194
158
  return !fieldIsAlreadyPresent;
195
159
  });
196
-
197
- // Return a new SelectionSet including minimum fields
198
- return {
199
- ...node,
200
- selections: [...selections, ...minimumFields],
201
- };
202
- },
203
- },
204
- };
205
- return ${constants_2.LUVIO_GRAPHQL_VISIT_IMPORT}(query, visitor);
160
+ };
161
+ injectSelectionSet(selection.selectionSet, {
162
+ ...fieldTransformHelper,
163
+ getMinimumFields: wrappedGetMinimumFields
164
+ });
165
+ }
166
+ })
206
167
  }
207
168
 
208
169
  export function ${constants_3.GET_REQUESTED_FIELD_IDENTIFIER}(responseDataFieldName: string, requestedFields: ${constants_2.LUVIO_GRAPHQL_FIELD_NODE_IMPORT}[]): ${constants_2.LUVIO_GRAPHQL_FIELD_NODE_IMPORT} | undefined {
@@ -216,12 +177,12 @@ function generateTypeUtil(graphqlResource, metadata, importContext) {
216
177
  }
217
178
 
218
179
  export function ${constants_3.GET_REQUESTED_FIELDS_FOR_TYPE_IDENTIFIER}(typename: string, selectionSet: ${constants_2.LUVIO_GRAPHQL_SELECTION_SET_NODE_IMPORT}, namedFragmentsMap: ${constants_3.GRAPHQL_FRAGMENT_MAP_IDENTIFIER}): ${constants_2.LUVIO_GRAPHQL_FIELD_NODE_IMPORT}[] {
219
- const selections = [];
180
+ const selections: ${constants_2.LUVIO_GRAPHQL_FIELD_NODE_IMPORT}[] = [];
220
181
  selectionSet.selections.forEach(selection => {
221
182
  if(selection.kind === "Field") {
222
183
  selections.push(selection);
223
184
  }
224
- if(selection.kind === "InlineFragment" && selection.typeCondition.name.value === typename) {
185
+ if(selection.kind === "InlineFragment" && selection.typeCondition?.name.value === typename) {
225
186
  ${constants_3.GET_REQUESTED_FIELDS_FOR_TYPE_IDENTIFIER}(typename, selection.selectionSet, namedFragmentsMap)
226
187
  .forEach(fragmentFieldSelection => selections.push(fragmentFieldSelection));
227
188
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generateTypeUtil.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/type/generateTypeUtil.ts"],"names":[],"mappings":";;;;;;AAAA,uEAA+C;AAC/C,oDAAwD;AAExD,oCAAuC;AAGvC,uDAAmF;AACnF,sDAagC;AAChC,2CAcqB;AAErB,SAAgB,gBAAgB,CAC5B,eAAgC,EAChC,QAAgC,EAChC,aAA4B;;IAE5B,kHAAkH;IAClH,MAAM,SAAS,GAAG,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACnE,IAAI,CAAC,SAAS,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC7E;IACD,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC;IACrC,MAAM,sBAAsB,GAAG,aAAa,CAAC,qBAAqB,CAC9D,OAAO,EACP,aAAa,EACb,6BAA6B,CAChC,CAAC;IACF,MAAM,6BAA6B,GAAG,aAAa,CAAC,qBAAqB,CACrE,OAAO,EACP,aAAa,EACb,4BAA4B,CAC/B,CAAC;IAEF,MAAM,2BAA2B,GAAG,aAAa,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAEjF,4GAA4G;IAC5G,wBAAwB;IACxB,OAAO,IAAA,wBAAc,EAAC,IAAA,kBAAQ,EAAA;sBACZ,wCAA4B;sBAC5B,2CAA+B,qBAAqB,yDAA6C;2BAC5F,8CAAkC;;yBAEpC,wCAA4B;yBAC5B,2CAA+B;oBACpC,oDAAwC;cAC9C,4BAAgB,KAAK,wBAAY;cACjC,kCAAsB,KAAK,8BAAkB;cAC7C,gCAAoB;;;;iCAID,wCAA4B;;;;kBAI3C,2CAA+B;;;2BAGtB,wCAA4B;cACzC,sDAA0C;cAC1C,yCAA6B;;;0BAGjB,kCAAsB;;;;;;0BAMtB,gDAAoC,4BAA4B,8CAAkC,mBAAmB,wCAA4B;;;;;;;;;;kDAUzH,8CAAkC,gBAAgB,wCAA4B;;;;;iDAK/E,2CAA+B,gBAAgB,wCAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAgC/F,IAAA,mBAAW,EAC5B,QAAQ,CAAC,OAAO,EAChB,MAAA,eAAe,CAAC,WAAW,0CAAE,EAAE,EAC/B,QAAQ,CAAC,SAAS,CACrB;;0BAEiB,oDAAwC,YAAY,8CAAkC,MAAM,8CAAkC;2CAC7G,wCAA4B;6BAC1C,4CAAgC;;;;;kCAK3B,sDAA0C,KAAK,sBAAsB;kCACrE,yCAA6B;;;;;;;;sCAQzB,sDAA0C;uDACzB,sDAA0C;;;;;;;;;;;;;;;;;;uDAkB1C,6BAA6B;;;;;;sCAM9C,yCAA6B;;;;4DAIP,yCAA6B;kCACvD,2BAA2B;+DACE,2CAA+B;6CACjD,yCAA6B;;;;;;;;;;kCAUxC,yCAA6B;;;;;;;;;;;;;;;;;;;;;kCAqB7B,yCAA6B;;;;gDAIf,yCAA6B;;;;;;;;;;;;;;;qBAexD,sCAA0B;;;0BAGrB,0CAA8B,oDAAoD,2CAA+B,QAAQ,2CAA+B;;;;0BAIxJ,mDAAuC,WAAW,2CAA+B,gBAAgB,wCAA4B;;qGAElD,gDAAoC;;;;0BAI/G,oDAAwC,oCAAoC,mDAAuC,wBAAwB,2CAA+B,MAAM,2CAA+B;;;;;;;sBAOnN,oDAAwC;;;;;;0BAMpC,oDAAwC;;;;;;;KAO7D,CAAC,CAAC;AACP,CAAC;AAnPD,4CAmPC"}
1
+ {"version":3,"file":"generateTypeUtil.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/type/generateTypeUtil.ts"],"names":[],"mappings":";;;;;;AAAA,uEAA+C;AAC/C,oDAAwD;AAExD,oCAAuC;AAGvC,uDAAmF;AACnF,sDAYgC;AAChC,2CAeqB;AAErB,SAAgB,gBAAgB,CAC5B,eAAgC,EAChC,QAAgC,EAChC,aAA4B;;IAE5B,kHAAkH;IAClH,MAAM,SAAS,GAAG,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACnE,IAAI,CAAC,SAAS,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC7E;IACD,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC;IACrC,MAAM,qCAAqC,GAAG,aAAa,CAAC,qBAAqB,CAC7E,OAAO,EACP,aAAa,EACb,iCAAiC,CACpC,CAAC;IACF,MAAM,oCAAoC,GAAG,aAAa,CAAC,qBAAqB,CAC5E,OAAO,EACP,aAAa,EACb,gCAAgC,CACnC,CAAC;IAEF,OAAO,IAAA,wBAAc,EAAC,IAAA,kBAAQ,EAAA;sBACZ,wCAA4B;sBAC5B,2CAA+B,qBAAqB,yDAA6C;2BAC5F,8CAAkC;;oBAEzC,oDAAwC;yBACnC,wCAA4B;yBAC5B,2CAA+B;;;2BAG7B,qDAAyC,eAAe,8CAAkC;cACvG,4BAAgB,KAAK,wBAAY;cACjC,kCAAsB,KAAK,8BAAkB;cAC7C,gCAAoB;;;;iCAID,6CAAiC;;;;kBAIhD,2CAA+B;;;2BAGtB,6CAAiC;cAC9C,2DAA+C;cAC/C,yCAA6B;;;0BAGjB,kCAAsB;;;;;;0BAMtB,gDAAoC,4BAA4B,8CAAkC,mBAAmB,wCAA4B;+DAC5G,8CAAkC;;;;;;;;;kDAS/C,8CAAkC,gBAAgB,wCAA4B;;;;;iDAK/E,2CAA+B,gBAAgB,wCAA4B;;;;;;;;;;uEAUrD,2CAA+B;;;;;;;;;;;;uEAY/B,kDAAsC;;;;;;;;;;6BAUhF,IAAA,mBAAW,EAC5B,QAAQ,CAAC,OAAO,EAChB,MAAA,eAAe,CAAC,WAAW,0CAAE,EAAE,EAC/B,QAAQ,CAAC,SAAS,CACrB;;0BAEiB,oDAAwC,YAAY,8CAAkC,MAAM,8CAAkC;;;;0BAI9H,2DAA+C,KAAK,qCAAqC;0BACzF,yCAA6B;;;;;;;gEAOS,mDAAuC,2BAA2B,6CAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mDA8BhH,oCAAoC;;;;yDAI9B,2CAA+B;;;;;;;;;;;;;;;;0BAgB9D,0CAA8B,oDAAoD,2CAA+B,QAAQ,2CAA+B;;;;0BAIxJ,mDAAuC,WAAW,2CAA+B,gBAAgB,wCAA4B;;qGAElD,gDAAoC;;;;0BAI/G,oDAAwC,oCAAoC,mDAAuC,wBAAwB,2CAA+B,MAAM,2CAA+B;gCACzM,2CAA+B;;;;;;sBAMzC,oDAAwC;;;;;;0BAMpC,oDAAwC;;;;;;;KAO7D,CAAC,CAAC;AACP,CAAC;AA3MD,4CA2MC"}
@@ -13,6 +13,8 @@ const merge_1 = require("./merge");
13
13
  const imports_1 = require("../../../utils/imports");
14
14
  const select_1 = require("./select");
15
15
  const query_transformer_1 = require("./query-transformer");
16
+ const type_cache_keys_1 = require("./type-cache-keys");
17
+ const type_from_field_1 = require("./type-from-field");
16
18
  function generateType(graphqlDsl, graphqlTypeName, def, importContext, metadata, modelInfo) {
17
19
  return (0, imports_1.resolveImports)((0, deindent_1.default) `
18
20
  export const name = '${graphqlTypeName}';
@@ -23,6 +25,8 @@ function generateType(graphqlDsl, graphqlTypeName, def, importContext, metadata,
23
25
  ${(0, ingest_1.generateIngest)(graphqlDsl, graphqlTypeName, def, importContext, metadata, modelInfo)}
24
26
  ${(0, select_1.generateSelect)(graphqlDsl, graphqlTypeName, def, importContext, metadata)}
25
27
  ${(0, query_transformer_1.generate)(graphqlDsl, graphqlTypeName, def, importContext, metadata)}
28
+ ${(0, type_cache_keys_1.generateGetTypeCacheKeys)(graphqlDsl, graphqlTypeName, def, importContext, metadata)}
29
+ ${(0, type_from_field_1.generateGetFieldType)(graphqlDsl, def, importContext, metadata)}
26
30
  `);
27
31
  }
28
32
  exports.generateType = generateType;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/type/index.ts"],"names":[],"mappings":";;;;;;AAAA,uEAA+C;AAC/C,+BAAoC;AACpC,2CAAiD;AACjD,qCAA0C;AAC1C,+BAAoC;AACpC,mCAAwC;AACxC,oDAAwD;AAKxD,qCAA0C;AAC1C,2DAA2E;AAG3E,SAAgB,YAAY,CACxB,UAA2B,EAC3B,eAAuB,EACvB,GAA6B,EAC7B,aAA4B,EAC5B,QAAgC,EAChC,SAAoB;IAEpB,OAAO,IAAA,wBAAc,EAAC,IAAA,kBAAQ,EAAA;+BACH,eAAe;UACpC,IAAA,iBAAW,EAAC,UAAU,EAAE,eAAe,CAAC;UACxC,IAAA,8BAAkB,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;UAC7E,IAAA,iBAAW,EAAC,GAAG,EAAE,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC;UACtD,IAAA,qBAAa,EAAC,aAAa,CAAC;UAC5B,IAAA,uBAAc,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAC;UACpF,IAAA,uBAAc,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;UACzE,IAAA,4BAAwB,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;KACxF,CAAC,CAAC;AACP,CAAC;AAlBD,oCAkBC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/type/index.ts"],"names":[],"mappings":";;;;;;AAAA,uEAA+C;AAC/C,+BAAoC;AACpC,2CAAiD;AACjD,qCAA0C;AAC1C,+BAAoC;AACpC,mCAAwC;AACxC,oDAAwD;AAKxD,qCAA0C;AAC1C,2DAA2E;AAE3E,uDAA6D;AAC7D,uDAAyD;AAEzD,SAAgB,YAAY,CACxB,UAA2B,EAC3B,eAAuB,EACvB,GAA6B,EAC7B,aAA4B,EAC5B,QAAgC,EAChC,SAAoB;IAEpB,OAAO,IAAA,wBAAc,EAAC,IAAA,kBAAQ,EAAA;+BACH,eAAe;UACpC,IAAA,iBAAW,EAAC,UAAU,EAAE,eAAe,CAAC;UACxC,IAAA,8BAAkB,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;UAC7E,IAAA,iBAAW,EAAC,GAAG,EAAE,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC;UACtD,IAAA,qBAAa,EAAC,aAAa,CAAC;UAC5B,IAAA,uBAAc,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAC;UACpF,IAAA,uBAAc,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;UACzE,IAAA,4BAAwB,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;UACnF,IAAA,0CAAwB,EAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;UACnF,IAAA,sCAAoB,EAAC,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC;KACnE,CAAC,CAAC;AACP,CAAC;AApBD,oCAoBC"}
@@ -4,7 +4,7 @@ import type { NormalizableTypes } from '../utils';
4
4
  import type { LuvioGraphQLDSL } from '../../../intermediate/graphql';
5
5
  import type { GraphQLCodegenMetadata } from '../source-printer';
6
6
  import type { ModelInfo } from '../../../main';
7
- export declare function ingestNamedType(field: FieldDefinitionNode, typeNode: NamedTypeNode, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
8
- export declare function ingestListType(field: FieldDefinitionNode, typeNode: ListTypeNode, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
9
- export declare function ingestType(field: FieldDefinitionNode, typeNode: TypeNode, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
7
+ export declare function ingestNamedType(graphqlField: FieldDefinitionNode, typeNode: NamedTypeNode, ramlFieldName: string | undefined, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
8
+ export declare function ingestListType(graphqlField: FieldDefinitionNode, typeNode: ListTypeNode, ramlFieldName: string | undefined, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
9
+ export declare function ingestType(graphqlField: FieldDefinitionNode, typeNode: TypeNode, ramlFieldName: string | undefined, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
10
10
  export declare function generateIngest(graphqlDsl: LuvioGraphQLDSL, graphqlTypeName: string, def: ObjectTypeDefinitionNode, importContext: ImportContext, _metadata: GraphQLCodegenMetadata, modelInfo: ModelInfo): string;
@@ -8,54 +8,71 @@ const deindent_1 = __importDefault(require("../../../utils/deindent"));
8
8
  const constants_1 = require("../../shared/constants");
9
9
  const utils_1 = require("../utils");
10
10
  const utils_2 = require("./utils");
11
+ const convert_1 = require("./convert");
11
12
  const constants_2 = require("./constants");
12
13
  const interface_1 = require("./interface");
13
14
  const types_1 = require("../utils/types");
14
15
  const REQUESTED_FIELDS_IDENTIFIER = 'requestedFields';
15
- function ingestNamedType(field, typeNode, importContext, normalizableTypeMap) {
16
+ function generateIngestScalarField(graphqlFieldName, ramlFieldName) {
17
+ // omit scalar fields that are mapped to RAML fields
18
+ if (ramlFieldName === undefined) {
19
+ return (0, deindent_1.default) `
20
+ case '${graphqlFieldName}': {
21
+ ${constants_2.SINK_IDENTIFIER}[${constants_2.FIELD_KEY_IDENTIFIER}] = ${constants_2.FIELD_DATA_IDENTIFIER};
22
+ break;
23
+ }
24
+ `;
25
+ }
26
+ return '';
27
+ }
28
+ function ingestNamedType(graphqlField, typeNode, ramlFieldName, importContext, normalizableTypeMap) {
16
29
  const graphqlTypeName = (0, utils_1.resolveTypeName)(typeNode);
17
30
  const { importGraphQLArtifact } = importContext;
18
31
  const isScalar = normalizableTypeMap[graphqlTypeName] === undefined;
19
- const fieldName = field.name.value;
32
+ const graphqlFieldName = graphqlField.name.value;
20
33
  if (isScalar) {
21
- return generateIngestScalarField(fieldName);
34
+ return generateIngestScalarField(graphqlFieldName, ramlFieldName);
22
35
  }
23
36
  const typeNameIngestImport = importGraphQLArtifact('types', graphqlTypeName, constants_2.TYPE_INGEST_IDENTIFIER);
24
- const fieldStateIdentifier = `${fieldName}State`;
37
+ const graphqlStateInterface = importGraphQLArtifact('types', constants_2.TYPE_UTIL_IDENTIFIER, constants_2.GRAPHQL_INGEST_STATE_INTERFACE_IDENTIFIER);
38
+ const typeNamePartialInterfaceImport = importGraphQLArtifact('types', graphqlTypeName, interface_1.PARTIAL_INTERFACE_IDENTIFIER);
39
+ const fieldStateIdentifier = `${graphqlFieldName}State`;
25
40
  return (0, deindent_1.default) `
26
- case '${fieldName}': {
41
+ case '${graphqlFieldName}': {
27
42
  const ${fieldStateIdentifier} = {
28
43
  ...state,
29
44
  path: {
30
45
  parent: null,
31
- propertyName: ${constants_2.FIELD_KEY_IDENTIFIER},
46
+ propertyName: null,
32
47
  fullPath: key + '__' + ${constants_2.FIELD_KEY_IDENTIFIER}
33
48
  },
34
49
  data: ${constants_2.FIELD_DATA_IDENTIFIER},
35
50
  };
36
- dataSink[${constants_2.FIELD_KEY_IDENTIFIER}] = ${typeNameIngestImport}(
51
+ ${constants_2.SINK_IDENTIFIER}[${constants_2.FIELD_KEY_IDENTIFIER}] = ${typeNameIngestImport}(
37
52
  ${constants_2.REQUESTED_FIELD_IDENTIFIER},
38
- ${fieldStateIdentifier}
53
+ ${fieldStateIdentifier} as ${graphqlStateInterface}<${typeNamePartialInterfaceImport}>
39
54
  ) as any;
40
55
  break;
41
56
  }
42
57
  `;
43
58
  }
44
59
  exports.ingestNamedType = ingestNamedType;
45
- function ingestListType(field, typeNode, importContext, normalizableTypeMap) {
60
+ function ingestListType(graphqlField, typeNode, ramlFieldName, importContext, normalizableTypeMap) {
46
61
  const { importGraphQLArtifact } = importContext;
47
- const fieldName = field.name.value;
62
+ const graphqlFieldName = graphqlField.name.value;
48
63
  const graphqlTypeName = (0, utils_1.resolveTypeName)(typeNode);
49
- const fullPathIdentifier = `fullPath__${fieldName}`;
50
- const typeDefinition = normalizableTypeMap[graphqlTypeName];
51
- const collectionIdentifier = `${fieldName}__items`;
64
+ const fullPathIdentifier = `fullPath__${graphqlFieldName}`;
65
+ const collectionIdentifier = `${graphqlFieldName}__items`;
52
66
  // Non-normalizable types
53
- if (typeDefinition === undefined) {
54
- return generateIngestScalarField(fieldName);
67
+ const isScalar = normalizableTypeMap[graphqlTypeName] === undefined;
68
+ if (isScalar) {
69
+ return generateIngestScalarField(graphqlFieldName, ramlFieldName);
55
70
  }
56
71
  const typeNameIngestImport = importGraphQLArtifact('types', graphqlTypeName, constants_2.TYPE_INGEST_IDENTIFIER);
72
+ const graphqlStateInterface = importGraphQLArtifact('types', constants_2.TYPE_UTIL_IDENTIFIER, constants_2.GRAPHQL_INGEST_STATE_INTERFACE_IDENTIFIER);
73
+ const typeNamePartialInterfaceImport = importGraphQLArtifact('types', graphqlTypeName, interface_1.PARTIAL_INTERFACE_IDENTIFIER);
57
74
  return (0, deindent_1.default) `
58
- case '${fieldName}': {
75
+ case '${graphqlFieldName}': {
59
76
  const ${collectionIdentifier}: ${constants_1.LUVIO_STORE_LINK_IMPORT}[] = [];
60
77
  const ${fullPathIdentifier} = \`\${key}__\${${constants_2.FIELD_KEY_IDENTIFIER}}\`;
61
78
  for(let i = 0, len = ${constants_2.FIELD_DATA_IDENTIFIER}.length; i < len; i++) {
@@ -65,58 +82,47 @@ function ingestListType(field, typeNode, importContext, normalizableTypeMap) {
65
82
  ...state,
66
83
  path: {
67
84
  parent: null,
68
- propertyName: i,
85
+ propertyName: null,
69
86
  fullPath: ${fullPathIdentifier} + i
70
87
  },
71
88
  data: item,
72
89
  };
73
90
  ${collectionIdentifier}[i] = ${typeNameIngestImport}(
74
91
  ${constants_2.REQUESTED_FIELD_IDENTIFIER},
75
- itemState
76
- )
92
+ itemState as ${graphqlStateInterface}<${typeNamePartialInterfaceImport}>
93
+ ) as any;
77
94
  }
78
- dataSink[${constants_2.FIELD_KEY_IDENTIFIER}] = ${collectionIdentifier};
95
+ ${constants_2.SINK_IDENTIFIER}[${constants_2.FIELD_KEY_IDENTIFIER}] = ${collectionIdentifier};
79
96
  break;
80
97
  }
81
98
  `;
82
99
  }
83
100
  exports.ingestListType = ingestListType;
84
- function generateIngestScalarField(fieldName) {
85
- return (0, deindent_1.default) `
86
- case '${fieldName}': {
87
- dataSink[${constants_2.FIELD_KEY_IDENTIFIER}] = ${constants_2.FIELD_DATA_IDENTIFIER};
88
- break;
89
- }
90
- `;
91
- }
92
- function ingestType(field, typeNode, importContext, normalizableTypeMap) {
93
- if (field === undefined) {
101
+ function ingestType(graphqlField, typeNode, ramlFieldName, importContext, normalizableTypeMap) {
102
+ if (graphqlField === undefined) {
94
103
  return '';
95
104
  }
96
105
  switch (typeNode.kind) {
97
106
  case 'NamedType':
98
- return ingestNamedType(field, typeNode, importContext, normalizableTypeMap);
107
+ return ingestNamedType(graphqlField, typeNode, ramlFieldName, importContext, normalizableTypeMap);
99
108
  case 'ListType':
100
- return ingestListType(field, typeNode, importContext, normalizableTypeMap);
109
+ return ingestListType(graphqlField, typeNode, ramlFieldName, importContext, normalizableTypeMap);
101
110
  default:
102
- return ingestType(field, typeNode.type, importContext, normalizableTypeMap);
111
+ return ingestType(graphqlField, typeNode.type, ramlFieldName, importContext, normalizableTypeMap);
103
112
  }
104
113
  }
105
114
  exports.ingestType = ingestType;
106
115
  function generateObjectTypeIngest(graphqlDsl, graphqlTypeName, importContext, def, normalizableTypeMap) {
107
- const { typeNameToExtensions } = graphqlDsl;
108
- const fields = (0, types_1.getObjectFields)(def);
109
- const fieldIngestStatements = fields
110
- .filter((field) => field.type !== undefined)
111
- .map((field) => {
112
- // omit the fields that are mapped to RAML fields and delegate to RAML ingestion
113
- const graphqlFieldName = field.name.value;
116
+ const graphqlFields = (0, types_1.getObjectFields)(def);
117
+ const fieldIngestStatements = graphqlFields
118
+ .filter((graphqlField) => graphqlField.type !== undefined)
119
+ .map((graphqlField) => {
120
+ const { typeNameToExtensions } = graphqlDsl;
121
+ const graphqlFieldName = graphqlField.name.value;
114
122
  const ramlFieldName = (0, utils_2.getRamlFieldName)(typeNameToExtensions, graphqlTypeName, graphqlFieldName);
115
- if (ramlFieldName !== undefined) {
116
- return '';
117
- }
118
- return ingestType(field, field.type, importContext, normalizableTypeMap);
119
- });
123
+ return ingestType(graphqlField, graphqlField.type, ramlFieldName, importContext, normalizableTypeMap);
124
+ })
125
+ .filter((fieldIngestStatement) => fieldIngestStatement !== '');
120
126
  const eachFieldHandling = fieldIngestStatements.join('\n');
121
127
  const ingestStatements = [
122
128
  getRequestedFieldsStatement(importContext),
@@ -146,69 +152,19 @@ function iterateThroughResponseKeys(importContext, individualFieldIngestBlock) {
146
152
  }
147
153
  const ${constants_2.FIELD_KEY_IDENTIFIER} = ${getFieldKeyImport}(${constants_2.REQUESTED_FIELD_IDENTIFIER}, state.variables);
148
154
 
149
- switch( ${constants_2.REQUESTED_FIELD_IDENTIFIER}.name.value) {
155
+ switch(${constants_2.REQUESTED_FIELD_IDENTIFIER}.name.value) {
150
156
  ${individualFieldIngestBlock}
151
157
  }
152
158
  }
153
159
  `;
154
160
  }
155
- function generateRamlIngestDelegation(graphqlDsl, graphqlTypeName, importContext, def, modelInfo, graphqlStateInterface) {
156
- // get the target RAML type ingest function
157
- const { typeNameToExtensions } = graphqlDsl;
158
- const { importRamlArtifact } = importContext;
159
- const ramlTypeName = (0, utils_2.getRamlTypeName)(typeNameToExtensions, graphqlTypeName);
160
- if (ramlTypeName === undefined) {
161
- return '';
162
- }
163
- const ramlTypeId = (0, utils_2.getRamlTypeIdByName)(ramlTypeName, modelInfo);
164
- if (ramlTypeId === undefined) {
165
- return '';
166
- }
167
- const ramlIngest = importRamlArtifact(ramlTypeId, constants_2.TYPE_INGEST_IDENTIFIER);
168
- // get RAML mapping
169
- const graphqlFields = (0, types_1.getObjectFields)(def);
170
- const ramlIngestStatements = graphqlFields
171
- .filter((graphqlField) => graphqlField.type !== undefined)
172
- .map((graphqlField) => {
173
- const graphqlFieldName = graphqlField.name.value;
174
- const ramlFieldName = (0, utils_2.getRamlFieldName)(typeNameToExtensions, graphqlTypeName, graphqlFieldName);
175
- if (ramlFieldName === undefined) {
176
- return '';
177
- }
178
- return (0, deindent_1.default) `
179
- if (responseKey === "${graphqlFieldName}") {
180
- ramlSink["${ramlFieldName}"] = data["${graphqlFieldName}"];
181
- }
182
- `;
183
- });
184
- if (ramlIngestStatements.length === 0) {
185
- return '';
186
- }
187
- return (0, deindent_1.default) `
188
- export function convertGraphQLToRaml (state: ${graphqlStateInterface}<${interface_1.PARTIAL_INTERFACE_IDENTIFIER}>) {
189
- const { path, data, ${constants_1.LUVIO_IDENTIFIER}, ${constants_1.LUVIO_STORE_IDENTIFIER}, ${constants_2.TIMESTAMP_IDENTIFIER} } = state;
190
- const ramlSink = {};
191
- const responseKeys = Object.keys(data);
192
- for (const responseKey of responseKeys) {
193
- ${ramlIngestStatements.join('\n')}
194
- }
195
-
196
- // delegate type ingest to RAML ingest if the type is in RAML mapping
197
- if (Object.keys(ramlSink).length === 0) {
198
- return undefined;
199
- }
200
- const ramlTypeRef = ${ramlIngest}(ramlSink, path, ${constants_1.LUVIO_IDENTIFIER}, ${constants_1.LUVIO_STORE_IDENTIFIER}, ${constants_2.TIMESTAMP_IDENTIFIER});
201
- return ramlTypeRef;
202
- }
203
- `;
204
- }
205
161
  function generateIngest(graphqlDsl, graphqlTypeName, def, importContext, _metadata, modelInfo) {
206
162
  var _a;
207
163
  const { schema, typeNameToExtensions } = graphqlDsl;
208
- const { importGraphQLArtifact, importAdapterUtil } = importContext;
164
+ const { importGraphQLArtifact, importAdapterUtil, importRamlArtifact } = importContext;
209
165
  const normalizableTypeMap = (0, utils_1.getNormalizableTypeMap)(schema);
210
166
  const createLink = importGraphQLArtifact('types', constants_2.TYPE_UTIL_IDENTIFIER, constants_2.CREATE_LINK_IDENTIFIER);
211
- const graphqlStateInterface = importGraphQLArtifact('types', constants_2.TYPE_UTIL_IDENTIFIER, constants_2.GRAPHQL_STATE_INTERFACE_IDENTIFIER);
167
+ const graphqlStateInterface = importGraphQLArtifact('types', constants_2.TYPE_UTIL_IDENTIFIER, constants_2.GRAPHQL_INGEST_STATE_INTERFACE_IDENTIFIER);
212
168
  const keyPrefix = importAdapterUtil('keyPrefix');
213
169
  const ttl = (0, utils_2.isTypeExtensionDefined)(typeNameToExtensions, graphqlTypeName, 'ttl')
214
170
  ? 'TTL'
@@ -216,36 +172,46 @@ function generateIngest(graphqlDsl, graphqlTypeName, def, importContext, _metada
216
172
  const astNodeParamType = ((_a = schema.getQueryType()) === null || _a === void 0 ? void 0 : _a.name) === graphqlTypeName
217
173
  ? constants_1.LUVIO_GRAPHQL_OPERATION_DEFINITION_NODE_IMPORT
218
174
  : constants_1.LUVIO_GRAPHQL_FIELD_NODE_IMPORT;
219
- const converToRaml = generateRamlIngestDelegation(graphqlDsl, graphqlTypeName, importContext, def, modelInfo, graphqlStateInterface);
175
+ const converToRaml = (0, convert_1.generateRamlConversion)(graphqlDsl, graphqlTypeName, importContext, def, modelInfo, graphqlStateInterface, normalizableTypeMap);
176
+ let ramlIngest = undefined;
177
+ const ramlTypeName = (0, utils_2.getRamlTypeName)(typeNameToExtensions, graphqlTypeName);
178
+ if (ramlTypeName !== undefined) {
179
+ const ramlTypeId = (0, utils_2.getRamlTypeIdByName)(ramlTypeName, modelInfo);
180
+ if (ramlTypeId !== undefined) {
181
+ ramlIngest = importRamlArtifact(ramlTypeId, constants_2.TYPE_INGEST_IDENTIFIER);
182
+ }
183
+ }
220
184
  return (0, deindent_1.default) `
221
185
 
222
186
  ${converToRaml}
223
187
 
224
188
  export function ingest(astNode: ${astNodeParamType}, state: ${graphqlStateInterface}<${interface_1.PARTIAL_INTERFACE_IDENTIFIER}>) {
225
- const { path, ${constants_1.LUVIO_IDENTIFIER}, ${constants_1.LUVIO_STORE_IDENTIFIER}, ${constants_2.TIMESTAMP_IDENTIFIER} } = state;
226
- const data = state.data;
227
- const key = ${constants_2.KEY_BUILDER_IDENTIFIER}(path, data);
228
- const dataSink = <PartialInterface>({});
189
+ const { path, data, ${constants_1.LUVIO_IDENTIFIER}, ${constants_1.LUVIO_STORE_IDENTIFIER}, ${constants_2.TIMESTAMP_IDENTIFIER} } = state;
190
+ const key = ${constants_2.KEY_BUILDER_IDENTIFIER}(${constants_1.LUVIO_IDENTIFIER}, path, data);
191
+ const ${constants_2.SINK_IDENTIFIER}: Record<string,any> = {};
229
192
 
230
193
  // normalize fields
231
194
  ${generateObjectTypeIngest(graphqlDsl, graphqlTypeName, importContext, def, normalizableTypeMap)}
232
195
 
233
196
  // merge existing cache data and new request response data
234
- let mergedData;
197
+ let mergedData: Record<string,any>;
235
198
  const existingData = ${constants_1.LUVIO_STORE_IDENTIFIER}.readEntry<${interface_1.PARTIAL_INTERFACE_IDENTIFIER}>(key);
236
- if (existingData !== undefined && existingData.__type !== "error") {
237
- mergedData = mergeData(existingData as PartialInterface, dataSink);
199
+ if (existingData !== undefined && existingData !== null && existingData.__type !== "error") {
200
+ mergedData = mergeData(existingData as ${interface_1.PARTIAL_INTERFACE_IDENTIFIER}, ${constants_2.SINK_IDENTIFIER} as ${interface_1.PARTIAL_INTERFACE_IDENTIFIER});
238
201
  }
239
202
  else {
240
- mergedData = {data: dataSink};
203
+ mergedData = {data: ${constants_2.SINK_IDENTIFIER}};
241
204
  }
242
205
 
243
206
  ${converToRaml === ''
244
207
  ? ''
245
208
  : (0, deindent_1.default) `
246
- // partially ingest with RAML
247
- const ramlTypeRef = convertGraphQLToRaml(state);
248
- if (ramlTypeRef !== undefined) {
209
+ // delegate type ingest to RAML ingest if the type is in RAML mapping
210
+ const ramlSink = convertGraphQLToRaml(astNode, state);
211
+ if (ramlSink !== undefined) {
212
+
213
+ // partially ingest with RAML
214
+ const ramlTypeRef = ${ramlIngest}(ramlSink, path, ${constants_1.LUVIO_IDENTIFIER}, ${constants_1.LUVIO_STORE_IDENTIFIER}, ${constants_2.TIMESTAMP_IDENTIFIER});
249
215
  mergedData["__link"] = ramlTypeRef;
250
216
  }`}
251
217