@aws-amplify/api-graphql 4.0.1-server-generate-client.1e317a1.0 → 4.0.1-ssr-api.df60e41.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 (91) hide show
  1. package/lib/GraphQLAPI.d.ts +1 -1
  2. package/lib/GraphQLAPI.js +25 -30
  3. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
  4. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +468 -584
  5. package/lib/Providers/constants.js +4 -5
  6. package/lib/index.js +5 -6
  7. package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
  8. package/lib/internals/InternalGraphQLAPI.js +203 -263
  9. package/lib/internals/index.d.ts +0 -1
  10. package/lib/internals/index.js +5 -8
  11. package/lib/internals/v6.js +3 -4
  12. package/lib/tsconfig.tsbuildinfo +6798 -1
  13. package/lib/types/PubSub.d.ts +2 -2
  14. package/lib/types/PubSub.js +2 -3
  15. package/lib/types/index.d.ts +39 -28
  16. package/lib/types/index.js +3 -4
  17. package/lib/utils/ConnectionStateMonitor.d.ts +3 -3
  18. package/lib/utils/ConnectionStateMonitor.js +51 -65
  19. package/lib/utils/ReachabilityMonitor/index.d.ts +1 -1
  20. package/lib/utils/ReachabilityMonitor/index.js +2 -4
  21. package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -1
  22. package/lib/utils/ReachabilityMonitor/index.native.js +4 -8
  23. package/lib/utils/ReconnectionMonitor.js +21 -26
  24. package/lib/utils/errors/APIError.js +7 -12
  25. package/lib/utils/errors/assertValidationError.js +4 -5
  26. package/lib/utils/errors/index.js +4 -5
  27. package/lib/utils/errors/validation.js +6 -8
  28. package/lib/utils/index.js +2 -3
  29. package/lib/utils/resolveConfig.d.ts +1 -1
  30. package/lib/utils/resolveConfig.js +10 -13
  31. package/lib/utils/resolveLibraryOptions.d.ts +1 -1
  32. package/lib/utils/resolveLibraryOptions.js +4 -7
  33. package/lib-esm/GraphQLAPI.d.ts +1 -1
  34. package/lib-esm/GraphQLAPI.js +25 -29
  35. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
  36. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
  37. package/lib-esm/Providers/constants.js +10 -10
  38. package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
  39. package/lib-esm/internals/InternalGraphQLAPI.js +197 -256
  40. package/lib-esm/internals/index.d.ts +0 -1
  41. package/lib-esm/internals/index.js +0 -1
  42. package/lib-esm/internals/v6.js +1 -1
  43. package/lib-esm/tsconfig.tsbuildinfo +6798 -1
  44. package/lib-esm/types/PubSub.d.ts +2 -2
  45. package/lib-esm/types/index.d.ts +39 -28
  46. package/lib-esm/types/index.js +1 -1
  47. package/lib-esm/utils/ConnectionStateMonitor.d.ts +3 -3
  48. package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
  49. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -1
  50. package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
  51. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -1
  52. package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
  53. package/lib-esm/utils/ReconnectionMonitor.js +19 -24
  54. package/lib-esm/utils/errors/APIError.js +6 -11
  55. package/lib-esm/utils/errors/assertValidationError.js +2 -2
  56. package/lib-esm/utils/errors/validation.js +5 -6
  57. package/lib-esm/utils/resolveConfig.d.ts +1 -1
  58. package/lib-esm/utils/resolveConfig.js +8 -9
  59. package/lib-esm/utils/resolveLibraryOptions.d.ts +1 -1
  60. package/lib-esm/utils/resolveLibraryOptions.js +4 -5
  61. package/package.json +6 -12
  62. package/src/GraphQLAPI.ts +6 -1
  63. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
  64. package/src/internals/InternalGraphQLAPI.ts +7 -8
  65. package/src/internals/index.ts +0 -1
  66. package/src/types/index.ts +39 -15
  67. package/lib/internals/APIClient.d.ts +0 -101
  68. package/lib/internals/APIClient.js +0 -443
  69. package/lib/internals/generateClient.d.ts +0 -12
  70. package/lib/internals/generateClient.js +0 -30
  71. package/lib/internals/generateModelsProperty.d.ts +0 -4
  72. package/lib/internals/generateModelsProperty.js +0 -169
  73. package/lib/internals/types.d.ts +0 -10
  74. package/lib/internals/types.js +0 -2
  75. package/lib/utils/resolveOwnerFields.d.ts +0 -12
  76. package/lib/utils/resolveOwnerFields.js +0 -63
  77. package/lib-esm/internals/APIClient.d.ts +0 -101
  78. package/lib-esm/internals/APIClient.js +0 -432
  79. package/lib-esm/internals/generateClient.d.ts +0 -12
  80. package/lib-esm/internals/generateClient.js +0 -26
  81. package/lib-esm/internals/generateModelsProperty.d.ts +0 -4
  82. package/lib-esm/internals/generateModelsProperty.js +0 -165
  83. package/lib-esm/internals/types.d.ts +0 -10
  84. package/lib-esm/internals/types.js +0 -1
  85. package/lib-esm/utils/resolveOwnerFields.d.ts +0 -12
  86. package/lib-esm/utils/resolveOwnerFields.js +0 -59
  87. package/src/internals/APIClient.ts +0 -583
  88. package/src/internals/generateClient.ts +0 -30
  89. package/src/internals/generateModelsProperty.ts +0 -192
  90. package/src/internals/types.ts +0 -15
  91. package/src/utils/resolveOwnerFields.ts +0 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.0.1-server-generate-client.1e317a1.0+1e317a1",
