@aws-amplify/data-schema 1.3.10 → 1.4.0

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 (102) hide show
  1. package/dist/cjs/ModelType.js +5 -0
  2. package/dist/cjs/ModelType.js.map +1 -1
  3. package/dist/cjs/SchemaProcessor.js +58 -1
  4. package/dist/cjs/SchemaProcessor.js.map +1 -1
  5. package/dist/cjs/runtime/addSchemaToClient.js +1 -0
  6. package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
  7. package/dist/cjs/runtime/addSchemaToClientWithInstance.js +1 -0
  8. package/dist/cjs/runtime/addSchemaToClientWithInstance.js.map +1 -1
  9. package/dist/cjs/runtime/internals/APIClient.js +63 -42
  10. package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
  11. package/dist/cjs/runtime/internals/cancellation.js +48 -0
  12. package/dist/cjs/runtime/internals/cancellation.js.map +1 -0
  13. package/dist/cjs/runtime/internals/clientUtils.js +45 -3
  14. package/dist/cjs/runtime/internals/clientUtils.js.map +1 -1
  15. package/dist/cjs/runtime/internals/index.js +3 -1
  16. package/dist/cjs/runtime/internals/index.js.map +1 -1
  17. package/dist/cjs/runtime/internals/operations/custom.js +91 -85
  18. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  19. package/dist/cjs/runtime/internals/operations/get.js +71 -65
  20. package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
  21. package/dist/cjs/runtime/internals/operations/indexQuery.js +66 -60
  22. package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
  23. package/dist/cjs/runtime/internals/operations/list.js +90 -84
  24. package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
  25. package/dist/cjs/runtime/internals/server/generateModelsProperty.js +3 -3
  26. package/dist/cjs/runtime/internals/server/generateModelsProperty.js.map +1 -1
  27. package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js +3 -3
  28. package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js.map +1 -1
  29. package/dist/cjs/runtime/utils/index.js +3 -1
  30. package/dist/cjs/runtime/utils/index.js.map +1 -1
  31. package/dist/cjs/runtime/utils/selfAwareAsync.js +40 -0
  32. package/dist/cjs/runtime/utils/selfAwareAsync.js.map +1 -0
  33. package/dist/esm/Authorization.d.ts +1 -1
  34. package/dist/esm/ClientSchema/Core/ClientModel.d.ts +20 -1
  35. package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +5 -1
  36. package/dist/esm/ModelType.d.ts +6 -0
  37. package/dist/esm/ModelType.mjs +5 -0
  38. package/dist/esm/ModelType.mjs.map +1 -1
  39. package/dist/esm/SchemaProcessor.mjs +58 -1
  40. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  41. package/dist/esm/runtime/addSchemaToClient.mjs +2 -0
  42. package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
  43. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs +2 -0
  44. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
  45. package/dist/esm/runtime/bridge-types.d.ts +2 -2
  46. package/dist/esm/runtime/client/index.d.ts +6 -6
  47. package/dist/esm/runtime/internals/APIClient.d.ts +2 -2
  48. package/dist/esm/runtime/internals/APIClient.mjs +64 -42
  49. package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
  50. package/dist/esm/runtime/internals/cancellation.d.ts +10 -0
  51. package/dist/esm/runtime/internals/cancellation.mjs +44 -0
  52. package/dist/esm/runtime/internals/cancellation.mjs.map +1 -0
  53. package/dist/esm/runtime/internals/clientUtils.d.ts +78 -1
  54. package/dist/esm/runtime/internals/clientUtils.mjs +45 -3
  55. package/dist/esm/runtime/internals/clientUtils.mjs.map +1 -1
  56. package/dist/esm/runtime/internals/index.d.ts +1 -0
  57. package/dist/esm/runtime/internals/index.mjs +1 -0
  58. package/dist/esm/runtime/internals/index.mjs.map +1 -1
  59. package/dist/esm/runtime/internals/operations/custom.d.ts +1 -1
  60. package/dist/esm/runtime/internals/operations/custom.mjs +91 -85
  61. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  62. package/dist/esm/runtime/internals/operations/get.d.ts +1 -1
  63. package/dist/esm/runtime/internals/operations/get.mjs +71 -65
  64. package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
  65. package/dist/esm/runtime/internals/operations/indexQuery.d.ts +1 -1
  66. package/dist/esm/runtime/internals/operations/indexQuery.mjs +66 -60
  67. package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
  68. package/dist/esm/runtime/internals/operations/list.d.ts +1 -1
  69. package/dist/esm/runtime/internals/operations/list.mjs +90 -84
  70. package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
  71. package/dist/esm/runtime/internals/server/generateModelsProperty.mjs +4 -4
  72. package/dist/esm/runtime/internals/server/generateModelsProperty.mjs.map +1 -1
  73. package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs +4 -4
  74. package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -1
  75. package/dist/esm/runtime/utils/index.d.ts +1 -0
  76. package/dist/esm/runtime/utils/index.mjs +1 -0
  77. package/dist/esm/runtime/utils/index.mjs.map +1 -1
  78. package/dist/esm/runtime/utils/selfAwareAsync.d.ts +19 -0
  79. package/dist/esm/runtime/utils/selfAwareAsync.mjs +37 -0
  80. package/dist/esm/runtime/utils/selfAwareAsync.mjs.map +1 -0
  81. package/dist/meta/cjs.tsbuildinfo +1 -1
  82. package/package.json +2 -2
  83. package/src/ClientSchema/Core/ClientModel.ts +29 -0
  84. package/src/ClientSchema/utilities/ResolveField.ts +26 -6
  85. package/src/ModelType.ts +31 -0
  86. package/src/SchemaProcessor.ts +77 -2
  87. package/src/runtime/addSchemaToClient.ts +2 -0
  88. package/src/runtime/addSchemaToClientWithInstance.ts +2 -0
  89. package/src/runtime/bridge-types.ts +2 -2
  90. package/src/runtime/client/index.ts +207 -184
  91. package/src/runtime/internals/APIClient.ts +67 -23
  92. package/src/runtime/internals/cancellation.ts +57 -0
  93. package/src/runtime/internals/clientUtils.ts +61 -1
  94. package/src/runtime/internals/index.ts +1 -0
  95. package/src/runtime/internals/operations/custom.ts +117 -109
  96. package/src/runtime/internals/operations/get.ts +111 -95
  97. package/src/runtime/internals/operations/indexQuery.ts +100 -94
  98. package/src/runtime/internals/operations/list.ts +132 -119
  99. package/src/runtime/internals/server/generateModelsProperty.ts +31 -28
  100. package/src/runtime/internals/utils/clientProperties/generateModelsProperty.ts +36 -33
  101. package/src/runtime/utils/index.ts +1 -0
  102. package/src/runtime/utils/selfAwareAsync.ts +39 -0
