@aws-amplify/api-graphql 3.4.12-unstable.7762f1a.0 → 4.0.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/README.md +3 -0
- package/lib/GraphQLAPI.d.ts +17 -4
- package/lib/GraphQLAPI.js +33 -27
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +690 -0
- package/lib/Providers/constants.d.ts +95 -0
- package/lib/Providers/constants.js +103 -0
- package/lib/index.d.ts +1 -3
- package/lib/index.js +6 -10
- package/lib/internals/InternalGraphQLAPI.d.ts +11 -34
- package/lib/internals/InternalGraphQLAPI.js +219 -345
- package/lib/internals/index.d.ts +1 -0
- package/lib/internals/index.js +4 -1
- package/lib/internals/v6.d.ts +101 -0
- package/lib/internals/v6.js +118 -0
- package/lib/tsconfig.tsbuildinfo +6813 -0
- package/lib/types/PubSub.d.ts +27 -0
- package/lib/types/PubSub.js +46 -0
- package/lib/types/index.d.ts +281 -5
- package/lib/types/index.js +4 -3
- package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
- package/lib/utils/ConnectionStateMonitor.js +131 -0
- package/lib/utils/ReachabilityMonitor/index.d.ts +1 -0
- package/lib/utils/ReachabilityMonitor/index.js +6 -0
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -0
- package/lib/utils/ReachabilityMonitor/index.native.js +8 -0
- package/lib/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib/utils/ReconnectionMonitor.js +68 -0
- package/lib/utils/errors/APIError.d.ts +7 -0
- package/lib/utils/errors/APIError.js +18 -0
- package/lib/utils/errors/assertValidationError.d.ts +5 -0
- package/lib/utils/errors/assertValidationError.js +16 -0
- package/lib/utils/errors/index.d.ts +3 -0
- package/lib/utils/errors/index.js +11 -0
- package/lib/utils/errors/validation.d.ts +7 -0
- package/lib/utils/errors/validation.js +25 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +8 -0
- package/lib/utils/resolveConfig.d.ts +12 -0
- package/lib/utils/resolveConfig.js +22 -0
- package/lib/utils/resolveLibraryOptions.d.ts +11 -0
- package/lib/utils/resolveLibraryOptions.js +12 -0
- package/lib-esm/GraphQLAPI.d.ts +17 -4
- package/lib-esm/GraphQLAPI.js +33 -28
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +687 -0
- package/lib-esm/Providers/constants.d.ts +95 -0
- package/lib-esm/Providers/constants.js +100 -0
- package/lib-esm/index.d.ts +1 -3
- package/lib-esm/index.js +1 -4
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +11 -34
- package/lib-esm/internals/InternalGraphQLAPI.js +218 -345
- package/lib-esm/internals/index.d.ts +1 -0
- package/lib-esm/internals/index.js +1 -1
- package/lib-esm/internals/v6.d.ts +101 -0
- package/lib-esm/internals/v6.js +113 -0
- package/lib-esm/tsconfig.tsbuildinfo +6813 -0
- package/lib-esm/types/PubSub.d.ts +27 -0
- package/lib-esm/types/PubSub.js +44 -0
- package/lib-esm/types/index.d.ts +281 -5
- package/lib-esm/types/index.js +2 -3
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +41 -0
- package/lib-esm/utils/ConnectionStateMonitor.js +128 -0
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -0
- package/lib-esm/utils/ReachabilityMonitor/index.js +4 -0
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -0
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +5 -0
- package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib-esm/utils/ReconnectionMonitor.js +65 -0
- package/lib-esm/utils/errors/APIError.d.ts +7 -0
- package/lib-esm/utils/errors/APIError.js +15 -0
- package/lib-esm/utils/errors/assertValidationError.d.ts +5 -0
- package/lib-esm/utils/errors/assertValidationError.js +13 -0
- package/lib-esm/utils/errors/index.d.ts +3 -0
- package/lib-esm/utils/errors/index.js +5 -0
- package/lib-esm/utils/errors/validation.d.ts +7 -0
- package/lib-esm/utils/errors/validation.js +23 -0
- package/lib-esm/utils/index.d.ts +2 -0
- package/lib-esm/utils/index.js +4 -0
- package/lib-esm/utils/resolveConfig.d.ts +12 -0
- package/lib-esm/utils/resolveConfig.js +20 -0
- package/lib-esm/utils/resolveLibraryOptions.d.ts +11 -0
- package/lib-esm/utils/resolveLibraryOptions.js +10 -0
- package/package.json +122 -114
- package/src/GraphQLAPI.ts +26 -4
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +998 -0
- package/src/Providers/constants.ts +110 -0
- package/src/index.ts +2 -3
- package/src/internals/InternalGraphQLAPI.ts +181 -218
- package/src/internals/index.ts +2 -0
- package/src/internals/v6.ts +138 -0
- package/src/types/PubSub.ts +56 -0
- package/src/types/index.ts +378 -8
- package/src/utils/ConnectionStateMonitor.ts +199 -0
- package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
- package/src/utils/ReachabilityMonitor/index.ts +4 -0
- package/src/utils/ReconnectionMonitor.ts +76 -0
- package/src/utils/errors/APIError.ts +21 -0
- package/src/utils/errors/assertValidationError.ts +19 -0
- package/src/utils/errors/index.ts +6 -0
- package/src/utils/errors/validation.ts +26 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/resolveConfig.ts +35 -0
- package/src/utils/resolveLibraryOptions.ts +13 -0
- package/lib/.tsbuildinfo +0 -3
- package/lib/GraphQLAPI.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/internals/InternalGraphQLAPI.js.map +0 -1
- package/lib/internals/index.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/GraphQLAPI.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/internals/InternalGraphQLAPI.js.map +0 -1
- package/lib-esm/internals/index.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { GraphQLAPI } from '../GraphQLAPI';
|
|
4
|
+
import {
|
|
5
|
+
__amplify,
|
|
6
|
+
V6Client,
|
|
7
|
+
GraphQLOptionsV6,
|
|
8
|
+
GraphQLResponseV6,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Invokes graphql operations against a graphql service, providing correct input and
|
|
13
|
+
* output types if Amplify-generated graphql from a recent version of the CLI/codegen
|
|
14
|
+
* are used *or* correct typing is provided via the type argument.
|
|
15
|
+
*
|
|
16
|
+
* Amplify-generated "branded" graphql queries will look similar to this:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* //
|
|
20
|
+
* // |-- branding
|
|
21
|
+
* // v
|
|
22
|
+
* export const getModel = `...` as GeneratedQuery<
|
|
23
|
+
* GetModelQueryVariables,
|
|
24
|
+
* GetModelQuery
|
|
25
|
+
* >;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* If this branding is not in your generated graphql, update to a newer version of
|
|
29
|
+
* CLI/codegen and regenerate your graphql using `amplify codegen`.
|
|
30
|
+
*
|
|
31
|
+
* ## Using Amplify-generated graphql
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import * as queries from './graphql/queries';
|
|
35
|
+
*
|
|
36
|
+
* //
|
|
37
|
+
* // |-- correctly typed graphql response containing a Widget
|
|
38
|
+
* // v
|
|
39
|
+
* const queryResult = await graphql({
|
|
40
|
+
* query: queries.getWidget,
|
|
41
|
+
* variables: {
|
|
42
|
+
* id: "abc", // <-- type hinted/enforced
|
|
43
|
+
* },
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* //
|
|
47
|
+
* // |-- a correctly typed Widget
|
|
48
|
+
* // v
|
|
49
|
+
* const fetchedWidget = queryResult.data?.getWidget!;
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* ## Custom input + result types
|
|
53
|
+
*
|
|
54
|
+
* To provide input types (`variables`) and result types:
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* type GetById_NameOnly = {
|
|
58
|
+
* variables: {
|
|
59
|
+
* id: string
|
|
60
|
+
* },
|
|
61
|
+
* result: Promise<{
|
|
62
|
+
* data: { getWidget: { name: string } }
|
|
63
|
+
* }>
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* //
|
|
67
|
+
* // |-- type is GetById_NameOnly["result"]
|
|
68
|
+
* // v
|
|
69
|
+
* const result = graphql<GetById_NameOnly>({
|
|
70
|
+
* query: "...",
|
|
71
|
+
* variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ## Custom result type only
|
|
76
|
+
*
|
|
77
|
+
* To specify result types only, use a type that is *not* in the `{variables, result}` shape:
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* type MyResultType = Promise<{
|
|
81
|
+
* data: {
|
|
82
|
+
* getWidget: { name: string }
|
|
83
|
+
* }
|
|
84
|
+
* }>
|
|
85
|
+
*
|
|
86
|
+
* //
|
|
87
|
+
* // |-- type is MyResultType
|
|
88
|
+
* // v
|
|
89
|
+
* const result = graphql<MyResultType>({query: "..."});
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param options
|
|
93
|
+
* @param additionalHeaders
|
|
94
|
+
*/
|
|
95
|
+
export function graphql<
|
|
96
|
+
FALLBACK_TYPES = unknown,
|
|
97
|
+
TYPED_GQL_STRING extends string = string
|
|
98
|
+
>(
|
|
99
|
+
this: V6Client,
|
|
100
|
+
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
101
|
+
additionalHeaders?: { [key: string]: string }
|
|
102
|
+
): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING> {
|
|
103
|
+
/**
|
|
104
|
+
* The correctness of these typings depends on correct string branding or overrides.
|
|
105
|
+
* Neither of these can actually be validated at runtime. Hence, we don't perform
|
|
106
|
+
* any validation or type-guarding here.
|
|
107
|
+
*/
|
|
108
|
+
const result = GraphQLAPI.graphql(
|
|
109
|
+
this[__amplify],
|
|
110
|
+
options,
|
|
111
|
+
additionalHeaders
|
|
112
|
+
);
|
|
113
|
+
return result as any;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
118
|
+
* @param {any} request - request to cancel
|
|
119
|
+
* @returns - A boolean indicating if the request was cancelled
|
|
120
|
+
*/
|
|
121
|
+
export function cancel(
|
|
122
|
+
this: V6Client,
|
|
123
|
+
promise: Promise<any>,
|
|
124
|
+
message?: string
|
|
125
|
+
): boolean {
|
|
126
|
+
return GraphQLAPI.cancel(promise, message);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
131
|
+
* @param {any} error - Any error
|
|
132
|
+
* @returns - A boolean indicating if the error was from an api request cancellation
|
|
133
|
+
*/
|
|
134
|
+
export function isCancelError(this: V6Client, error: any): boolean {
|
|
135
|
+
return GraphQLAPI.isCancelError(error);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { GraphQLOptionsV6, GraphQLResponseV6 };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Observer } from 'rxjs';
|
|
4
|
+
export interface SubscriptionObserver<T> {
|
|
5
|
+
closed: boolean;
|
|
6
|
+
next(value: T): void;
|
|
7
|
+
error(errorValue: any): void;
|
|
8
|
+
complete(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum CONTROL_MSG {
|
|
12
|
+
CONNECTION_CLOSED = 'Connection closed',
|
|
13
|
+
CONNECTION_FAILED = 'Connection failed',
|
|
14
|
+
REALTIME_SUBSCRIPTION_INIT_ERROR = 'AppSync Realtime subscription init error',
|
|
15
|
+
SUBSCRIPTION_ACK = 'Subscription ack',
|
|
16
|
+
TIMEOUT_DISCONNECT = 'Timeout disconnect',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @enum {string} */
|
|
20
|
+
export enum ConnectionState {
|
|
21
|
+
/*
|
|
22
|
+
* The connection is alive and healthy
|
|
23
|
+
*/
|
|
24
|
+
Connected = 'Connected',
|
|
25
|
+
/*
|
|
26
|
+
* The connection is alive, but the connection is offline
|
|
27
|
+
*/
|
|
28
|
+
ConnectedPendingNetwork = 'ConnectedPendingNetwork',
|
|
29
|
+
/*
|
|
30
|
+
* The connection has been disconnected while in use
|
|
31
|
+
*/
|
|
32
|
+
ConnectionDisrupted = 'ConnectionDisrupted',
|
|
33
|
+
/*
|
|
34
|
+
* The connection has been disconnected and the network is offline
|
|
35
|
+
*/
|
|
36
|
+
ConnectionDisruptedPendingNetwork = 'ConnectionDisruptedPendingNetwork',
|
|
37
|
+
/*
|
|
38
|
+
* The connection is in the process of connecting
|
|
39
|
+
*/
|
|
40
|
+
Connecting = 'Connecting',
|
|
41
|
+
/*
|
|
42
|
+
* The connection is not in use and is being disconnected
|
|
43
|
+
*/
|
|
44
|
+
ConnectedPendingDisconnect = 'ConnectedPendingDisconnect',
|
|
45
|
+
/*
|
|
46
|
+
* The connection is not in use and has been disconnected
|
|
47
|
+
*/
|
|
48
|
+
Disconnected = 'Disconnected',
|
|
49
|
+
/*
|
|
50
|
+
* The connection is alive, but a keep alive message has been missed
|
|
51
|
+
*/
|
|
52
|
+
ConnectedPendingKeepAlive = 'ConnectedPendingKeepAlive',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type PubSubContent = Record<string, unknown>;
|
|
56
|
+
export type PubSubContentObserver = Observer<PubSubContent>;
|
package/src/types/index.ts
CHANGED
|
@@ -1,30 +1,184 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
4
|
+
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
4
5
|
export { OperationTypeNode } from 'graphql';
|
|
5
|
-
import {
|
|
6
|
-
export { GRAPHQL_AUTH_MODE };
|
|
7
|
-
import { CustomUserAgentDetails } from '@aws-amplify/core';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
8
7
|
|
|
8
|
+
import {
|
|
9
|
+
GraphQLAuthMode,
|
|
10
|
+
DocumentType,
|
|
11
|
+
} from '@aws-amplify/core/internals/utils';
|
|
12
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
13
|
+
|
|
14
|
+
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
15
|
+
/**
|
|
16
|
+
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
17
|
+
*/
|
|
9
18
|
export interface GraphQLOptions {
|
|
10
19
|
query: string | DocumentNode;
|
|
11
|
-
variables?:
|
|
12
|
-
authMode?:
|
|
20
|
+
variables?: Record<string, DocumentType>;
|
|
21
|
+
authMode?: GraphQLAuthMode;
|
|
13
22
|
authToken?: string;
|
|
14
23
|
/**
|
|
15
24
|
* @deprecated This property should not be used
|
|
16
25
|
*/
|
|
17
|
-
userAgentSuffix?: string;
|
|
26
|
+
userAgentSuffix?: string;
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
export interface GraphQLResult<T = object> {
|
|
21
|
-
data
|
|
30
|
+
data: T;
|
|
22
31
|
errors?: GraphQLError[];
|
|
23
32
|
extensions?: {
|
|
24
33
|
[key: string]: any;
|
|
25
34
|
};
|
|
26
35
|
}
|
|
27
36
|
|
|
37
|
+
// Opaque type used for determining the graphql query type
|
|
38
|
+
declare const queryType: unique symbol;
|
|
39
|
+
|
|
40
|
+
export type GraphQLQuery<T> = T & { readonly [queryType]: 'query' };
|
|
41
|
+
export type GraphQLSubscription<T> = T & {
|
|
42
|
+
readonly [queryType]: 'subscription';
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Accepts a code generated model type and returns a supertype that
|
|
47
|
+
* can accept return values from the relevant graphql operations.
|
|
48
|
+
*
|
|
49
|
+
* For example:
|
|
50
|
+
*
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { GraphQLReturnType } from 'aws-amplify/api';
|
|
53
|
+
* import { MyModel } from './API';
|
|
54
|
+
* import { getMyModel } from './graphql/queries';
|
|
55
|
+
*
|
|
56
|
+
* const [item, setItem] = useState<GraphQLReturnType<MyModel>>();
|
|
57
|
+
* setItem(await client.graphql({ query: getMyModel }).data.getMyModel!)
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* Trying to assign the result of a `getMyModel` operation directly to a
|
|
61
|
+
* `MyModel` variables won't necessarily work, because normally-required related
|
|
62
|
+
* models might not be part of the selection set.
|
|
63
|
+
*
|
|
64
|
+
* This util simply makes related model properties optional recursively.
|
|
65
|
+
*/
|
|
66
|
+
export type GraphQLReturnType<T> = T extends {}
|
|
67
|
+
? {
|
|
68
|
+
[K in keyof T]?: GraphQLReturnType<T[K]>;
|
|
69
|
+
}
|
|
70
|
+
: T;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Describes a paged list result from AppSync, which can either
|
|
74
|
+
* live at the top query or property (e.g., related model) level.
|
|
75
|
+
*/
|
|
76
|
+
type PagedList<T, TYPENAME> = {
|
|
77
|
+
__typename: TYPENAME;
|
|
78
|
+
nextToken?: string | null | undefined;
|
|
79
|
+
items: Array<T>;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Recursively looks through a result type and removes nulls and
|
|
84
|
+
* and undefined from `PagedList` types.
|
|
85
|
+
*
|
|
86
|
+
* Although a graphql response might contain empty values in an
|
|
87
|
+
* array, this will only be the case when we also have errors,
|
|
88
|
+
* which will then be *thrown*.
|
|
89
|
+
*/
|
|
90
|
+
type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME>
|
|
91
|
+
? PagedList<Exclude<IT, null | undefined>, NAME>
|
|
92
|
+
: T extends {}
|
|
93
|
+
? {
|
|
94
|
+
[K in keyof T]: WithListsFixed<T[K]>;
|
|
95
|
+
}
|
|
96
|
+
: T;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns an updated response type to always return a value.
|
|
100
|
+
*/
|
|
101
|
+
type NeverEmpty<T> = {
|
|
102
|
+
[K in keyof T]-?: Exclude<WithListsFixed<T[K]>, undefined | null>;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Replaces all list result types in a query result with types to exclude
|
|
107
|
+
* nulls and undefined from list member unions.
|
|
108
|
+
*
|
|
109
|
+
* If empty members are present, there will also be errors present,
|
|
110
|
+
* and the response will instead be *thrown*.
|
|
111
|
+
*/
|
|
112
|
+
type FixedQueryResult<T> = Exclude<
|
|
113
|
+
T[keyof T],
|
|
114
|
+
null | undefined
|
|
115
|
+
> extends PagedList<any, any>
|
|
116
|
+
? {
|
|
117
|
+
[K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
|
|
118
|
+
}
|
|
119
|
+
: T;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The return value from a `graphql({query})` call when `query` is a subscription.
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* // |-- You are here
|
|
126
|
+
* // v
|
|
127
|
+
* const subResult: GraphqlSubscriptionResult<T> = client.graphql({
|
|
128
|
+
* query: onCreateWidget
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* const sub = subResult.subscribe({
|
|
132
|
+
* //
|
|
133
|
+
* // |-- You are here
|
|
134
|
+
* // v
|
|
135
|
+
* next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
|
|
136
|
+
* handle(message.value); // <-- type OnCreateWidgetSubscription
|
|
137
|
+
* }
|
|
138
|
+
* })
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export type GraphqlSubscriptionResult<T> = Observable<
|
|
142
|
+
GraphqlSubscriptionMessage<T>
|
|
143
|
+
>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The shape of messages passed to `next()` from a graphql subscription. E.g.,
|
|
147
|
+
*
|
|
148
|
+
* ```ts
|
|
149
|
+
* const sub = client.graphql({
|
|
150
|
+
* query: onCreateWidget,
|
|
151
|
+
* }).subscribe({
|
|
152
|
+
* //
|
|
153
|
+
* // |-- You are here
|
|
154
|
+
* // v
|
|
155
|
+
* next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
|
|
156
|
+
* handle(message.value); // <-- type OnCreateWidgetSubscription
|
|
157
|
+
* }
|
|
158
|
+
* })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export type GraphqlSubscriptionMessage<T> = {
|
|
162
|
+
data: T;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export interface AWSAppSyncRealTimeProviderOptions {
|
|
166
|
+
appSyncGraphqlEndpoint?: string;
|
|
167
|
+
authenticationType?: GraphQLAuthMode;
|
|
168
|
+
query?: string;
|
|
169
|
+
variables?: Record<string, unknown>;
|
|
170
|
+
apiKey?: string;
|
|
171
|
+
region?: string;
|
|
172
|
+
graphql_headers?: () => {} | (() => Promise<{}>);
|
|
173
|
+
additionalHeaders?: { [key: string]: string };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export type AWSAppSyncRealTimeProvider = {
|
|
177
|
+
subscribe(
|
|
178
|
+
options?: AWSAppSyncRealTimeProviderOptions
|
|
179
|
+
): Observable<Record<string, unknown>>;
|
|
180
|
+
};
|
|
181
|
+
|
|
28
182
|
export enum GraphQLAuthError {
|
|
29
183
|
NO_API_KEY = 'No api-key configured',
|
|
30
184
|
NO_CURRENT_USER = 'No current user',
|
|
@@ -38,3 +192,219 @@ export enum GraphQLAuthError {
|
|
|
38
192
|
* @see: https://graphql.org/graphql-js/language/#parse
|
|
39
193
|
*/
|
|
40
194
|
export type GraphQLOperation = Source | string;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* API V6 `graphql({options})` type that can leverage branded graphql `query`
|
|
198
|
+
* objects and fallback types.
|
|
199
|
+
*/
|
|
200
|
+
export interface GraphQLOptionsV6<
|
|
201
|
+
FALLBACK_TYPES = unknown,
|
|
202
|
+
TYPED_GQL_STRING extends string = string
|
|
203
|
+
> {
|
|
204
|
+
query: TYPED_GQL_STRING | DocumentNode;
|
|
205
|
+
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
206
|
+
authMode?: GraphQLAuthMode;
|
|
207
|
+
authToken?: string;
|
|
208
|
+
/**
|
|
209
|
+
* @deprecated This property should not be used
|
|
210
|
+
*/
|
|
211
|
+
userAgentSuffix?: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Result type for `graphql()` operations that don't include any specific
|
|
216
|
+
* type information. The result could be either a `Promise` or `Subscription`.
|
|
217
|
+
*
|
|
218
|
+
* Invoking code should either cast the result or use `?` and `!` operators to
|
|
219
|
+
* navigate the result objects.
|
|
220
|
+
*/
|
|
221
|
+
export type UnknownGraphQLResponse =
|
|
222
|
+
| Promise<GraphQLResult<any>>
|
|
223
|
+
| GraphqlSubscriptionResult<any>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The expected type for `variables` in a V6 `graphql()` operation with
|
|
227
|
+
* respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
|
|
228
|
+
*/
|
|
229
|
+
export type GraphQLVariablesV6<
|
|
230
|
+
FALLBACK_TYPES = unknown,
|
|
231
|
+
TYPED_GQL_STRING extends string = string
|
|
232
|
+
> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any>
|
|
233
|
+
? IN
|
|
234
|
+
: TYPED_GQL_STRING extends GeneratedMutation<infer IN, any>
|
|
235
|
+
? IN
|
|
236
|
+
: TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any>
|
|
237
|
+
? IN
|
|
238
|
+
: FALLBACK_TYPES extends GraphQLOperationType<infer IN, any>
|
|
239
|
+
? IN
|
|
240
|
+
: any;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The expected return type with respect to the given `FALLBACK_TYPE`
|
|
244
|
+
* and `TYPED_GQL_STRING`.
|
|
245
|
+
*/
|
|
246
|
+
export type GraphQLResponseV6<
|
|
247
|
+
FALLBACK_TYPE = unknown,
|
|
248
|
+
TYPED_GQL_STRING extends string = string
|
|
249
|
+
> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
|
|
250
|
+
? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
|
|
251
|
+
: TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
|
|
252
|
+
? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
|
|
253
|
+
: TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
|
|
254
|
+
? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
|
|
255
|
+
: FALLBACK_TYPE extends GraphQLQuery<infer T>
|
|
256
|
+
? Promise<GraphQLResult<FALLBACK_TYPE>>
|
|
257
|
+
: FALLBACK_TYPE extends GraphQLSubscription<infer T>
|
|
258
|
+
? GraphqlSubscriptionResult<FALLBACK_TYPE>
|
|
259
|
+
: FALLBACK_TYPE extends GraphQLOperationType<infer IN, infer CUSTOM_OUT>
|
|
260
|
+
? CUSTOM_OUT
|
|
261
|
+
: UnknownGraphQLResponse;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* The shape customers can use to provide `T` to `graphql<T>()` to specify both
|
|
265
|
+
* `IN` and `OUT` types (the type of `variables` and the return type, respectively).
|
|
266
|
+
*
|
|
267
|
+
* I.E.,
|
|
268
|
+
*
|
|
269
|
+
* ```ts
|
|
270
|
+
* type MyVariablesType = { ... };
|
|
271
|
+
* type MyResultType = { ... };
|
|
272
|
+
* type MyOperationType = { variables: MyVariablesType, result: MyResultType };
|
|
273
|
+
*
|
|
274
|
+
* const result: MyResultType = graphql<MyOperationType>("graphql string", {
|
|
275
|
+
* variables: {
|
|
276
|
+
* // MyVariablesType
|
|
277
|
+
* }
|
|
278
|
+
* })
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
|
|
282
|
+
variables: IN;
|
|
283
|
+
result: OUT;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Nominal type for branding generated graphql query operation strings with
|
|
288
|
+
* input and output types.
|
|
289
|
+
*
|
|
290
|
+
* E.g.,
|
|
291
|
+
*
|
|
292
|
+
* ```ts
|
|
293
|
+
* export const getWidget = `...` as GeneratedQuery<
|
|
294
|
+
* GetWidgetQueryVariables,
|
|
295
|
+
* GetWidgetQuery
|
|
296
|
+
* >;
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
300
|
+
* assign types to the `variables` and result objects.
|
|
301
|
+
*/
|
|
302
|
+
export type GeneratedQuery<InputType, OutputType> = string & {
|
|
303
|
+
__generatedQueryInput: InputType;
|
|
304
|
+
__generatedQueryOutput: OutputType;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Nominal type for branding generated graphql mutation operation strings with
|
|
309
|
+
* input and output types.
|
|
310
|
+
*
|
|
311
|
+
* E.g.,
|
|
312
|
+
*
|
|
313
|
+
* ```ts
|
|
314
|
+
* export const createWidget = `...` as GeneratedQuery<
|
|
315
|
+
* CreateWidgetMutationVariables,
|
|
316
|
+
* CreateWidgetMutation
|
|
317
|
+
* >;
|
|
318
|
+
* ```
|
|
319
|
+
*
|
|
320
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
321
|
+
* assign types to the `variables` and result objects.
|
|
322
|
+
*/
|
|
323
|
+
export type GeneratedMutation<InputType, OutputType> = string & {
|
|
324
|
+
__generatedMutationInput: InputType;
|
|
325
|
+
__generatedMutationOutput: OutputType;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Nominal type for branding generated graphql mutation operation strings with
|
|
330
|
+
* input and output types.
|
|
331
|
+
*
|
|
332
|
+
* E.g.,
|
|
333
|
+
*
|
|
334
|
+
* ```ts
|
|
335
|
+
* export const createWidget = `...` as GeneratedMutation<
|
|
336
|
+
* CreateWidgetMutationVariables,
|
|
337
|
+
* CreateWidgetMutation
|
|
338
|
+
* >;
|
|
339
|
+
* ```
|
|
340
|
+
*
|
|
341
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
342
|
+
* assign types to the `variables` and result objects.
|
|
343
|
+
*/
|
|
344
|
+
export type GeneratedSubscription<InputType, OutputType> = string & {
|
|
345
|
+
__generatedSubscriptionInput: InputType;
|
|
346
|
+
__generatedSubscriptionOutput: OutputType;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
type FilteredKeys<T> = {
|
|
350
|
+
[P in keyof T]: T[P] extends never ? never : P;
|
|
351
|
+
}[keyof T];
|
|
352
|
+
type ExcludeNeverFields<O> = {
|
|
353
|
+
[K in FilteredKeys<O>]: O[K];
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export const __amplify = Symbol('amplify');
|
|
357
|
+
|
|
358
|
+
export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
359
|
+
[__amplify]: AmplifyClassV6;
|
|
360
|
+
graphql: GraphQLMethod;
|
|
361
|
+
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
362
|
+
isCancelError: (error: any) => boolean;
|
|
363
|
+
}>;
|
|
364
|
+
|
|
365
|
+
export type V6ClientSSR<T extends Record<any, any> = never> =
|
|
366
|
+
ExcludeNeverFields<{
|
|
367
|
+
[__amplify]: AmplifyClassV6;
|
|
368
|
+
graphql: GraphQLMethodSSR;
|
|
369
|
+
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
370
|
+
isCancelError: (error: any) => boolean;
|
|
371
|
+
}>;
|
|
372
|
+
|
|
373
|
+
export type GraphQLMethod = <
|
|
374
|
+
FALLBACK_TYPES = unknown,
|
|
375
|
+
TYPED_GQL_STRING extends string = string
|
|
376
|
+
>(
|
|
377
|
+
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
378
|
+
additionalHeaders?:
|
|
379
|
+
| {
|
|
380
|
+
[key: string]: string;
|
|
381
|
+
}
|
|
382
|
+
| undefined
|
|
383
|
+
) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
384
|
+
|
|
385
|
+
export type GraphQLMethodSSR = <
|
|
386
|
+
FALLBACK_TYPES = unknown,
|
|
387
|
+
TYPED_GQL_STRING extends string = string
|
|
388
|
+
>(
|
|
389
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
390
|
+
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
391
|
+
additionalHeaders?:
|
|
392
|
+
| {
|
|
393
|
+
[key: string]: string;
|
|
394
|
+
}
|
|
395
|
+
| undefined
|
|
396
|
+
) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @private
|
|
400
|
+
*
|
|
401
|
+
* The knobs available for configuring `server/generateClient` internally.
|
|
402
|
+
*/
|
|
403
|
+
export type ServerClientGenerationParams = {
|
|
404
|
+
amplify:
|
|
405
|
+
| null // null expected when used with `generateServerClient`
|
|
406
|
+
// closure expected with `generateServerClientUsingCookies`
|
|
407
|
+
| ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>);
|
|
408
|
+
// global env-sourced config use for retrieving modelIntro
|
|
409
|
+
config: ResourcesConfig;
|
|
410
|
+
};
|