@aws-amplify/api-graphql 4.0.1-unstable.cfbde4c.0 → 4.0.2-unstable.b778a9e.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.
- package/{lib → dist/cjs}/GraphQLAPI.js +8 -4
- package/dist/cjs/GraphQLAPI.js.map +1 -0
- package/{lib → dist/cjs}/Providers/AWSAppSyncRealTimeProvider/index.js +11 -8
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
- package/{lib → dist/cjs}/Providers/constants.js +8 -8
- package/dist/cjs/Providers/constants.js.map +1 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internals/APIClient.js +503 -0
- package/dist/cjs/internals/APIClient.js.map +1 -0
- package/{lib → dist/cjs}/internals/InternalGraphQLAPI.js +19 -19
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -0
- package/dist/cjs/internals/generateClient.js +33 -0
- package/dist/cjs/internals/generateClient.js.map +1 -0
- package/dist/cjs/internals/generateModelsProperty.js +43 -0
- package/dist/cjs/internals/generateModelsProperty.js.map +1 -0
- package/dist/cjs/internals/index.js +16 -0
- package/dist/cjs/internals/index.js.map +1 -0
- package/dist/cjs/internals/operations/get.js +61 -0
- package/dist/cjs/internals/operations/get.js.map +1 -0
- package/dist/cjs/internals/operations/list.js +73 -0
- package/dist/cjs/internals/operations/list.js.map +1 -0
- package/dist/cjs/internals/operations/observeQuery.js +121 -0
- package/dist/cjs/internals/operations/observeQuery.js.map +1 -0
- package/dist/cjs/internals/operations/subscription.js +29 -0
- package/dist/cjs/internals/operations/subscription.js.map +1 -0
- package/dist/cjs/internals/server/generateClient.js +32 -0
- package/dist/cjs/internals/server/generateClient.js.map +1 -0
- package/dist/cjs/internals/server/generateModelsProperty.js +47 -0
- package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -0
- package/dist/cjs/internals/server/index.js +9 -0
- package/dist/cjs/internals/server/index.js.map +1 -0
- package/dist/cjs/internals/types.js +4 -0
- package/dist/cjs/internals/types.js.map +1 -0
- package/{lib → dist/cjs}/internals/v6.js +4 -1
- package/dist/cjs/internals/v6.js.map +1 -0
- package/{lib → dist/cjs}/types/PubSub.js +6 -6
- package/dist/cjs/types/PubSub.js.map +1 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/{lib → dist/cjs}/utils/ConnectionStateMonitor.js +8 -5
- package/dist/cjs/utils/ConnectionStateMonitor.js.map +1 -0
- package/{lib → dist/cjs}/utils/ReachabilityMonitor/index.js +6 -2
- package/dist/cjs/utils/ReachabilityMonitor/index.js.map +1 -0
- package/{lib → dist/cjs}/utils/ReachabilityMonitor/index.native.js +6 -2
- package/dist/cjs/utils/ReachabilityMonitor/index.native.js.map +1 -0
- package/{lib → dist/cjs}/utils/ReconnectionMonitor.js +4 -1
- package/dist/cjs/utils/ReconnectionMonitor.js.map +1 -0
- package/{lib → dist/cjs}/utils/errors/APIError.js +4 -1
- package/dist/cjs/utils/errors/APIError.js.map +1 -0
- package/{lib → dist/cjs}/utils/errors/assertValidationError.js +4 -1
- package/dist/cjs/utils/errors/assertValidationError.js.map +1 -0
- package/dist/cjs/utils/errors/index.js +14 -0
- package/dist/cjs/utils/errors/index.js.map +1 -0
- package/{lib → dist/cjs}/utils/errors/validation.js +4 -1
- package/dist/cjs/utils/errors/validation.js.map +1 -0
- package/dist/cjs/utils/findIndexByFields.js +25 -0
- package/dist/cjs/utils/findIndexByFields.js.map +1 -0
- package/dist/cjs/utils/index.js +15 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/{lib → dist/cjs}/utils/resolveConfig.js +7 -3
- package/dist/cjs/utils/resolveConfig.js.map +1 -0
- package/{lib-esm → dist/cjs}/utils/resolveLibraryOptions.js +7 -1
- package/dist/cjs/utils/resolveLibraryOptions.js.map +1 -0
- package/dist/cjs/utils/resolveOwnerFields.js +42 -0
- package/dist/cjs/utils/resolveOwnerFields.js.map +1 -0
- package/dist/cjs/utils/resolvePKFields.js +17 -0
- package/dist/cjs/utils/resolvePKFields.js.map +1 -0
- package/{lib-esm → dist/esm}/GraphQLAPI.d.ts +2 -2
- package/{lib-esm/GraphQLAPI.js → dist/esm/GraphQLAPI.mjs} +8 -4
- package/dist/esm/GraphQLAPI.mjs.map +1 -0
- package/{lib → dist/esm}/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/{lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js → dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs} +13 -9
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -0
- package/{lib-esm/Providers/constants.js → dist/esm/Providers/constants.mjs} +18 -14
- package/dist/esm/Providers/constants.mjs.map +1 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/internals/APIClient.d.ts +121 -0
- package/dist/esm/internals/APIClient.mjs +493 -0
- package/dist/esm/internals/APIClient.mjs.map +1 -0
- package/{lib → dist/esm}/internals/InternalGraphQLAPI.d.ts +1 -1
- package/{lib-esm/internals/InternalGraphQLAPI.js → dist/esm/internals/InternalGraphQLAPI.mjs} +20 -19
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -0
- package/dist/esm/internals/generateClient.d.ts +12 -0
- package/dist/esm/internals/generateClient.mjs +31 -0
- package/dist/esm/internals/generateClient.mjs.map +1 -0
- package/dist/esm/internals/generateModelsProperty.d.ts +4 -0
- package/dist/esm/internals/generateModelsProperty.mjs +41 -0
- package/dist/esm/internals/generateModelsProperty.mjs.map +1 -0
- package/{lib → dist/esm}/internals/index.d.ts +1 -0
- package/dist/esm/internals/index.mjs +4 -0
- package/dist/esm/internals/index.mjs.map +1 -0
- package/dist/esm/internals/operations/get.d.ts +2 -0
- package/dist/esm/internals/operations/get.mjs +59 -0
- package/dist/esm/internals/operations/get.mjs.map +1 -0
- package/dist/esm/internals/operations/list.d.ts +2 -0
- package/dist/esm/internals/operations/list.mjs +71 -0
- package/dist/esm/internals/operations/list.mjs.map +1 -0
- package/dist/esm/internals/operations/observeQuery.d.ts +2 -0
- package/dist/esm/internals/operations/observeQuery.mjs +122 -0
- package/dist/esm/internals/operations/observeQuery.mjs.map +1 -0
- package/dist/esm/internals/operations/subscription.d.ts +1 -0
- package/dist/esm/internals/operations/subscription.mjs +27 -0
- package/dist/esm/internals/operations/subscription.mjs.map +1 -0
- package/dist/esm/internals/server/generateClient.d.ts +11 -0
- package/dist/esm/internals/server/generateClient.mjs +34 -0
- package/dist/esm/internals/server/generateClient.mjs.map +1 -0
- package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -0
- package/dist/esm/internals/server/generateModelsProperty.mjs +45 -0
- package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -0
- package/dist/esm/internals/server/index.d.ts +1 -0
- package/dist/esm/internals/server/index.mjs +2 -0
- package/dist/esm/internals/server/index.mjs.map +1 -0
- package/dist/esm/internals/types.d.ts +17 -0
- package/dist/esm/internals/types.mjs +2 -0
- package/dist/esm/internals/types.mjs.map +1 -0
- package/{lib-esm/internals/v6.js → dist/esm/internals/v6.mjs} +9 -5
- package/dist/esm/internals/v6.mjs.map +1 -0
- package/{lib → dist/esm}/types/PubSub.d.ts +2 -2
- package/{lib-esm/types/PubSub.js → dist/esm/types/PubSub.mjs} +5 -2
- package/dist/esm/types/PubSub.mjs.map +1 -0
- package/{lib-esm → dist/esm}/types/index.d.ts +46 -26
- package/{lib-esm/types/index.js → dist/esm/types/index.mjs} +9 -3
- package/dist/esm/types/index.mjs.map +1 -0
- package/{lib-esm → dist/esm}/utils/ConnectionStateMonitor.d.ts +3 -3
- package/{lib-esm/utils/ConnectionStateMonitor.js → dist/esm/utils/ConnectionStateMonitor.mjs} +9 -5
- package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -0
- package/dist/esm/utils/ReachabilityMonitor/index.d.ts +1 -0
- package/{lib-esm/utils/ReachabilityMonitor/index.js → dist/esm/utils/ReachabilityMonitor/index.mjs} +6 -2
- package/dist/esm/utils/ReachabilityMonitor/index.mjs.map +1 -0
- package/dist/esm/utils/ReachabilityMonitor/index.native.d.ts +1 -0
- package/dist/esm/utils/ReachabilityMonitor/index.native.mjs +9 -0
- package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -0
- package/{lib-esm/utils/ReconnectionMonitor.js → dist/esm/utils/ReconnectionMonitor.mjs} +7 -3
- package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -0
- package/{lib-esm/utils/errors/APIError.js → dist/esm/utils/errors/APIError.mjs} +6 -2
- package/dist/esm/utils/errors/APIError.mjs.map +1 -0
- package/{lib-esm/utils/errors/assertValidationError.js → dist/esm/utils/errors/assertValidationError.mjs} +7 -3
- package/dist/esm/utils/errors/assertValidationError.mjs.map +1 -0
- package/dist/esm/utils/errors/index.mjs +4 -0
- package/dist/esm/utils/errors/index.mjs.map +1 -0
- package/{lib-esm/utils/errors/validation.js → dist/esm/utils/errors/validation.mjs} +5 -2
- package/dist/esm/utils/errors/validation.mjs.map +1 -0
- package/dist/esm/utils/findIndexByFields.d.ts +9 -0
- package/dist/esm/utils/findIndexByFields.mjs +22 -0
- package/dist/esm/utils/findIndexByFields.mjs.map +1 -0
- package/{lib → dist/esm}/utils/index.d.ts +2 -0
- package/dist/esm/utils/index.mjs +5 -0
- package/dist/esm/utils/index.mjs.map +1 -0
- package/{lib → dist/esm}/utils/resolveConfig.d.ts +1 -1
- package/{lib-esm/utils/resolveConfig.js → dist/esm/utils/resolveConfig.mjs} +8 -2
- package/dist/esm/utils/resolveConfig.mjs.map +1 -0
- package/{lib → dist/esm}/utils/resolveLibraryOptions.d.ts +2 -2
- package/{lib/utils/resolveLibraryOptions.js → dist/esm/utils/resolveLibraryOptions.mjs} +4 -3
- package/dist/esm/utils/resolveLibraryOptions.mjs.map +1 -0
- package/dist/esm/utils/resolveOwnerFields.d.ts +12 -0
- package/dist/esm/utils/resolveOwnerFields.mjs +39 -0
- package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -0
- package/dist/esm/utils/resolvePKFields.d.ts +13 -0
- package/dist/esm/utils/resolvePKFields.mjs +14 -0
- package/dist/esm/utils/resolvePKFields.mjs.map +1 -0
- package/internals/package.json +4 -4
- package/internals/server/package.json +8 -0
- package/package.json +56 -26
- package/src/GraphQLAPI.ts +1 -1
- package/src/internals/APIClient.ts +724 -0
- package/src/internals/InternalGraphQLAPI.ts +1 -1
- package/src/internals/generateClient.ts +33 -0
- package/src/internals/generateModelsProperty.ts +70 -0
- package/src/internals/index.ts +1 -0
- package/src/internals/operations/get.ts +121 -0
- package/src/internals/operations/list.ts +111 -0
- package/src/internals/operations/observeQuery.ts +140 -0
- package/src/internals/operations/subscription.ts +59 -0
- package/src/internals/server/generateClient.ts +45 -0
- package/src/internals/server/generateModelsProperty.ts +70 -0
- package/src/internals/server/index.ts +4 -0
- package/src/internals/types.ts +21 -0
- package/src/types/index.ts +28 -2
- package/src/utils/findIndexByFields.ts +29 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/resolveOwnerFields.ts +65 -0
- package/src/utils/resolvePKFields.ts +22 -0
- package/lib/GraphQLAPI.d.ts +0 -38
- package/lib/Providers/constants.d.ts +0 -95
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -12
- package/lib/internals/index.js +0 -11
- package/lib/internals/v6.d.ts +0 -101
- package/lib/tsconfig.tsbuildinfo +0 -6813
- package/lib/types/index.d.ts +0 -309
- package/lib/types/index.js +0 -14
- package/lib/utils/ConnectionStateMonitor.d.ts +0 -41
- package/lib/utils/ReachabilityMonitor/index.d.ts +0 -1
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +0 -1
- package/lib/utils/ReconnectionMonitor.d.ts +0 -29
- package/lib/utils/errors/APIError.d.ts +0 -7
- package/lib/utils/errors/assertValidationError.d.ts +0 -5
- package/lib/utils/errors/index.d.ts +0 -3
- package/lib/utils/errors/index.js +0 -11
- package/lib/utils/errors/validation.d.ts +0 -7
- package/lib/utils/index.js +0 -8
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -64
- package/lib-esm/index.js +0 -5
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +0 -58
- package/lib-esm/internals/index.d.ts +0 -2
- package/lib-esm/internals/index.js +0 -4
- package/lib-esm/tsconfig.tsbuildinfo +0 -6813
- package/lib-esm/types/PubSub.d.ts +0 -27
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +0 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +0 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +0 -5
- package/lib-esm/utils/errors/index.js +0 -5
- package/lib-esm/utils/index.d.ts +0 -2
- package/lib-esm/utils/index.js +0 -4
- package/lib-esm/utils/resolveConfig.d.ts +0 -12
- package/lib-esm/utils/resolveLibraryOptions.d.ts +0 -11
- /package/{lib-esm → dist/esm}/Providers/constants.d.ts +0 -0
- /package/{lib-esm → dist/esm}/index.d.ts +0 -0
- /package/{lib-esm → dist/esm}/internals/v6.d.ts +0 -0
- /package/{lib-esm → dist/esm}/utils/ReconnectionMonitor.d.ts +0 -0
- /package/{lib-esm → dist/esm}/utils/errors/APIError.d.ts +0 -0
- /package/{lib-esm → dist/esm}/utils/errors/assertValidationError.d.ts +0 -0
- /package/{lib-esm → dist/esm}/utils/errors/index.d.ts +0 -0
- /package/{lib-esm → dist/esm}/utils/errors/validation.d.ts +0 -0
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
4
|
+
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
4
5
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
5
6
|
export { OperationTypeNode } from 'graphql';
|
|
6
7
|
import { Observable } from 'rxjs';
|
|
@@ -12,6 +13,11 @@ import {
|
|
|
12
13
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
13
14
|
|
|
14
15
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
16
|
+
|
|
17
|
+
export { SelectionSet } from '@aws-amplify/data-schema-types';
|
|
18
|
+
|
|
19
|
+
export { CommonPublicClientOptions } from '../internals/types';
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
17
23
|
*/
|
|
@@ -349,25 +355,45 @@ export type GeneratedSubscription<InputType, OutputType> = string & {
|
|
|
349
355
|
type FilteredKeys<T> = {
|
|
350
356
|
[P in keyof T]: T[P] extends never ? never : P;
|
|
351
357
|
}[keyof T];
|
|
358
|
+
|
|
352
359
|
type ExcludeNeverFields<O> = {
|
|
353
360
|
[K in FilteredKeys<O>]: O[K];
|
|
354
361
|
};
|
|
355
362
|
|
|
356
363
|
export const __amplify = Symbol('amplify');
|
|
364
|
+
export const __authMode = Symbol('authMode');
|
|
365
|
+
export const __authToken = Symbol('authToken');
|
|
357
366
|
|
|
358
367
|
export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
359
368
|
[__amplify]: AmplifyClassV6;
|
|
369
|
+
[__authMode]?: GraphQLAuthMode;
|
|
370
|
+
[__authToken]?: string;
|
|
360
371
|
graphql: GraphQLMethod;
|
|
361
372
|
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
362
373
|
isCancelError: (error: any) => boolean;
|
|
374
|
+
models: ModelTypes<T>;
|
|
363
375
|
}>;
|
|
364
376
|
|
|
365
|
-
export type
|
|
377
|
+
export type V6ClientSSRRequest<T extends Record<any, any> = never> =
|
|
366
378
|
ExcludeNeverFields<{
|
|
367
379
|
[__amplify]: AmplifyClassV6;
|
|
380
|
+
[__authMode]?: GraphQLAuthMode;
|
|
381
|
+
[__authToken]?: string;
|
|
368
382
|
graphql: GraphQLMethodSSR;
|
|
369
383
|
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
370
384
|
isCancelError: (error: any) => boolean;
|
|
385
|
+
models: ModelTypes<T, 'REQUEST'>;
|
|
386
|
+
}>;
|
|
387
|
+
|
|
388
|
+
export type V6ClientSSRCookies<T extends Record<any, any> = never> =
|
|
389
|
+
ExcludeNeverFields<{
|
|
390
|
+
[__amplify]: AmplifyClassV6;
|
|
391
|
+
[__authMode]?: GraphQLAuthMode;
|
|
392
|
+
[__authToken]?: string;
|
|
393
|
+
graphql: GraphQLMethod;
|
|
394
|
+
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
395
|
+
isCancelError: (error: any) => boolean;
|
|
396
|
+
models: ModelTypes<T, 'COOKIES'>;
|
|
371
397
|
}>;
|
|
372
398
|
|
|
373
399
|
export type GraphQLMethod = <
|
|
@@ -404,7 +430,7 @@ export type ServerClientGenerationParams = {
|
|
|
404
430
|
amplify:
|
|
405
431
|
| null // null expected when used with `generateServerClient`
|
|
406
432
|
// closure expected with `generateServerClientUsingCookies`
|
|
407
|
-
| ((fn: (amplify:
|
|
433
|
+
| ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
|
|
408
434
|
// global env-sourced config use for retrieving modelIntro
|
|
409
435
|
config: ResourcesConfig;
|
|
410
436
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Iterates through a collection to find a matching item and returns the index.
|
|
5
|
+
*
|
|
6
|
+
* @param needle The item to search for
|
|
7
|
+
* @param haystack The collection to search
|
|
8
|
+
* @param keyFields The fields used to indicate a match
|
|
9
|
+
* @returns Index of `needle` in `haystack`, otherwise -1 if not found.
|
|
10
|
+
*/
|
|
11
|
+
export function findIndexByFields<T>(
|
|
12
|
+
needle: T,
|
|
13
|
+
haystack: T[],
|
|
14
|
+
keyFields: Array<keyof T>
|
|
15
|
+
): number {
|
|
16
|
+
const searchObject = Object.fromEntries(
|
|
17
|
+
keyFields.map(fieldName => [fieldName, needle[fieldName]])
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < haystack.length; i++) {
|
|
21
|
+
if (
|
|
22
|
+
Object.keys(searchObject).every(k => searchObject[k] === haystack[i][k])
|
|
23
|
+
) {
|
|
24
|
+
return i;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ResourcesConfig } from '@aws-amplify/core';
|
|
4
|
+
|
|
5
|
+
type GraphQLConfig = Exclude<ResourcesConfig['API'], undefined>['GraphQL'];
|
|
6
|
+
type ModelIntrospectionSchema = Exclude<
|
|
7
|
+
Exclude<GraphQLConfig, undefined>['modelIntrospection'],
|
|
8
|
+
undefined
|
|
9
|
+
>;
|
|
10
|
+
type Model = ModelIntrospectionSchema['models'][string];
|
|
11
|
+
|
|
12
|
+
type AuthAttribute = {
|
|
13
|
+
type: 'auth';
|
|
14
|
+
properties: {
|
|
15
|
+
rules: AuthRule[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Only the portions of an Auth rule we care about.
|
|
21
|
+
*/
|
|
22
|
+
type AuthRule = {
|
|
23
|
+
allow: string;
|
|
24
|
+
ownerField?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Given an introspection schema model, returns all owner fields.
|
|
29
|
+
*
|
|
30
|
+
* @param model Model from an introspection schema
|
|
31
|
+
* @returns List of owner field names
|
|
32
|
+
*/
|
|
33
|
+
export function resolveOwnerFields(model: Model): string[] {
|
|
34
|
+
const ownerFields = new Set<string>();
|
|
35
|
+
for (const attr of model.attributes || []) {
|
|
36
|
+
if (isAuthAttribute(attr)) {
|
|
37
|
+
for (const rule of attr.properties.rules) {
|
|
38
|
+
if (rule.allow === 'owner') {
|
|
39
|
+
ownerFields.add(rule.ownerField || 'owner');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Array.from(ownerFields);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Type guard that identifies an auth attribute with an attached rules list that
|
|
49
|
+
* specifies an `allow` attribute at a minimum.
|
|
50
|
+
*
|
|
51
|
+
* @param attribute Any object. Ideally a model introspection schema model attribute
|
|
52
|
+
* @returns True if given object is an auth attribute
|
|
53
|
+
*/
|
|
54
|
+
function isAuthAttribute(attribute: any): attribute is AuthAttribute {
|
|
55
|
+
if (attribute?.type === 'auth') {
|
|
56
|
+
if (typeof attribute?.properties === 'object') {
|
|
57
|
+
if (Array.isArray(attribute?.properties?.rules)) {
|
|
58
|
+
return (attribute?.properties?.rules as Array<any>).every(
|
|
59
|
+
rule => !!rule.allow
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ResourcesConfig } from '@aws-amplify/core';
|
|
4
|
+
|
|
5
|
+
type GraphQLConfig = Exclude<ResourcesConfig['API'], undefined>['GraphQL'];
|
|
6
|
+
type ModelIntrospectionSchema = Exclude<
|
|
7
|
+
Exclude<GraphQLConfig, undefined>['modelIntrospection'],
|
|
8
|
+
undefined
|
|
9
|
+
>;
|
|
10
|
+
type SchemaModel = ModelIntrospectionSchema['models'][string];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Given a SchemaModel from a ModelIntrospectionSchema, returns the primary key
|
|
14
|
+
* as an array of field names.
|
|
15
|
+
*
|
|
16
|
+
* @param model The model object
|
|
17
|
+
* @returns Array of field names
|
|
18
|
+
*/
|
|
19
|
+
export function resolvePKFields(model: SchemaModel) {
|
|
20
|
+
const { primaryKeyFieldName, sortKeyFieldNames } = model.primaryKeyInfo;
|
|
21
|
+
return [primaryKeyFieldName, ...sortKeyFieldNames];
|
|
22
|
+
}
|
package/lib/GraphQLAPI.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
-
import { GraphQLOptions, GraphQLResult } from './types';
|
|
3
|
-
import { InternalGraphQLAPIClass } from './internals';
|
|
4
|
-
import { Observable } from 'rxjs';
|
|
5
|
-
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
|
|
6
|
-
query: any;
|
|
7
|
-
variables: {};
|
|
8
|
-
authToken: string | undefined;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Export Cloud Logic APIs
|
|
12
|
-
*/
|
|
13
|
-
export declare class GraphQLAPIClass extends InternalGraphQLAPIClass {
|
|
14
|
-
getModuleName(): string;
|
|
15
|
-
/**
|
|
16
|
-
* Executes a GraphQL operation
|
|
17
|
-
*
|
|
18
|
-
* @param options - GraphQL Options
|
|
19
|
-
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
20
|
-
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
21
|
-
*/
|
|
22
|
-
graphql<T = any>(amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>), options: GraphQLOptions, additionalHeaders?: {
|
|
23
|
-
[key: string]: string;
|
|
24
|
-
}): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
|
|
25
|
-
/**
|
|
26
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
27
|
-
* @param error - Any error
|
|
28
|
-
* @returns A boolean indicating if the error was from an api request cancellation
|
|
29
|
-
*/
|
|
30
|
-
isCancelError(error: any): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
33
|
-
* @param {any} request - request to cancel
|
|
34
|
-
* @returns A boolean indicating if the request was cancelled
|
|
35
|
-
*/
|
|
36
|
-
cancel(request: Promise<any>, message?: string): boolean;
|
|
37
|
-
}
|
|
38
|
-
export declare const GraphQLAPI: GraphQLAPIClass;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
export { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils';
|
|
2
|
-
export declare const MAX_DELAY_MS = 5000;
|
|
3
|
-
export declare const NON_RETRYABLE_CODES: number[];
|
|
4
|
-
export declare const CONNECTION_STATE_CHANGE = "ConnectionStateChange";
|
|
5
|
-
export declare enum MESSAGE_TYPES {
|
|
6
|
-
/**
|
|
7
|
-
* Client -> Server message.
|
|
8
|
-
* This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
|
|
9
|
-
*/
|
|
10
|
-
GQL_CONNECTION_INIT = "connection_init",
|
|
11
|
-
/**
|
|
12
|
-
* Server -> Client message
|
|
13
|
-
* This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
|
|
14
|
-
*/
|
|
15
|
-
GQL_CONNECTION_ERROR = "connection_error",
|
|
16
|
-
/**
|
|
17
|
-
* Server -> Client message.
|
|
18
|
-
* This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
|
|
19
|
-
*/
|
|
20
|
-
GQL_CONNECTION_ACK = "connection_ack",
|
|
21
|
-
/**
|
|
22
|
-
* Client -> Server message.
|
|
23
|
-
* This message type is for register subscriptions with AWS AppSync RealTime
|
|
24
|
-
*/
|
|
25
|
-
GQL_START = "start",
|
|
26
|
-
/**
|
|
27
|
-
* Server -> Client message.
|
|
28
|
-
* This message type is for the ack response from AWS AppSync RealTime for GQL_START message
|
|
29
|
-
*/
|
|
30
|
-
GQL_START_ACK = "start_ack",
|
|
31
|
-
/**
|
|
32
|
-
* Server -> Client message.
|
|
33
|
-
* This message type is for subscription message from AWS AppSync RealTime
|
|
34
|
-
*/
|
|
35
|
-
GQL_DATA = "data",
|
|
36
|
-
/**
|
|
37
|
-
* Server -> Client message.
|
|
38
|
-
* This message type helps the client to know is still receiving messages from AWS AppSync RealTime
|
|
39
|
-
*/
|
|
40
|
-
GQL_CONNECTION_KEEP_ALIVE = "ka",
|
|
41
|
-
/**
|
|
42
|
-
* Client -> Server message.
|
|
43
|
-
* This message type is for unregister subscriptions with AWS AppSync RealTime
|
|
44
|
-
*/
|
|
45
|
-
GQL_STOP = "stop",
|
|
46
|
-
/**
|
|
47
|
-
* Server -> Client message.
|
|
48
|
-
* This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
|
|
49
|
-
*/
|
|
50
|
-
GQL_COMPLETE = "complete",
|
|
51
|
-
/**
|
|
52
|
-
* Server -> Client message.
|
|
53
|
-
* This message type is for sending error messages from AWS AppSync RealTime to the client
|
|
54
|
-
*/
|
|
55
|
-
GQL_ERROR = "error"
|
|
56
|
-
}
|
|
57
|
-
export declare enum SUBSCRIPTION_STATUS {
|
|
58
|
-
PENDING = 0,
|
|
59
|
-
CONNECTED = 1,
|
|
60
|
-
FAILED = 2
|
|
61
|
-
}
|
|
62
|
-
export declare enum SOCKET_STATUS {
|
|
63
|
-
CLOSED = 0,
|
|
64
|
-
READY = 1,
|
|
65
|
-
CONNECTING = 2
|
|
66
|
-
}
|
|
67
|
-
export declare const AWS_APPSYNC_REALTIME_HEADERS: {
|
|
68
|
-
accept: string;
|
|
69
|
-
'content-encoding': string;
|
|
70
|
-
'content-type': string;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Time in milleseconds to wait for GQL_CONNECTION_INIT message
|
|
74
|
-
*/
|
|
75
|
-
export declare const CONNECTION_INIT_TIMEOUT = 15000;
|
|
76
|
-
/**
|
|
77
|
-
* Time in milleseconds to wait for GQL_START_ACK message
|
|
78
|
-
*/
|
|
79
|
-
export declare const START_ACK_TIMEOUT = 15000;
|
|
80
|
-
/**
|
|
81
|
-
* Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
|
|
82
|
-
*/
|
|
83
|
-
export declare const DEFAULT_KEEP_ALIVE_TIMEOUT: number;
|
|
84
|
-
/**
|
|
85
|
-
* Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
|
|
86
|
-
*/
|
|
87
|
-
export declare const DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT: number;
|
|
88
|
-
/**
|
|
89
|
-
* Default delay time in milleseconds between when reconnect is triggered vs when it is attempted
|
|
90
|
-
*/
|
|
91
|
-
export declare const RECONNECT_DELAY: number;
|
|
92
|
-
/**
|
|
93
|
-
* Default interval time in milleseconds between when reconnect is re-attempted
|
|
94
|
-
*/
|
|
95
|
-
export declare const RECONNECT_INTERVAL: number;
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
var GraphQLAPI_1 = require("./GraphQLAPI");
|
|
7
|
-
exports.GraphQLAPI = GraphQLAPI_1.GraphQLAPI;
|
|
8
|
-
exports.GraphQLAPIClass = GraphQLAPI_1.GraphQLAPIClass;
|
|
9
|
-
exports.graphqlOperation = GraphQLAPI_1.graphqlOperation;
|
|
10
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
11
|
-
var constants_1 = require("./Providers/constants");
|
|
12
|
-
exports.CONNECTION_STATE_CHANGE = constants_1.CONNECTION_STATE_CHANGE;
|
package/lib/internals/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
var InternalGraphQLAPI_1 = require("./InternalGraphQLAPI");
|
|
6
|
-
exports.InternalGraphQLAPI = InternalGraphQLAPI_1.InternalGraphQLAPI;
|
|
7
|
-
exports.InternalGraphQLAPIClass = InternalGraphQLAPI_1.InternalGraphQLAPIClass;
|
|
8
|
-
var v6_1 = require("./v6");
|
|
9
|
-
exports.graphql = v6_1.graphql;
|
|
10
|
-
exports.cancel = v6_1.cancel;
|
|
11
|
-
exports.isCancelError = v6_1.isCancelError;
|
package/lib/internals/v6.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { V6Client, GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Invokes graphql operations against a graphql service, providing correct input and
|
|
4
|
-
* output types if Amplify-generated graphql from a recent version of the CLI/codegen
|
|
5
|
-
* are used *or* correct typing is provided via the type argument.
|
|
6
|
-
*
|
|
7
|
-
* Amplify-generated "branded" graphql queries will look similar to this:
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* //
|
|
11
|
-
* // |-- branding
|
|
12
|
-
* // v
|
|
13
|
-
* export const getModel = `...` as GeneratedQuery<
|
|
14
|
-
* GetModelQueryVariables,
|
|
15
|
-
* GetModelQuery
|
|
16
|
-
* >;
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* If this branding is not in your generated graphql, update to a newer version of
|
|
20
|
-
* CLI/codegen and regenerate your graphql using `amplify codegen`.
|
|
21
|
-
*
|
|
22
|
-
* ## Using Amplify-generated graphql
|
|
23
|
-
*
|
|
24
|
-
* ```ts
|
|
25
|
-
* import * as queries from './graphql/queries';
|
|
26
|
-
*
|
|
27
|
-
* //
|
|
28
|
-
* // |-- correctly typed graphql response containing a Widget
|
|
29
|
-
* // v
|
|
30
|
-
* const queryResult = await graphql({
|
|
31
|
-
* query: queries.getWidget,
|
|
32
|
-
* variables: {
|
|
33
|
-
* id: "abc", // <-- type hinted/enforced
|
|
34
|
-
* },
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* //
|
|
38
|
-
* // |-- a correctly typed Widget
|
|
39
|
-
* // v
|
|
40
|
-
* const fetchedWidget = queryResult.data?.getWidget!;
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* ## Custom input + result types
|
|
44
|
-
*
|
|
45
|
-
* To provide input types (`variables`) and result types:
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* type GetById_NameOnly = {
|
|
49
|
-
* variables: {
|
|
50
|
-
* id: string
|
|
51
|
-
* },
|
|
52
|
-
* result: Promise<{
|
|
53
|
-
* data: { getWidget: { name: string } }
|
|
54
|
-
* }>
|
|
55
|
-
* }
|
|
56
|
-
*
|
|
57
|
-
* //
|
|
58
|
-
* // |-- type is GetById_NameOnly["result"]
|
|
59
|
-
* // v
|
|
60
|
-
* const result = graphql<GetById_NameOnly>({
|
|
61
|
-
* query: "...",
|
|
62
|
-
* variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
|
|
63
|
-
* });
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* ## Custom result type only
|
|
67
|
-
*
|
|
68
|
-
* To specify result types only, use a type that is *not* in the `{variables, result}` shape:
|
|
69
|
-
*
|
|
70
|
-
* ```ts
|
|
71
|
-
* type MyResultType = Promise<{
|
|
72
|
-
* data: {
|
|
73
|
-
* getWidget: { name: string }
|
|
74
|
-
* }
|
|
75
|
-
* }>
|
|
76
|
-
*
|
|
77
|
-
* //
|
|
78
|
-
* // |-- type is MyResultType
|
|
79
|
-
* // v
|
|
80
|
-
* const result = graphql<MyResultType>({query: "..."});
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @param options
|
|
84
|
-
* @param additionalHeaders
|
|
85
|
-
*/
|
|
86
|
-
export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(this: V6Client, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
87
|
-
[key: string]: string;
|
|
88
|
-
}): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
89
|
-
/**
|
|
90
|
-
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
91
|
-
* @param {any} request - request to cancel
|
|
92
|
-
* @returns - A boolean indicating if the request was cancelled
|
|
93
|
-
*/
|
|
94
|
-
export declare function cancel(this: V6Client, promise: Promise<any>, message?: string): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
97
|
-
* @param {any} error - Any error
|
|
98
|
-
* @returns - A boolean indicating if the error was from an api request cancellation
|
|
99
|
-
*/
|
|
100
|
-
export declare function isCancelError(this: V6Client, error: any): boolean;
|
|
101
|
-
export { GraphQLOptionsV6, GraphQLResponseV6 };
|