3
+ "version": "4.0.1-ssr-api.df60e41.0+df60e41",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -40,10 +40,6 @@
40
40
  "url": "https://github.com/aws/aws-amplify/issues"
41
41
  },
42
42
  "homepage": "https://aws-amplify.github.io/",
43
- "devDependencies": {
44
- "@aws-amplify/amplify-api-next-alpha": "^0.6.0",
45
- "typescript": "5.1.6"
46
- },
47
43
  "files": [
48
44
  "lib",
49
45
  "lib-esm",
@@ -51,15 +47,13 @@
51
47
  "internals"
52
48
  ],
53
49
  "dependencies": {
54
- "@aws-amplify/amplify-api-next-types-alpha": "^0.2.0",
55
- "@aws-amplify/api-rest": "4.0.1-server-generate-client.1e317a1.0+1e317a1",
56
- "@aws-amplify/auth": "6.0.1-server-generate-client.1e317a1.0+1e317a1",
57
- "@aws-amplify/core": "6.0.1-server-generate-client.1e317a1.0+1e317a1",
50
+ "@aws-amplify/api-rest": "4.0.1-ssr-api.df60e41.0+df60e41",
51
+ "@aws-amplify/auth": "6.0.1-ssr-api.df60e41.0+df60e41",
52
+ "@aws-amplify/core": "6.0.1-ssr-api.df60e41.0+df60e41",
58
53
  "@aws-sdk/types": "3.387.0",
59
54
  "graphql": "15.8.0",
60
55
  "rxjs": "^7.8.1",
61
- "tslib": "^2.6.1",
62
- "url": "0.11.0"
56
+ "tslib": "^2.5.0"
63
57
  },
64
58
  "size-limit": [
65
59
  {
@@ -126,5 +120,5 @@
126
120
  "<rootDir>/__tests__"
127
121
  ]
128
122
  },
129
- "gitHead": "1e317a10a7a7e980919b0d78e397bcff1461fec5"
123
+ "gitHead": "df60e41fbc70bd6277162b7780b3fc030c93c6a0"
130
124
  }
package/src/GraphQLAPI.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 } from '@aws-amplify/core';
4
+ import { Category, ApiAction } from '@aws-amplify/core/internals/utils';
4
5
  import { GraphQLOptions, GraphQLResult } from './types';
5
6
  import { InternalGraphQLAPIClass } from './internals';
6
7
  import { Observable } from 'rxjs';
@@ -32,10 +33,14 @@ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
32
33
  */
33
34
  graphql<T = any>(
34
35
  amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>),
36
+ // amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>),
35
37
  options: GraphQLOptions,
36
38
  additionalHeaders?: { [key: string]: string }
37
39
  ): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
38
- return super.graphql(amplify, options, additionalHeaders);
40
+ return super.graphql(amplify, options, additionalHeaders, {
41
+ category: Category.API,
42
+ action: ApiAction.GraphQl,
43
+ });
39
44
  }
40
45
 
