@aws-amplify/api-graphql 4.0.17-unstable.e316a2e.0 → 4.0.17
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/dist/cjs/internals/APIClient.js +0 -1
- package/dist/cjs/internals/APIClient.js.map +1 -1
- package/dist/cjs/internals/v6.js +1 -1
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/esm/internals/APIClient.mjs +0 -1
- package/dist/esm/internals/APIClient.mjs.map +1 -1
- package/dist/esm/internals/v6.mjs +1 -1
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/utils/resolveLibraryOptions.d.ts +4 -1
- package/package.json +4 -4
- package/src/GraphQLAPI.ts +2 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +20 -20
- package/src/internals/APIClient.ts +6 -8
- package/src/internals/InternalGraphQLAPI.ts +1 -1
- package/src/internals/operations/get.ts +11 -11
- package/src/internals/operations/list.ts +10 -10
- package/src/internals/operations/subscription.ts +6 -6
- package/src/internals/server/generateClientWithAmplifyInstance.ts +1 -1
- package/src/internals/v6.ts +5 -5
- package/src/server/generateClient.ts +2 -2
- package/src/types/index.ts +50 -45
- package/src/utils/ConnectionStateMonitor.ts +6 -6
- package/src/utils/errors/assertValidationError.ts +1 -1
- package/src/utils/findIndexByFields.ts +3 -3
- package/src/utils/resolveConfig.ts +2 -2
- package/src/utils/resolveOwnerFields.ts +1 -1
package/src/GraphQLAPI.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
|
|
10
10
|
export const graphqlOperation = (
|
|
11
11
|
query: any,
|
|
12
12
|
variables = {},
|
|
13
|
-
authToken?: string
|
|
13
|
+
authToken?: string,
|
|
14
14
|
) => ({
|
|
15
15
|
query,
|
|
16
16
|
variables,
|
|
@@ -35,7 +35,7 @@ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
|
|
|
35
35
|
graphql<T = any>(
|
|
36
36
|
amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>),
|
|
37
37
|
options: GraphQLOptions,
|
|
38
|
-
additionalHeaders?: CustomHeaders
|
|
38
|
+
additionalHeaders?: CustomHeaders,
|
|
39
39
|
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
|
|
40
40
|
return super.graphql(amplify, options, additionalHeaders, {
|
|
41
41
|
category: Category.API,
|
|
@@ -158,7 +158,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
158
158
|
) {
|
|
159
159
|
this.reconnectionMonitor.record(ReconnectEvent.HALT_RECONNECT);
|
|
160
160
|
}
|
|
161
|
-
}
|
|
161
|
+
},
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -191,7 +191,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
191
191
|
|
|
192
192
|
subscribe(
|
|
193
193
|
options?: AWSAppSyncRealTimeProviderOptions,
|
|
194
|
-
customUserAgentDetails?: CustomUserAgentDetails
|
|
194
|
+
customUserAgentDetails?: CustomUserAgentDetails,
|
|
195
195
|
): Observable<Record<string, unknown>> {
|
|
196
196
|
const {
|
|
197
197
|
appSyncGraphqlEndpoint,
|
|
@@ -211,7 +211,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
211
211
|
errors: [
|
|
212
212
|
{
|
|
213
213
|
...new GraphQLError(
|
|
214
|
-
`Subscribe only available for AWS AppSync endpoint
|
|
214
|
+
`Subscribe only available for AWS AppSync endpoint`,
|
|
215
215
|
),
|
|
216
216
|
},
|
|
217
217
|
],
|
|
@@ -242,7 +242,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
242
242
|
customUserAgentDetails,
|
|
243
243
|
}).catch<any>(err => {
|
|
244
244
|
logger.debug(
|
|
245
|
-
`${CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR}: ${err}
|
|
245
|
+
`${CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR}: ${err}`,
|
|
246
246
|
);
|
|
247
247
|
|
|
248
248
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
@@ -428,13 +428,13 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
428
428
|
private _logStartSubscriptionError(
|
|
429
429
|
subscriptionId: string,
|
|
430
430
|
observer: PubSubContentObserver,
|
|
431
|
-
err: { message?: string }
|
|
431
|
+
err: { message?: string },
|
|
432
432
|
) {
|
|
433
433
|
logger.debug({ err });
|
|
434
434
|
const message = String(err.message ?? '');
|
|
435
435
|
// Resolving to give the state observer time to propogate the update
|
|
436
436
|
Promise.resolve(
|
|
437
|
-
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED)
|
|
437
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED),
|
|
438
438
|
);
|
|
439
439
|
|
|
440
440
|
// Capture the error only when the network didn't cause disruption
|
|
@@ -447,7 +447,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
447
447
|
errors: [
|
|
448
448
|
{
|
|
449
449
|
...new GraphQLError(
|
|
450
|
-
`${CONTROL_MSG.CONNECTION_FAILED}: ${message}
|
|
450
|
+
`${CONTROL_MSG.CONNECTION_FAILED}: ${message}`,
|
|
451
451
|
),
|
|
452
452
|
},
|
|
453
453
|
],
|
|
@@ -558,7 +558,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
558
558
|
return;
|
|
559
559
|
}
|
|
560
560
|
logger.debug(
|
|
561
|
-
`subscription message from AWS AppSync RealTime: ${message.data}
|
|
561
|
+
`subscription message from AWS AppSync RealTime: ${message.data}`,
|
|
562
562
|
);
|
|
563
563
|
const {
|
|
564
564
|
id = '',
|
|
@@ -587,7 +587,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
587
587
|
|
|
588
588
|
if (type === MESSAGE_TYPES.GQL_START_ACK) {
|
|
589
589
|
logger.debug(
|
|
590
|
-
`subscription ready for ${JSON.stringify({ query, variables })}
|
|
590
|
+
`subscription ready for ${JSON.stringify({ query, variables })}`,
|
|
591
591
|
);
|
|
592
592
|
if (typeof subscriptionReadyCallback === 'function') {
|
|
593
593
|
subscriptionReadyCallback();
|
|
@@ -611,7 +611,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
611
611
|
});
|
|
612
612
|
}
|
|
613
613
|
this.connectionStateMonitor.record(
|
|
614
|
-
CONNECTION_CHANGE.CONNECTION_ESTABLISHED
|
|
614
|
+
CONNECTION_CHANGE.CONNECTION_ESTABLISHED,
|
|
615
615
|
);
|
|
616
616
|
|
|
617
617
|
return;
|
|
@@ -623,7 +623,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
623
623
|
clearTimeout(this.keepAliveAlertTimeoutId);
|
|
624
624
|
this.keepAliveTimeoutId = setTimeout(
|
|
625
625
|
() => this._errorDisconnect(CONTROL_MSG.TIMEOUT_DISCONNECT),
|
|
626
|
-
this.keepAliveTimeout
|
|
626
|
+
this.keepAliveTimeout,
|
|
627
627
|
);
|
|
628
628
|
this.keepAliveAlertTimeoutId = setTimeout(() => {
|
|
629
629
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE_MISSED);
|
|
@@ -646,14 +646,14 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
646
646
|
});
|
|
647
647
|
|
|
648
648
|
logger.debug(
|
|
649
|
-
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}
|
|
649
|
+
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}`,
|
|
650
650
|
);
|
|
651
651
|
|
|
652
652
|
observer.error({
|
|
653
653
|
errors: [
|
|
654
654
|
{
|
|
655
655
|
...new GraphQLError(
|
|
656
|
-
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}
|
|
656
|
+
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}`,
|
|
657
657
|
),
|
|
658
658
|
},
|
|
659
659
|
],
|
|
@@ -697,7 +697,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
697
697
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
698
698
|
logger.debug(
|
|
699
699
|
'timeoutStartSubscription',
|
|
700
|
-
JSON.stringify({ query, variables })
|
|
700
|
+
JSON.stringify({ query, variables }),
|
|
701
701
|
);
|
|
702
702
|
}
|
|
703
703
|
}
|
|
@@ -785,7 +785,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
785
785
|
await jitteredExponentialRetry(
|
|
786
786
|
this._initializeHandshake.bind(this),
|
|
787
787
|
[awsRealTimeUrl],
|
|
788
|
-
MAX_DELAY_MS
|
|
788
|
+
MAX_DELAY_MS,
|
|
789
789
|
);
|
|
790
790
|
}
|
|
791
791
|
|
|
@@ -827,7 +827,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
827
827
|
return;
|
|
828
828
|
}
|
|
829
829
|
logger.debug(
|
|
830
|
-
`subscription message from AWS AppSyncRealTime: ${message.data}
|
|
830
|
+
`subscription message from AWS AppSyncRealTime: ${message.data} `,
|
|
831
831
|
);
|
|
832
832
|
const data = JSON.parse(message.data) as ParsedMessagePayload;
|
|
833
833
|
const {
|
|
@@ -874,12 +874,12 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
874
874
|
const checkAckOk = (ackOk: boolean) => {
|
|
875
875
|
if (!ackOk) {
|
|
876
876
|
this.connectionStateMonitor.record(
|
|
877
|
-
CONNECTION_CHANGE.CONNECTION_FAILED
|
|
877
|
+
CONNECTION_CHANGE.CONNECTION_FAILED,
|
|
878
878
|
);
|
|
879
879
|
rej(
|
|
880
880
|
new Error(
|
|
881
|
-
`Connection timeout: ack from AWSAppSyncRealTime was not received after ${CONNECTION_INIT_TIMEOUT} ms
|
|
882
|
-
)
|
|
881
|
+
`Connection timeout: ack from AWSAppSyncRealTime was not received after ${CONNECTION_INIT_TIMEOUT} ms`,
|
|
882
|
+
),
|
|
883
883
|
);
|
|
884
884
|
}
|
|
885
885
|
};
|
|
@@ -1010,7 +1010,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
1010
1010
|
credentials: creds!,
|
|
1011
1011
|
signingRegion: endpointInfo.region!,
|
|
1012
1012
|
signingService: endpointInfo.service,
|
|
1013
|
-
}
|
|
1013
|
+
},
|
|
1014
1014
|
);
|
|
1015
1015
|
return signed_params.headers;
|
|
1016
1016
|
}
|
|
@@ -579,8 +579,6 @@ export function generateGraphQLDocument(
|
|
|
579
579
|
);
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
-
console.log('indexQueryArgs', indexQueryArgs!);
|
|
583
|
-
|
|
584
582
|
let graphQLOperationType: 'mutation' | 'query' | 'subscription' | undefined;
|
|
585
583
|
let graphQLSelectionSet: string | undefined;
|
|
586
584
|
let graphQLArguments: Record<string, any> | undefined;
|
|
@@ -613,10 +611,10 @@ export function generateGraphQLDocument(
|
|
|
613
611
|
return acc;
|
|
614
612
|
},
|
|
615
613
|
{},
|
|
616
|
-
|
|
614
|
+
)
|
|
617
615
|
: {
|
|
618
616
|
[primaryKeyFieldName]: `${fields[primaryKeyFieldName].type}!`,
|
|
619
|
-
|
|
617
|
+
});
|
|
620
618
|
graphQLSelectionSet ?? (graphQLSelectionSet = selectionSetFields);
|
|
621
619
|
case 'LIST':
|
|
622
620
|
graphQLArguments ??
|
|
@@ -660,13 +658,13 @@ export function generateGraphQLDocument(
|
|
|
660
658
|
graphQLArguments
|
|
661
659
|
? `(${Object.entries(graphQLArguments).map(
|
|
662
660
|
([fieldName, type]) => `\$${fieldName}: ${type}`,
|
|
663
|
-
|
|
661
|
+
)})`
|
|
664
662
|
: ''
|
|
665
663
|
} { ${graphQLFieldName}${
|
|
666
664
|
graphQLArguments
|
|
667
665
|
? `(${Object.keys(graphQLArguments).map(
|
|
668
666
|
fieldName => `${fieldName}: \$${fieldName}`,
|
|
669
|
-
|
|
667
|
+
)})`
|
|
670
668
|
: ''
|
|
671
669
|
} { ${graphQLSelectionSet} } }`;
|
|
672
670
|
|
|
@@ -716,7 +714,7 @@ export function buildGraphQLVariables(
|
|
|
716
714
|
|
|
717
715
|
return !isReadOnly;
|
|
718
716
|
}),
|
|
719
|
-
|
|
717
|
+
)
|
|
720
718
|
: {},
|
|
721
719
|
};
|
|
722
720
|
break;
|
|
@@ -732,7 +730,7 @@ export function buildGraphQLVariables(
|
|
|
732
730
|
return acc;
|
|
733
731
|
},
|
|
734
732
|
{},
|
|
735
|
-
|
|
733
|
+
)
|
|
736
734
|
: { [primaryKeyFieldName]: arg[primaryKeyFieldName] };
|
|
737
735
|
}
|
|
738
736
|
|
|
@@ -30,12 +30,12 @@ export function getFactory(
|
|
|
30
30
|
modelIntrospection: ModelIntrospectionSchema,
|
|
31
31
|
model: SchemaModel,
|
|
32
32
|
operation: ModelOperation,
|
|
33
|
-
useContext = false
|
|
33
|
+
useContext = false,
|
|
34
34
|
) {
|
|
35
35
|
const getWithContext = async (
|
|
36
36
|
contextSpec: AmplifyServer.ContextSpec & GraphQLOptionsV6<unknown, string>,
|
|
37
37
|
arg?: any,
|
|
38
|
-
options?: any
|
|
38
|
+
options?: any,
|
|
39
39
|
) => {
|
|
40
40
|
return _get(
|
|
41
41
|
client,
|
|
@@ -44,7 +44,7 @@ export function getFactory(
|
|
|
44
44
|
arg,
|
|
45
45
|
options,
|
|
46
46
|
operation,
|
|
47
|
-
contextSpec
|
|
47
|
+
contextSpec,
|
|
48
48
|
);
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -62,7 +62,7 @@ async function _get(
|
|
|
62
62
|
arg: QueryArgs,
|
|
63
63
|
options: AuthModeParams & ListArgs,
|
|
64
64
|
operation: ModelOperation,
|
|
65
|
-
context?: AmplifyServer.ContextSpec
|
|
65
|
+
context?: AmplifyServer.ContextSpec,
|
|
66
66
|
) {
|
|
67
67
|
const { name } = model;
|
|
68
68
|
|
|
@@ -70,13 +70,13 @@ async function _get(
|
|
|
70
70
|
modelIntrospection.models,
|
|
71
71
|
name,
|
|
72
72
|
operation,
|
|
73
|
-
options
|
|
73
|
+
options,
|
|
74
74
|
);
|
|
75
75
|
const variables = buildGraphQLVariables(
|
|
76
76
|
model,
|
|
77
77
|
operation,
|
|
78
78
|
arg,
|
|
79
|
-
modelIntrospection
|
|
79
|
+
modelIntrospection,
|
|
80
80
|
);
|
|
81
81
|
|
|
82
82
|
try {
|
|
@@ -92,16 +92,16 @@ async function _get(
|
|
|
92
92
|
query,
|
|
93
93
|
variables,
|
|
94
94
|
},
|
|
95
|
-
headers
|
|
96
|
-
|
|
95
|
+
headers,
|
|
96
|
+
)) as GraphQLResult<any>)
|
|
97
97
|
: ((await (client as V6Client<Record<string, any>>).graphql(
|
|
98
98
|
{
|
|
99
99
|
...auth,
|
|
100
100
|
query,
|
|
101
101
|
variables,
|
|
102
102
|
},
|
|
103
|
-
headers
|
|
104
|
-
|
|
103
|
+
headers,
|
|
104
|
+
)) as GraphQLResult<any>);
|
|
105
105
|
|
|
106
106
|
// flatten response
|
|
107
107
|
if (data) {
|
|
@@ -119,7 +119,7 @@ async function _get(
|
|
|
119
119
|
modelIntrospection,
|
|
120
120
|
auth.authMode,
|
|
121
121
|
auth.authToken,
|
|
122
|
-
!!context
|
|
122
|
+
!!context,
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
return { data: initialized, extensions };
|
|
@@ -26,11 +26,11 @@ export function listFactory(
|
|
|
26
26
|
client: ClientWithModels,
|
|
27
27
|
modelIntrospection: ModelIntrospectionSchema,
|
|
28
28
|
model: SchemaModel,
|
|
29
|
-
context = false
|
|
29
|
+
context = false,
|
|
30
30
|
) {
|
|
31
31
|
const listWithContext = async (
|
|
32
32
|
contextSpec: AmplifyServer.ContextSpec,
|
|
33
|
-
args?: ListArgs
|
|
33
|
+
args?: ListArgs,
|
|
34
34
|
) => {
|
|
35
35
|
return _list(client, modelIntrospection, model, args, contextSpec);
|
|
36
36
|
};
|
|
@@ -47,7 +47,7 @@ async function _list(
|
|
|
47
47
|
modelIntrospection: ModelIntrospectionSchema,
|
|
48
48
|
model: SchemaModel,
|
|
49
49
|
args?: ListArgs & AuthModeParams,
|
|
50
|
-
contextSpec?: AmplifyServer.ContextSpec
|
|
50
|
+
contextSpec?: AmplifyServer.ContextSpec,
|
|
51
51
|
) {
|
|
52
52
|
const { name } = model;
|
|
53
53
|
|
|
@@ -55,13 +55,13 @@ async function _list(
|
|
|
55
55
|
modelIntrospection.models,
|
|
56
56
|
name,
|
|
57
57
|
'LIST',
|
|
58
|
-
args
|
|
58
|
+
args,
|
|
59
59
|
);
|
|
60
60
|
const variables = buildGraphQLVariables(
|
|
61
61
|
model,
|
|
62
62
|
'LIST',
|
|
63
63
|
args,
|
|
64
|
-
modelIntrospection
|
|
64
|
+
modelIntrospection,
|
|
65
65
|
);
|
|
66
66
|
|
|
67
67
|
try {
|
|
@@ -77,16 +77,16 @@ async function _list(
|
|
|
77
77
|
query,
|
|
78
78
|
variables,
|
|
79
79
|
},
|
|
80
|
-
headers
|
|
81
|
-
|
|
80
|
+
headers,
|
|
81
|
+
)) as GraphQLResult<any>)
|
|
82
82
|
: ((await (client as V6Client<Record<string, any>>).graphql(
|
|
83
83
|
{
|
|
84
84
|
...auth,
|
|
85
85
|
query,
|
|
86
86
|
variables,
|
|
87
87
|
},
|
|
88
|
-
headers
|
|
89
|
-
|
|
88
|
+
headers,
|
|
89
|
+
)) as GraphQLResult<any>);
|
|
90
90
|
|
|
91
91
|
// flatten response
|
|
92
92
|
if (data !== undefined) {
|
|
@@ -110,7 +110,7 @@ async function _list(
|
|
|
110
110
|
modelIntrospection,
|
|
111
111
|
auth.authMode,
|
|
112
112
|
auth.authToken,
|
|
113
|
-
!!contextSpec
|
|
113
|
+
!!contextSpec,
|
|
114
114
|
);
|
|
115
115
|
|
|
116
116
|
return {
|
|
@@ -20,7 +20,7 @@ export function subscriptionFactory(
|
|
|
20
20
|
client: any,
|
|
21
21
|
modelIntrospection: ModelIntrospectionSchema,
|
|
22
22
|
model: SchemaModel,
|
|
23
|
-
operation: ModelOperation
|
|
23
|
+
operation: ModelOperation,
|
|
24
24
|
) {
|
|
25
25
|
const { name } = model as any;
|
|
26
26
|
|
|
@@ -28,13 +28,13 @@ export function subscriptionFactory(
|
|
|
28
28
|
const query = generateGraphQLDocument(
|
|
29
29
|
modelIntrospection.models,
|
|
30
30
|
name,
|
|
31
|
-
operation
|
|
31
|
+
operation,
|
|
32
32
|
);
|
|
33
33
|
const variables = buildGraphQLVariables(
|
|
34
34
|
model,
|
|
35
35
|
operation,
|
|
36
36
|
args,
|
|
37
|
-
modelIntrospection
|
|
37
|
+
modelIntrospection,
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
const auth = authModeParams(client, args);
|
|
@@ -47,7 +47,7 @@ export function subscriptionFactory(
|
|
|
47
47
|
query,
|
|
48
48
|
variables,
|
|
49
49
|
},
|
|
50
|
-
headers
|
|
50
|
+
headers,
|
|
51
51
|
) as GraphqlSubscriptionResult<object>;
|
|
52
52
|
|
|
53
53
|
return observable.pipe(
|
|
@@ -60,10 +60,10 @@ export function subscriptionFactory(
|
|
|
60
60
|
[data],
|
|
61
61
|
modelIntrospection,
|
|
62
62
|
auth.authMode,
|
|
63
|
-
auth.authToken
|
|
63
|
+
auth.authToken,
|
|
64
64
|
);
|
|
65
65
|
return initialized;
|
|
66
|
-
})
|
|
66
|
+
}),
|
|
67
67
|
);
|
|
68
68
|
};
|
|
69
69
|
|
|
@@ -30,7 +30,7 @@ export function generateClientWithAmplifyInstance<
|
|
|
30
30
|
| V6ClientSSRRequest<T>
|
|
31
31
|
| V6ClientSSRCookies<T> = V6ClientSSRCookies<T>,
|
|
32
32
|
>(
|
|
33
|
-
params: ServerClientGenerationParams & CommonPublicClientOptions
|
|
33
|
+
params: ServerClientGenerationParams & CommonPublicClientOptions,
|
|
34
34
|
): ClientType {
|
|
35
35
|
const client = {
|
|
36
36
|
[__amplify]: params.amplify,
|
package/src/internals/v6.ts
CHANGED
|
@@ -101,12 +101,12 @@ export function graphql<
|
|
|
101
101
|
>(
|
|
102
102
|
this: V6Client,
|
|
103
103
|
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
104
|
-
additionalHeaders?: CustomHeaders
|
|
104
|
+
additionalHeaders?: CustomHeaders,
|
|
105
105
|
): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING> {
|
|
106
|
-
// inject client-level auth
|
|
106
|
+
// inject client-level auth
|
|
107
107
|
options.authMode = options.authMode || this[__authMode];
|
|
108
108
|
options.authToken = options.authToken || this[__authToken];
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
/**
|
|
111
111
|
* The correctness of these typings depends on correct string branding or overrides.
|
|
112
112
|
* Neither of these can actually be validated at runtime. Hence, we don't perform
|
|
@@ -115,7 +115,7 @@ export function graphql<
|
|
|
115
115
|
const result = GraphQLAPI.graphql(
|
|
116
116
|
this[__amplify],
|
|
117
117
|
options,
|
|
118
|
-
additionalHeaders
|
|
118
|
+
additionalHeaders,
|
|
119
119
|
);
|
|
120
120
|
return result as any;
|
|
121
121
|
}
|
|
@@ -128,7 +128,7 @@ export function graphql<
|
|
|
128
128
|
export function cancel(
|
|
129
129
|
this: V6Client,
|
|
130
130
|
promise: Promise<any>,
|
|
131
|
-
message?: string
|
|
131
|
+
message?: string,
|
|
132
132
|
): boolean {
|
|
133
133
|
return GraphQLAPI.cancel(promise, message);
|
|
134
134
|
}
|
|
@@ -52,13 +52,13 @@ export function generateClient<T extends Record<any, any> = never>({
|
|
|
52
52
|
const wrappedGraphql = (
|
|
53
53
|
contextSpec: AmplifyServer.ContextSpec,
|
|
54
54
|
options: GraphQLOptionsV6,
|
|
55
|
-
additionalHeaders?: CustomHeaders
|
|
55
|
+
additionalHeaders?: CustomHeaders,
|
|
56
56
|
) => {
|
|
57
57
|
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
|
|
58
58
|
return prevGraphql.call(
|
|
59
59
|
{ [__amplify]: amplifyInstance },
|
|
60
60
|
options,
|
|
61
|
-
additionalHeaders as any
|
|
61
|
+
additionalHeaders as any,
|
|
62
62
|
);
|
|
63
63
|
};
|
|
64
64
|
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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 {
|
|
4
|
+
import {
|
|
5
|
+
ModelTypes,
|
|
6
|
+
CustomHeaders,
|
|
7
|
+
EnumTypes,
|
|
8
|
+
} from '@aws-amplify/data-schema-types';
|
|
5
9
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
6
10
|
export { OperationTypeNode } from 'graphql';
|
|
7
11
|
import { Observable } from 'rxjs';
|
|
@@ -72,7 +76,7 @@ export type GraphQLSubscription<T> = T & {
|
|
|
72
76
|
export type GraphQLReturnType<T> = T extends {}
|
|
73
77
|
? {
|
|
74
78
|
[K in keyof T]?: GraphQLReturnType<T[K]>;
|
|
75
|
-
|
|
79
|
+
}
|
|
76
80
|
: T;
|
|
77
81
|
|
|
78
82
|
/**
|
|
@@ -93,13 +97,14 @@ type PagedList<T, TYPENAME> = {
|
|
|
93
97
|
* array, this will only be the case when we also have errors,
|
|
94
98
|
* which will then be *thrown*.
|
|
95
99
|
*/
|
|
96
|
-
type WithListsFixed<T> =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
type WithListsFixed<T> =
|
|
101
|
+
T extends PagedList<infer IT, infer NAME>
|
|
102
|
+
? PagedList<Exclude<IT, null | undefined>, NAME>
|
|
103
|
+
: T extends {}
|
|
104
|
+
? {
|
|
105
|
+
[K in keyof T]: WithListsFixed<T[K]>;
|
|
106
|
+
}
|
|
107
|
+
: T;
|
|
103
108
|
|
|
104
109
|
/**
|
|
105
110
|
* Returns an updated response type to always return a value.
|
|
@@ -115,14 +120,12 @@ type NeverEmpty<T> = {
|
|
|
115
120
|
* If empty members are present, there will also be errors present,
|
|
116
121
|
* and the response will instead be *thrown*.
|
|
117
122
|
*/
|
|
118
|
-
type FixedQueryResult<T> =
|
|
119
|
-
T[keyof T],
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
: T;
|
|
123
|
+
type FixedQueryResult<T> =
|
|
124
|
+
Exclude<T[keyof T], null | undefined> extends PagedList<any, any>
|
|
125
|
+
? {
|
|
126
|
+
[K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
|
|
127
|
+
}
|
|
128
|
+
: T;
|
|
126
129
|
|
|
127
130
|
/**
|
|
128
131
|
* The return value from a `graphql({query})` call when `query` is a subscription.
|
|
@@ -181,7 +184,7 @@ export interface AWSAppSyncRealTimeProviderOptions {
|
|
|
181
184
|
|
|
182
185
|
export type AWSAppSyncRealTimeProvider = {
|
|
183
186
|
subscribe(
|
|
184
|
-
options?: AWSAppSyncRealTimeProviderOptions
|
|
187
|
+
options?: AWSAppSyncRealTimeProviderOptions,
|
|
185
188
|
): Observable<Record<string, unknown>>;
|
|
186
189
|
};
|
|
187
190
|
|
|
@@ -235,15 +238,16 @@ export type UnknownGraphQLResponse =
|
|
|
235
238
|
export type GraphQLVariablesV6<
|
|
236
239
|
FALLBACK_TYPES = unknown,
|
|
237
240
|
TYPED_GQL_STRING extends string = string,
|
|
238
|
-
> =
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
> =
|
|
242
|
+
TYPED_GQL_STRING extends GeneratedQuery<infer IN, any>
|
|
243
|
+
? IN
|
|
244
|
+
: TYPED_GQL_STRING extends GeneratedMutation<infer IN, any>
|
|
245
|
+
? IN
|
|
246
|
+
: TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any>
|
|
247
|
+
? IN
|
|
248
|
+
: FALLBACK_TYPES extends GraphQLOperationType<infer IN, any>
|
|
249
|
+
? IN
|
|
250
|
+
: any;
|
|
247
251
|
|
|
248
252
|
/**
|
|
249
253
|
* The expected return type with respect to the given `FALLBACK_TYPE`
|
|
@@ -252,22 +256,23 @@ export type GraphQLVariablesV6<
|
|
|
252
256
|
export type GraphQLResponseV6<
|
|
253
257
|
FALLBACK_TYPE = unknown,
|
|
254
258
|
TYPED_GQL_STRING extends string = string,
|
|
255
|
-
> =
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
259
|
+
> =
|
|
260
|
+
TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
|
|
261
|
+
? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
|
|
262
|
+
: TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
|
|
263
|
+
? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
|
|
264
|
+
: TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
|
|
265
|
+
? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
|
|
266
|
+
: FALLBACK_TYPE extends GraphQLQuery<infer T>
|
|
267
|
+
? Promise<GraphQLResult<FALLBACK_TYPE>>
|
|
268
|
+
: FALLBACK_TYPE extends GraphQLSubscription<infer T>
|
|
269
|
+
? GraphqlSubscriptionResult<FALLBACK_TYPE>
|
|
270
|
+
: FALLBACK_TYPE extends GraphQLOperationType<
|
|
271
|
+
infer IN,
|
|
272
|
+
infer CUSTOM_OUT
|
|
273
|
+
>
|
|
274
|
+
? CUSTOM_OUT
|
|
275
|
+
: UnknownGraphQLResponse;
|
|
271
276
|
|
|
272
277
|
/**
|
|
273
278
|
* The shape customers can use to provide `T` to `graphql<T>()` to specify both
|
|
@@ -414,7 +419,7 @@ export type GraphQLMethod = <
|
|
|
414
419
|
TYPED_GQL_STRING extends string = string,
|
|
415
420
|
>(
|
|
416
421
|
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
417
|
-
additionalHeaders?: CustomHeaders | undefined
|
|
422
|
+
additionalHeaders?: CustomHeaders | undefined,
|
|
418
423
|
) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
419
424
|
|
|
420
425
|
export type GraphQLMethodSSR = <
|
|
@@ -423,7 +428,7 @@ export type GraphQLMethodSSR = <
|
|
|
423
428
|
>(
|
|
424
429
|
contextSpec: AmplifyServer.ContextSpec,
|
|
425
430
|
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
426
|
-
additionalHeaders?: CustomHeaders | undefined
|
|
431
|
+
additionalHeaders?: CustomHeaders | undefined,
|
|
427
432
|
) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
428
433
|
|
|
429
434
|
/**
|