@@ -22,6 +22,8 @@ import {
22
22
  } from '../APIClient';
23
23
 
24
24
  import { handleListGraphQlError } from './utils';
25
+ import { selfAwareAsync } from '../../utils';
26
+ import { extendCancellability } from '../cancellation';
25
27
 
26
28
  export interface IndexMeta {
27
29
  queryField: string;
@@ -37,7 +39,7 @@ export function indexQueryFactory(
37
39
  getInternals: ClientInternalsGetter,
38
40
  context = false,
39
41
  ) {
40
- const indexQueryWithContext = async (
42
+ const indexQueryWithContext = (
41
43
  contextSpec: AmplifyServer.ContextSpec,
42
44
  args: QueryArgs,
43
45
  options?: ListArgs,
@@ -56,7 +58,7 @@ export function indexQueryFactory(
56
58
  );
57
59
  };
58
60
 
59
- const indexQuery = async (args: QueryArgs, options?: ListArgs) => {
61
+ const indexQuery = (args: QueryArgs, options?: ListArgs) => {
60
62
  return _indexQuery(
61
63
  client,
62
64
  modelIntrospection,
@@ -104,7 +106,7 @@ function processGraphQlResponse(
104
106
  };
105
107
  }
106
108
 
107
- async function _indexQuery(
109
+ function _indexQuery(
108
110
  client: BaseClient,
109
111
  modelIntrospection: ModelIntrospectionSchema,
110
112
  model: SchemaModel,
@@ -113,108 +115,112 @@ async function _indexQuery(
113
115
  args?: ListArgs & AuthModeParams,
114
116
  contextSpec?: AmplifyServer.ContextSpec,
115
117
  ) {
116
- const { name } = model;
117
-
118
- const query = generateGraphQLDocument(
119
- modelIntrospection,
120
- name,
121
- 'INDEX_QUERY',
122
- args,
123
- indexMeta,
124
- );
125
- const variables = buildGraphQLVariables(
126
- model,
127
- 'INDEX_QUERY',
128
- args,
129
- modelIntrospection,
130
- indexMeta,
131
- );
132
-
133
- const auth = authModeParams(client, getInternals, args);
134
-
135
- const modelInitializer = (flattenedResult: any[]) =>
136
- initializeModel(
137
- client,
118
+ return selfAwareAsync(async (resultPromise) => {
119
+ const { name } = model;
120
+
121
+ const query = generateGraphQLDocument(
122
+ modelIntrospection,
138
123
  name,
139
- flattenedResult,
124
+ 'INDEX_QUERY',
125
+ args,
126
+ indexMeta,
127
+ );
128
+ const variables = buildGraphQLVariables(
129
+ model,
130
+ 'INDEX_QUERY',
131
+ args,
140
132
  modelIntrospection,
141
- auth.authMode,
142
- auth.authToken,
143
- !!contextSpec,
133
+ indexMeta,
144
134
  );
145
135
 
146
- try {
147
- const headers = getCustomHeaders(client, getInternals, args?.headers);
136
+ const auth = authModeParams(client, getInternals, args);
148
137
 
149
- const graphQlParams = {
150
- ...auth,
151
- query,
152
- variables,
153
- };
138
+ const modelInitializer = (flattenedResult: any[]) =>
139
+ initializeModel(
140
+ client,
141
+ name,
142
+ flattenedResult,
143
+ modelIntrospection,
144
+ auth.authMode,
145
+ auth.authToken,
146
+ !!contextSpec,
147
+ );
154
148
 
155
- const requestArgs: [any, any] = [graphQlParams, headers];
149
+ try {
150
+ const headers = getCustomHeaders(client, getInternals, args?.headers);
156
151
 
157
- if (contextSpec !== undefined) {
158
- requestArgs.unshift(contextSpec);
159
- }
152
+ const graphQlParams = {
153
+ ...auth,
154
+ query,
155
+ variables,
156
+ };
160
157
 
161
- const response = (await (client as BaseClient).graphql(
162
- ...requestArgs,
163
- )) as GraphQLResult;
158
+ const requestArgs: [any, any] = [graphQlParams, headers];
164
159
 
165
- if (response.data !== undefined) {
166
- return processGraphQlResponse(
167
- modelIntrospection,
168
- name,
169
- response,
170
- args?.selectionSet,
171
- modelInitializer,
172
- );
173
- }
174
- } catch (error: any) {
175
- /**
176
- * The `data` type returned by `error` here could be:
177
- * 1) `null`
178
- * 2) an empty object
179
- * 3) "populated" but with a `null` value:
180
- * `data: { listByExampleId: null }`
181
- * 4) an actual record:
182
- * `data: { listByExampleId: items: [{ id: '1', ...etc } }]`
183
- */
184
- const { data, errors } = error;
185
-
186
- // `data` is not `null`, and is not an empty object:
187
- if (data !== undefined && Object.keys(data).length !== 0 && errors) {
188
- const [key] = Object.keys(data);
189
-
190
- if (data[key]?.items) {
191
- const flattenedResult = data[key]?.items.map(
192
- (value: Record<string, any>) =>
193
- flattenItems(modelIntrospection, name, value),
194
- );
160
+ if (contextSpec !== undefined) {
161
+ requestArgs.unshift(contextSpec);
162
+ }
195
163
 
196
- /**
197
- * Check exists since `flattenedResult` could be `null`.
198
- * if `flattenedResult` exists, result is an actual record.
199
- */
200
- if (flattenedResult) {
201
- return {
202
- data: args?.selectionSet
203
- ? flattenedResult
204
- : modelInitializer(flattenedResult),
205
- nextToken: data[key]?.nextToken,
206
- };
207
- }
164
+ const basePromise = (client as BaseClient).graphql(
165
+ ...requestArgs,
166
+ ) as Promise<GraphQLResult>;
167
+ const extendedPromise = extendCancellability(basePromise, resultPromise);
168
+ const response = await extendedPromise;
169
+
170
+ if (response.data !== undefined) {
171
+ return processGraphQlResponse(
172
+ modelIntrospection,
173
+ name,
174
+ response,
175
+ args?.selectionSet,
176
+ modelInitializer,
177
+ );
208
178
  }
179
+ } catch (error: any) {
180
+ /**
181
+ * The `data` type returned by `error` here could be:
182
+ * 1) `null`
183
+ * 2) an empty object
184
+ * 3) "populated" but with a `null` value:
185
+ * `data: { listByExampleId: null }`
186
+ * 4) an actual record:
187
+ * `data: { listByExampleId: items: [{ id: '1', ...etc } }]`
188
+ */
189
+ const { data, errors } = error;
190
+
191
+ // `data` is not `null`, and is not an empty object:
192
+ if (data !== undefined && Object.keys(data).length !== 0 && errors) {
193
+ const [key] = Object.keys(data);
194
+
195
+ if (data[key]?.items) {
196
+ const flattenedResult = data[key]?.items.map(
197
+ (value: Record<string, any>) =>
198
+ flattenItems(modelIntrospection, name, value),
199
+ );
200
+
201
+ /**
202
+ * Check exists since `flattenedResult` could be `null`.
203
+ * if `flattenedResult` exists, result is an actual record.
204
+ */
205
+ if (flattenedResult) {
206
+ return {
207
+ data: args?.selectionSet
208
+ ? flattenedResult
209
+ : modelInitializer(flattenedResult),
210
+ nextToken: data[key]?.nextToken,
211
+ };
212
+ }
213
+ }
209
214
 
210
- // response is of type `data: { listByExampleId: null }`
211
- return {
212
- data: data[key],
213
- nextToken: data[key]?.nextToken,
214
- };
215
- } else {
216
- // `data` is `null` or an empty object:
217
- return handleListGraphQlError(error);
215
+ // response is of type `data: { listByExampleId: null }`
216
+ return {
217
+ data: data[key],
218
+ nextToken: data[key]?.nextToken,
219
+ };
220
+ } else {
221
+ // `data` is `null` or an empty object:
222
+ return handleListGraphQlError(error);
223
+ }
218
224
  }
219
- }
225
+ });
220
226
  }
@@ -23,6 +23,9 @@ import {
23
23
  } from '../APIClient';
24
24
 
25
25
  import { handleListGraphQlError } from './utils';
26
+ import { selfAwareAsync } from '../../utils';
27
+
28
+ import { extendCancellability } from '../cancellation';
26
29
 
27
30
  export function listFactory(
28
31
  client: BaseClient,
@@ -31,7 +34,7 @@ export function listFactory(
31
34
  getInternals: ClientInternalsGetter,
32
35
  context = false,
33
36
  ) {
34
- const listWithContext = async (
37
+ const listWithContext = (
35
38
  contextSpec: AmplifyServer.ContextSpec,
36
39
  args?: ListArgs,
37
40
  ) => {
@@ -45,14 +48,14 @@ export function listFactory(
45
48
  );
46
49
  };
47
50
 
48
- const list = async (args?: Record<string, any>) => {
51
+ const list = (args?: Record<string, any>) => {
49
52
  return _list(client, modelIntrospection, model, getInternals, args);
50
53
  };
51
54
 
52
55
  return context ? listWithContext : list;
53
56
  }
54
57
 
55
- async function _list(
58
+ function _list(
56
59
  client: BaseClient,
57
60
  modelIntrospection: ModelIntrospectionSchema,
58
61
  model: SchemaModel,
@@ -60,118 +63,65 @@ async function _list(
60
63
  args?: ListArgs & AuthModeParams,
61
64
  contextSpec?: AmplifyServer.ContextSpec,
62
65
  ) {
63
- const { name } = model;
64
-
65
- const query = generateGraphQLDocument(modelIntrospection, name, 'LIST', args);
66
- const variables = buildGraphQLVariables(
67
- model,
68
- 'LIST',
69
- args,
70
- modelIntrospection,
71
- );
72
-
73
- const auth = authModeParams(client, getInternals, args);
74
-
75
- try {
76
- const headers = getCustomHeaders(client, getInternals, args?.headers);
77
-
78
- const { data, extensions } = contextSpec
79
- ? ((await (client as BaseSSRClient).graphql(
80
- contextSpec,
81
- {
82
- ...auth,
83
- query,
84
- variables,
85
- },
86
- headers,
87
- )) as GraphQLResult)
88
- : ((await (client as BaseBrowserClient).graphql(
89
- {
90
- ...auth,
91
- query,
92
- variables,
93
- },
94
- headers,
95
- )) as GraphQLResult);
96
-
97
- // flatten response
98
- if (data !== undefined) {
99
- const [key] = Object.keys(data);
100
-
101
- if (data[key].items) {
102
- const flattenedResult = data[key].items.map(
103
- (value: Record<string, any>) =>
104
- flattenItems(modelIntrospection, name, value),
105
- );
106
-
107
- // don't init if custom selection set
108
- if (args?.selectionSet) {
109
- return {
110
- data: flattenedResult,
111
- nextToken: data[key].nextToken,
112
- extensions,
113
- };
114
- } else {
115
- const initialized = initializeModel(
116
- client,
117
- name,
118
- flattenedResult,
119
- modelIntrospection,
120
- auth.authMode,
121
- auth.authToken,
122
- !!contextSpec,
123
- );
66
+ return selfAwareAsync(async (resultPromise) => {
67
+ const { name } = model;
124
68
 
125
- return {
126
- data: initialized,
127
- nextToken: data[key].nextToken,
128
- extensions,
129
- };
130
- }
131
- }
69
+ const query = generateGraphQLDocument(
70
+ modelIntrospection,
71
+ name,
72
+ 'LIST',
73
+ args,
74
+ );
75
+ const variables = buildGraphQLVariables(
76
+ model,
77
+ 'LIST',
78
+ args,
79
+ modelIntrospection,
80
+ );
81
+
82
+ const auth = authModeParams(client, getInternals, args);
83
+
84
+ try {
85
+ const headers = getCustomHeaders(client, getInternals, args?.headers);
86
+
87
+ const basePromise = contextSpec
88
+ ? ((client as BaseSSRClient).graphql(
89
+ contextSpec,
90
+ {
91
+ ...auth,
92
+ query,
93
+ variables,
94
+ },
95
+ headers,
96
+ ) as Promise<GraphQLResult>)
97
+ : ((client as BaseBrowserClient).graphql(
98
+ {
99
+ ...auth,
100
+ query,
101
+ variables,
102
+ },
103
+ headers,
104
+ ) as Promise<GraphQLResult>);
105
+
106
+ const extendedPromise = extendCancellability(basePromise, resultPromise);
107
+ const { data, extensions } = await extendedPromise;
108
+
109
+ // flatten response
110
+ if (data !== undefined) {
111
+ const [key] = Object.keys(data);
112
+
113
+ if (data[key].items) {
114
+ const flattenedResult = data[key].items.map(
115
+ (value: Record<string, any>) =>
116
+ flattenItems(modelIntrospection, name, value),
117
+ );
132
118
 
133
- return {
134
- data: data[key],
135
- nextToken: data[key].nextToken,
136
- extensions,
137
- };
138
- }
139
- } catch (error: any) {
140
- /**
141
- * The `data` type returned by `error` here could be:
142
- * 1) `null`
143
- * 2) an empty object
144
- * 3) "populated" but with a `null` value `data: { listPosts: null }`
145
- * 4) actual records `data: { listPosts: items: [{ id: '1', ...etc }] }`
146
- */
147
- const { data, errors } = error;
148
-
149
- // `data` is not `null`, and is not an empty object:
150
- if (
151
- data !== undefined &&
152
- data !== null &&
153
- Object.keys(data).length !== 0 &&
154
- errors
155
- ) {
156
- const [key] = Object.keys(data);
157
-
158
- if (data[key]?.items) {
159
- const flattenedResult = data[key].items.map(
160
- (value: Record<string, any>) =>
161
- flattenItems(modelIntrospection, name, value),
162
- );
163
-
164
- /**
165
- * Check exists since `flattenedResult` could be `null`.
166
- * if `flattenedResult` exists, result is an actual record.
167
- */
168
- if (flattenedResult) {
169
119
  // don't init if custom selection set
170
120
  if (args?.selectionSet) {
171
121
  return {
172
122
  data: flattenedResult,
173
- nextToken: data[key]?.nextToken,
174
- errors,
123
+ nextToken: data[key].nextToken,
124
+ extensions,
175
125
  };
176
126
  } else {
177
127
  const initialized = initializeModel(
@@ -184,27 +134,90 @@ async function _list(
184
134
  !!contextSpec,
185
135
  );
186
136
 
187
- // data is full record w/out selection set:
188
137
  return {
189
138
  data: initialized,
190
- nextToken: data[key]?.nextToken,
191
- errors,
139
+ nextToken: data[key].nextToken,
140
+ extensions,
192
141
  };
193
142
  }
194
143
  }
195
144
 
196
145
  return {
197
146
  data: data[key],
198
- nextToken: data[key]?.nextToken,
199
- errors,
147
+ nextToken: data[key].nextToken,
148
+ extensions,
200
149
  };
150
+ }
151
+ } catch (error: any) {
152
+ /**
153
+ * The `data` type returned by `error` here could be:
154
+ * 1) `null`
155
+ * 2) an empty object
156
+ * 3) "populated" but with a `null` value `data: { listPosts: null }`
157
+ * 4) actual records `data: { listPosts: items: [{ id: '1', ...etc }] }`
158
+ */
159
+ const { data, errors } = error;
160
+
161
+ // `data` is not `null`, and is not an empty object:
162
+ if (
163
+ data !== undefined &&
164
+ data !== null &&
165
+ Object.keys(data).length !== 0 &&
166
+ errors
167
+ ) {
168
+ const [key] = Object.keys(data);
169
+
170
+ if (data[key]?.items) {
171
+ const flattenedResult = data[key].items.map(
172
+ (value: Record<string, any>) =>
173
+ flattenItems(modelIntrospection, name, value),
174
+ );
175
+
176
+ /**
177
+ * Check exists since `flattenedResult` could be `null`.
178
+ * if `flattenedResult` exists, result is an actual record.
179
+ */
180
+ if (flattenedResult) {
181
+ // don't init if custom selection set
182
+ if (args?.selectionSet) {
183
+ return {
184
+ data: flattenedResult,
185
+ nextToken: data[key]?.nextToken,
186
+ errors,
187
+ };
188
+ } else {
189
+ const initialized = initializeModel(
190
+ client,
191
+ name,
192
+ flattenedResult,
193
+ modelIntrospection,
194
+ auth.authMode,
195
+ auth.authToken,
196
+ !!contextSpec,
197
+ );
198
+
199
+ // data is full record w/out selection set:
200
+ return {
201
+ data: initialized,
202
+ nextToken: data[key]?.nextToken,
203
+ errors,
204
+ };
205
+ }
206
+ }
207
+
208
+ return {
209
+ data: data[key],
210
+ nextToken: data[key]?.nextToken,
211
+ errors,
212
+ };
213
+ } else {
214
+ // response is of type `data: { getPost: null }`)
215
+ return handleListGraphQlError(error);
216
+ }
201
217
  } else {
202
- // response is of type `data: { getPost: null }`)
218
+ // `data` is `null` or an empty object:
203
219
  return handleListGraphQlError(error);
204
220
  }
205
- } else {
206
- // `data` is `null` or an empty object:
207
- return handleListGraphQlError(error);
208
221
  }
209
- }
222
+ });
210
223
  }
@@ -8,11 +8,14 @@ import {
8
8
  ServerClientGenerationParams,
9
9
  } from '../../bridge-types';
10
10
 
11
- import { ModelOperation, graphQLOperationsInfo } from '../APIClient';
11
+ import { ModelOperation } from '../APIClient';
12
12
  import { listFactory } from '../operations/list';
13
13
  import { indexQueryFactory } from '../operations/indexQuery';
14
14
  import { getFactory } from '../operations/get';
15
- import { getSecondaryIndexesFromSchemaModel } from '../clientUtils';
15
+ import {
16
+ getSecondaryIndexesFromSchemaModel,
17
+ excludeDisabledOps,
18
+ } from '../clientUtils';
16
19
 
17
20
  export function generateModelsProperty<T extends Record<any, any> = never>(
18
21
  client: BaseClient,
@@ -42,40 +45,40 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
42
45
  'ONCREATE',
43
46
  'ONUPDATE',
44
47
  'ONDELETE',
45
- 'OBSERVE_QUERY',
48
+ 'OBSERVEQUERY',
46
49
  ];
47
50
 
48
51
  for (const model of Object.values(modelIntrospection.models)) {
49
52
  const { name } = model;
50
53
  models[name] = {} as Record<string, any>;
51
54
 
52
- Object.entries(graphQLOperationsInfo).forEach(
53
- ([key, { operationPrefix }]) => {
54
- const operation = key as ModelOperation;
55
+ const enabledModelOps = excludeDisabledOps(modelIntrospection, name);
56
+
57
+ Object.entries(enabledModelOps).forEach(([key, { operationPrefix }]) => {
58
+ const operation = key as ModelOperation;
55
59
 
56
- // subscriptions are not supported in SSR
57
- if (SSR_UNSUPORTED_OPS.includes(operation)) return;
60
+ // subscriptions are not supported in SSR
61
+ if (SSR_UNSUPORTED_OPS.includes(operation)) return;
58
62
 
59
- if (operation === 'LIST') {
60
- models[name][operationPrefix] = listFactory(
61
- client,
62
- modelIntrospection,
63
- model,
64
- getInternals,
65
- useContext,
66
- );
67
- } else {
68
- models[name][operationPrefix] = getFactory(
69
- client,
70
- modelIntrospection,
71
- model,
72
- operation,
73
- getInternals,
74
- useContext,
75
- );
76
- }
77
- },
78
- );
63
+ if (operation === 'LIST') {
64
+ models[name][operationPrefix] = listFactory(
65
+ client,
66
+ modelIntrospection,
67
+ model,
68
+ getInternals,
69
+ useContext,
70
+ );
71
+ } else {
72
+ models[name][operationPrefix] = getFactory(
73
+ client,
74
+ modelIntrospection,
75
+ model,
76
+ operation,
77
+ getInternals,
78
+ useContext,
79
+ );
80
+ }
81
+ });
79
82
 
80
83
  const secondaryIdxs = getSecondaryIndexesFromSchemaModel(model);
81
84