41
46
  /**
@@ -2,11 +2,10 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Observable, SubscriptionLike } from 'rxjs';
4
4
  import { GraphQLError } from 'graphql';
5
- import * as url from 'url';
6
- import { Buffer } from 'buffer';
7
5
  import { Hub, fetchAuthSession, ConsoleLogger } from '@aws-amplify/core';
8
6
  import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
9
7
  import {
8
+ base64Encoder,
10
9
  GraphQLAuthMode,
11
10
  CustomUserAgentDetails,
12
11
  NonRetryableError,
@@ -700,9 +699,9 @@ export class AWSAppSyncRealTimeProvider {
700
699
  });
701
700
 
702
701
  const headerString = authHeader ? JSON.stringify(authHeader) : '';
703
- const headerQs = Buffer.from(headerString).toString('base64');
702
+ const headerQs = base64Encoder.convert(headerString);
704
703
 
705
- const payloadQs = Buffer.from(payloadString).toString('base64');
704
+ const payloadQs = base64Encoder.convert(payloadString);
706
705
 
707
706
  let discoverableEndpoint = appSyncGraphqlEndpoint ?? '';
708
707
 
@@ -900,7 +899,9 @@ export class AWSAppSyncRealTimeProvider {
900
899
  } else {
901
900
  const handler = headerHandler[authenticationType];
902
901
 
903
- const { host } = url.parse(appSyncGraphqlEndpoint ?? '');
902
+ const host = appSyncGraphqlEndpoint
903
+ ? new AmplifyUrl(appSyncGraphqlEndpoint).host
904
+ : undefined;
904
905
 
905
906
  logger.debug(`Authenticating with ${JSON.stringify(authenticationType)}`);
906
907
  let resolvedApiKey;
@@ -46,10 +46,7 @@ export const graphqlOperation = (
46
46
  });
47
47
 
48
48
  const isAmplifyInstance = (amplify): amplify is AmplifyClassV6 => {
49
- if (typeof amplify !== 'function') {
50
- return true;
51
- }
52
- return false;
49
+ return typeof amplify !== 'function';
53
50
  };
54
51
 
55
52
  /**
@@ -200,7 +197,7 @@ export class InternalGraphQLAPIClass {
200
197
  case 'mutation':
201
198
  const abortController = new AbortController();
202
199
 
203
- let responsePromise;
200
+ let responsePromise: Promise<GraphQLResult<T>>;
204
201
 
205
202
  if (isAmplifyInstance(amplify)) {
206
203
  responsePromise = this._graphql<T>(
@@ -220,7 +217,9 @@ export class InternalGraphQLAPIClass {
220
217
  customUserAgentDetails
221
218
  );
222
219
 
223
- responsePromise = amplify(wrapper);
220
+ responsePromise = amplify(wrapper) as unknown as Promise<
221
+ GraphQLResult<T>
222
+ >;
224
223
  }
225
224
 
226
225
  this._api.updateRequestToBeCancellable(
@@ -347,7 +346,7 @@ export class InternalGraphQLAPIClass {
347
346
  // If the exception is because user intentionally
348
347
  // cancelled the request, do not modify the exception
349
348
  // so that clients can identify the exception correctly.
350
- if (this._api.isCancelErrorREST(err)) {
349
+ if (this.isCancelError(err)) {
351
350
  throw err;
352
351
  }
353
352
 
@@ -401,7 +400,7 @@ export class InternalGraphQLAPIClass {
401
400
  variables,
402
401
  appSyncGraphqlEndpoint: config?.endpoint,
403
402
  region: config?.region,
404
- authenticationType: config?.defaultAuthMode,
403
+ authenticationType: authMode ?? config?.defaultAuthMode,
405
404
  apiKey: config?.apiKey,
406
405
  additionalHeaders,
407
406
  },
@@ -6,4 +6,3 @@ export {
6
6
  } from './InternalGraphQLAPI';
7
7
 
8
8
  export { graphql, cancel, isCancelError } from './v6';
9
- export { generateClient } from './generateClient';
@@ -1,7 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyClassV6 } from '@aws-amplify/core';
4
- import { ModelTypes } from '@aws-amplify/amplify-api-next-types-alpha';
5
4
  import { Source, DocumentNode, GraphQLError } from 'graphql';
6
5
  export { OperationTypeNode } from 'graphql';
7
6
  import { Observable } from 'rxjs';
@@ -10,10 +9,8 @@ import {
10
9
  GraphQLAuthMode,
11
10
  DocumentType,
12
11
  } from '@aws-amplify/core/internals/utils';
12
+ import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
13
13
  export { CONTROL_MSG, ConnectionState } from './PubSub';
14
-
15
- export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
16
-
17
14
  /**
18
15
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
19
16
  */
@@ -351,24 +348,51 @@ export type GeneratedSubscription<InputType, OutputType> = string & {
351
348
  type FilteredKeys<T> = {
352
349
  [P in keyof T]: T[P] extends never ? never : P;
353
350
  }[keyof T];
354
-
355
351
  type ExcludeNeverFields<O> = {
356
352
  [K in FilteredKeys<O>]: O[K];
357
353
  };
358
354
 
359
355
  export const __amplify = Symbol('amplify');
360
356
 
357
+ /**
358
+ * TODO: Refactor these 2. Pull out `graphQL` into its own type
359
+ */
361
360
  export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
362
- [__amplify]: AmplifyClassV6 | (() => Promise<AmplifyClassV6>);
363
- graphql: <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(
364
- options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
365
- additionalHeaders?:
366
- | {
367
- [key: string]: string;
368
- }
369
- | undefined
370
- ) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
361
+ [__amplify]: AmplifyClassV6;
362
+ graphql: GraphQLMethod;
371
363
  cancel: (promise: Promise<any>, message?: string) => boolean;
372
364
  isCancelError: (error: any) => boolean;
373
- models: ModelTypes<T>;
374
365
  }>;
366
+
367
+ export type V6ClientSSR<T extends Record<any, any> = never> =
368
+ ExcludeNeverFields<{
369
+ [__amplify]: AmplifyClassV6;
370
+ graphql: GraphQLMethodSSR;
371
+ cancel: (promise: Promise<any>, message?: string) => boolean;
372
+ isCancelError: (error: any) => boolean;
373
+ }>;
374
+
375
+ export type GraphQLMethod = <
376
+ FALLBACK_TYPES = unknown,
377
+ TYPED_GQL_STRING extends string = string
378
+ >(
379
+ options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
380
+ additionalHeaders?:
381
+ | {
382
+ [key: string]: string;
383
+ }
384
+ | undefined
385
+ ) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
386
+
387
+ export type GraphQLMethodSSR = <
388
+ FALLBACK_TYPES = unknown,
389
+ TYPED_GQL_STRING extends string = string
390
+ >(
391
+ contextSpec: AmplifyServer.ContextSpec,
392
+ options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
393
+ additionalHeaders?:
394
+ | {
395
+ [key: string]: string;
396
+ }
397
+ | undefined
398
+ ) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
@@ -1,101 +0,0 @@
1
- type ListArgs = {
2
- selectionSet?: string[];
3
- filter?: {};
4
- };
5
- /**
6
- *
7
- * @param GraphQL response object
8
- * @returns response object with `items` properties flattened
9
- */
10
- export declare const flattenItems: (obj: Record<string, any>) => Record<string, any>;
11
- export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any): any[];
12
- export declare const graphQLOperationsInfo: {
13
- CREATE: {
14
- operationPrefix: "create";
15
- usePlural: boolean;
16
- };
17
- READ: {
18
- operationPrefix: "get";
19
- usePlural: boolean;
20
- };
21
- UPDATE: {
22
- operationPrefix: "update";
23
- usePlural: boolean;
24
- };
25
- DELETE: {
26
- operationPrefix: "delete";
27
- usePlural: boolean;
28
- };
29
- LIST: {
30
- operationPrefix: "list";
31
- usePlural: boolean;
32
- };
33
- ONCREATE: {
34
- operationPrefix: "onCreate";
35
- usePlural: boolean;
36
- };
37
- ONUPDATE: {
38
- operationPrefix: "onUpdate";
39
- usePlural: boolean;
40
- };
41
- ONDELETE: {
42
- operationPrefix: "onDelete";
43
- usePlural: boolean;
44
- };
45
- };
46
- export type ModelOperation = keyof typeof graphQLOperationsInfo;
47
- /**
48
- * Generates nested Custom Selection Set IR from path
49
- *
50
- * @param modelIntrospection
51
- * @param modelName
52
- * @param selectionSet - array of object paths
53
- * @example
54
- * ### Given
55
- * `selectionSet = ['id', 'comments.post.id']`
56
- * ### Returns
57
- * ```ts
58
- * {
59
- * id: '',
60
- * comments: {
61
- * items: { post: { id: '' } }
62
- * }
63
- * }
64
- * ```
65
- */
66
- export declare function customSelectionSetToIR(modelIntrospection: any, modelName: string, selectionSet: string[]): Record<string, string | object>;
67
- /**
68
- * Stringifies selection set IR
69
- * * @example
70
- * ### Given
71
- * ```ts
72
- * {
73
- * id: '',
74
- * comments: {
75
- * items: { post: { id: '' } }
76
- * }
77
- * }
78
- * ```
79
- * ### Returns
80
- * `'id comments { items { post { id } } }'`
81
- */
82
- export declare function selectionSetIRToString(obj: Record<string, string | any>): string;
83
- export declare function generateSelectionSet(modelIntrospection: any, modelName: string, selectionSet?: string[]): string;
84
- export declare function generateGraphQLDocument(modelIntrospection: any, modelName: string, modelOperation: ModelOperation, listArgs?: ListArgs): string;
85
- export declare function buildGraphQLVariables(modelDefinition: any, operation: ModelOperation, arg: any, modelIntrospection: any): object;
86
- /**
87
- * Iterates over mutation input values and resolves any model inputs to their corresponding join fields/values
88
- *
89
- * @example
90
- * ### Usage
91
- * ```ts
92
- * const result = normalizeMutationInput({ post: post }, model, modelDefinition);
93
- * ```
94
- * ### Result
95
- * ```ts
96
- * { postId: "abc123" }
97
- * ```
98
- *
99
- */
100
- export declare function normalizeMutationInput(mutationInput: any, model: any, modelDefinition: any): Record<string, unknown>;
101
- export {};