@apollo/client 4.0.0-rc.9 → 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.
Files changed (173) hide show
  1. package/CHANGELOG.md +2476 -0
  2. package/README.md +6 -2
  3. package/__cjs/cache/inmemory/inMemoryCache.cjs +2 -2
  4. package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
  5. package/__cjs/cache/inmemory/policies.cjs +18 -12
  6. package/__cjs/cache/inmemory/policies.cjs.map +1 -1
  7. package/__cjs/core/ObservableQuery.d.cts +1 -1
  8. package/__cjs/core/index.cjs.map +1 -1
  9. package/__cjs/core/index.d.cts +1 -1
  10. package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
  11. package/__cjs/incremental/handlers/defer20220824.d.cts +9 -6
  12. package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
  13. package/__cjs/incremental/handlers/notImplemented.d.cts +11 -0
  14. package/__cjs/link/core/ApolloLink.cjs.map +1 -1
  15. package/__cjs/link/core/ApolloLink.d.cts +5 -2
  16. package/__cjs/link/core/types.d.cts +0 -4
  17. package/__cjs/link/index.cjs.map +1 -1
  18. package/__cjs/link/index.d.cts +2 -1
  19. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +2 -2
  20. package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
  21. package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +2 -2
  22. package/__cjs/local-state/LocalState.cjs.map +1 -1
  23. package/__cjs/masking/GraphQLCodegenDataMasking.d.cts +10 -42
  24. package/__cjs/masking/PreserveTypes.cjs +3 -0
  25. package/__cjs/masking/PreserveTypes.cjs.map +1 -0
  26. package/__cjs/masking/PreserveTypes.d.cts +26 -0
  27. package/__cjs/masking/index.cjs.map +1 -1
  28. package/__cjs/masking/index.d.cts +1 -1
  29. package/__cjs/masking/internal/types.d.cts +0 -1
  30. package/__cjs/masking/types.d.cts +6 -23
  31. package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
  32. package/__cjs/react/hooks/useBackgroundQuery.d.cts +2 -1
  33. package/__cjs/react/hooks/useLazyQuery.d.cts +1 -1
  34. package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
  35. package/__cjs/react/hooks/useLoadableQuery.d.cts +2 -1
  36. package/__cjs/react/hooks/useQuery.d.cts +1 -1
  37. package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
  38. package/__cjs/react/hooks/useQueryRefHandlers.d.cts +2 -1
  39. package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
  40. package/__cjs/react/hooks/useReadQuery.d.cts +1 -1
  41. package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
  42. package/__cjs/react/query-preloader/createQueryPreloader.d.cts +1 -1
  43. package/__cjs/react/types/deprecated.d.cts +1 -1
  44. package/__cjs/react/types/types.documentation.d.cts +1 -1
  45. package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +1 -1
  46. package/__cjs/testing/react/MockedProvider.cjs.map +1 -1
  47. package/__cjs/testing/react/MockedProvider.d.cts +5 -0
  48. package/__cjs/utilities/common/stripTypename.cjs +11 -0
  49. package/__cjs/utilities/common/stripTypename.cjs.map +1 -1
  50. package/__cjs/utilities/common/stripTypename.d.cts +11 -0
  51. package/__cjs/utilities/graphql/DocumentTransform.cjs +84 -1
  52. package/__cjs/utilities/graphql/DocumentTransform.cjs.map +1 -1
  53. package/__cjs/utilities/graphql/DocumentTransform.d.cts +94 -5
  54. package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs +27 -0
  55. package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs.map +1 -1
  56. package/__cjs/utilities/graphql/isFormattedExecutionResult.d.cts +27 -0
  57. package/__cjs/utilities/graphql/operations.cjs +54 -3
  58. package/__cjs/utilities/graphql/operations.cjs.map +1 -1
  59. package/__cjs/utilities/graphql/operations.d.cts +54 -3
  60. package/__cjs/utilities/graphql/storeUtils.cjs +9 -0
  61. package/__cjs/utilities/graphql/storeUtils.cjs.map +1 -1
  62. package/__cjs/utilities/graphql/storeUtils.d.cts +9 -0
  63. package/__cjs/utilities/graphql/transform.cjs +12 -1
  64. package/__cjs/utilities/graphql/transform.cjs.map +1 -1
  65. package/__cjs/utilities/graphql/transform.d.cts +12 -1
  66. package/__cjs/utilities/internal/canonicalStringify.cjs +30 -7
  67. package/__cjs/utilities/internal/canonicalStringify.cjs.map +1 -1
  68. package/__cjs/utilities/internal/canonicalStringify.d.cts +30 -7
  69. package/__cjs/utilities/internal/getMainDefinition.cjs +36 -8
  70. package/__cjs/utilities/internal/getMainDefinition.cjs.map +1 -1
  71. package/__cjs/utilities/internal/getMainDefinition.d.cts +36 -8
  72. package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +1 -1
  73. package/__cjs/v4-migration.cjs +9 -0
  74. package/__cjs/v4-migration.cjs.map +1 -0
  75. package/__cjs/v4-migration.d.cts +826 -0
  76. package/__cjs/version.cjs +1 -1
  77. package/__cjs/version.cjs.map +1 -1
  78. package/cache/inmemory/inMemoryCache.js +2 -2
  79. package/cache/inmemory/inMemoryCache.js.map +1 -1
  80. package/cache/inmemory/policies.js +18 -12
  81. package/cache/inmemory/policies.js.map +1 -1
  82. package/core/ObservableQuery.d.ts +1 -1
  83. package/core/index.d.ts +1 -1
  84. package/core/index.js.map +1 -1
  85. package/incremental/handlers/defer20220824.d.ts +9 -6
  86. package/incremental/handlers/defer20220824.js.map +1 -1
  87. package/incremental/handlers/notImplemented.d.ts +11 -0
  88. package/incremental/handlers/notImplemented.js.map +1 -1
  89. package/legacyEntryPoints/v4-migration/index.d.ts +1 -0
  90. package/legacyEntryPoints/v4-migration/index.js +1 -0
  91. package/legacyEntryPoints/v4-migration/v4-migration.cjs +1 -0
  92. package/legacyEntryPoints/v4-migration/v4-migration.d.cts +1 -0
  93. package/link/core/ApolloLink.d.ts +5 -2
  94. package/link/core/ApolloLink.js.map +1 -1
  95. package/link/core/types.d.ts +0 -4
  96. package/link/core/types.js.map +1 -1
  97. package/link/index.d.ts +2 -1
  98. package/link/index.js.map +1 -1
  99. package/link/remove-typename/removeTypenameFromVariables.d.ts +2 -2
  100. package/link/remove-typename/removeTypenameFromVariables.js +2 -2
  101. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  102. package/local-state/LocalState.js.map +1 -1
  103. package/masking/GraphQLCodegenDataMasking.d.ts +10 -42
  104. package/masking/GraphQLCodegenDataMasking.js.map +1 -1
  105. package/masking/PreserveTypes.d.ts +26 -0
  106. package/masking/PreserveTypes.js +2 -0
  107. package/masking/PreserveTypes.js.map +1 -0
  108. package/masking/index.d.ts +1 -1
  109. package/masking/index.js.map +1 -1
  110. package/masking/internal/types.d.ts +0 -1
  111. package/masking/internal/types.js.map +1 -1
  112. package/masking/types.d.ts +6 -23
  113. package/masking/types.js.map +1 -1
  114. package/package.json +8 -2
  115. package/react/hooks/useBackgroundQuery.d.ts +2 -1
  116. package/react/hooks/useBackgroundQuery.js.map +1 -1
  117. package/react/hooks/useLazyQuery.d.ts +1 -1
  118. package/react/hooks/useLoadableQuery.d.ts +2 -1
  119. package/react/hooks/useLoadableQuery.js.map +1 -1
  120. package/react/hooks/useQuery.d.ts +1 -1
  121. package/react/hooks/useQueryRefHandlers.d.ts +2 -1
  122. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  123. package/react/hooks/useReadQuery.d.ts +1 -1
  124. package/react/hooks/useReadQuery.js.map +1 -1
  125. package/react/hooks-compiled/useBackgroundQuery.d.ts +2 -1
  126. package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
  127. package/react/hooks-compiled/useLazyQuery.d.ts +1 -1
  128. package/react/hooks-compiled/useLoadableQuery.d.ts +2 -1
  129. package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
  130. package/react/hooks-compiled/useQuery.d.ts +1 -1
  131. package/react/hooks-compiled/useQueryRefHandlers.d.ts +2 -1
  132. package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
  133. package/react/hooks-compiled/useReadQuery.d.ts +1 -1
  134. package/react/hooks-compiled/useReadQuery.js.map +1 -1
  135. package/react/query-preloader/createQueryPreloader.d.ts +1 -1
  136. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  137. package/react/types/deprecated.d.ts +1 -1
  138. package/react/types/deprecated.js.map +1 -1
  139. package/react/types/types.documentation.d.ts +1 -1
  140. package/react/types/types.documentation.js.map +1 -1
  141. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  142. package/testing/react/MockedProvider.d.ts +5 -0
  143. package/testing/react/MockedProvider.js.map +1 -1
  144. package/utilities/common/stripTypename.d.ts +11 -0
  145. package/utilities/common/stripTypename.js +11 -0
  146. package/utilities/common/stripTypename.js.map +1 -1
  147. package/utilities/graphql/DocumentTransform.d.ts +94 -5
  148. package/utilities/graphql/DocumentTransform.js +84 -1
  149. package/utilities/graphql/DocumentTransform.js.map +1 -1
  150. package/utilities/graphql/isFormattedExecutionResult.d.ts +27 -0
  151. package/utilities/graphql/isFormattedExecutionResult.js +27 -0
  152. package/utilities/graphql/isFormattedExecutionResult.js.map +1 -1
  153. package/utilities/graphql/operations.d.ts +54 -3
  154. package/utilities/graphql/operations.js +54 -3
  155. package/utilities/graphql/operations.js.map +1 -1
  156. package/utilities/graphql/storeUtils.d.ts +9 -0
  157. package/utilities/graphql/storeUtils.js +9 -0
  158. package/utilities/graphql/storeUtils.js.map +1 -1
  159. package/utilities/graphql/transform.d.ts +12 -1
  160. package/utilities/graphql/transform.js +12 -1
  161. package/utilities/graphql/transform.js.map +1 -1
  162. package/utilities/internal/canonicalStringify.d.ts +30 -7
  163. package/utilities/internal/canonicalStringify.js +30 -7
  164. package/utilities/internal/canonicalStringify.js.map +1 -1
  165. package/utilities/internal/getMainDefinition.d.ts +37 -9
  166. package/utilities/internal/getMainDefinition.js +36 -8
  167. package/utilities/internal/getMainDefinition.js.map +1 -1
  168. package/utilities/internal/types/DocumentationTypes.d.ts +1 -1
  169. package/v4-migration.d.ts +826 -0
  170. package/v4-migration.js +8 -0
  171. package/v4-migration.js.map +1 -0
  172. package/version.js +1 -1
  173. package/version.js.map +1 -1
@@ -3,37 +3,126 @@ export type DocumentTransformCacheKey = ReadonlyArray<unknown>;
3
3
  type TransformFn = (document: DocumentNode) => DocumentNode;
4
4
  interface DocumentTransformOptions {
5
5
  /**
6
- * Determines whether to cache the transformed GraphQL document. Caching can speed up repeated calls to the document transform for the same input document. Set to `false` to completely disable caching for the document transform. When disabled, this option takes precedence over the [`getCacheKey`](#getcachekey) option.
6
+ * Determines whether to cache the transformed GraphQL document. Caching can
7
+ * speed up repeated calls to the document transform for the same input
8
+ * document. Set to `false` to completely disable caching for the document
9
+ * transform. When disabled, this option takes precedence over the [`getCacheKey`](#getcachekey)
10
+ * option.
7
11
  *
8
- * The default value is `true`.
12
+ * @defaultValue `true`
9
13
  */
10
14
  cache?: boolean;
11
15
  /**
12
16
  * Defines a custom cache key for a GraphQL document that will determine whether to re-run the document transform when given the same input GraphQL document. Returns an array that defines the cache key. Return `undefined` to disable caching for that GraphQL document.
13
17
  *
14
- * > **Note:** The items in the array may be any type, but also need to be referentially stable to guarantee a stable cache key.
18
+ * > [!NOTE]
19
+ * > The items in the array can be any type, but each item needs to be
20
+ * > referentially stable to guarantee a stable cache key.
15
21
  *
16
- * The default implementation of this function returns the `document` as the cache key.
22
+ * @defaultValue `(document) => [document]`
17
23
  */
18
24
  getCacheKey?: (document: DocumentNode) => DocumentTransformCacheKey | undefined;
19
25
  }
26
+ /**
27
+ * A class for transforming GraphQL documents. See the [Document transforms
28
+ * documentation](https://www.apollographql.com/docs/react/data/document-transforms) for more details on using them.
29
+ *
30
+ * @example
31
+ *
32
+ * ```ts
33
+ * import { DocumentTransform } from "@apollo/client/utilities";
34
+ * import { visit } from "graphql";
35
+ *
36
+ * const documentTransform = new DocumentTransform((doc) => {
37
+ * return visit(doc, {
38
+ * // ...
39
+ * });
40
+ * });
41
+ *
42
+ * const transformedDoc = documentTransform.transformDocument(myDocument);
43
+ * ```
44
+ */
20
45
  export declare class DocumentTransform {
21
46
  private readonly transform;
22
47
  private cached;
23
48
  private readonly resultCache;
24
49
  private getCacheKey;
50
+ /**
51
+ * Creates a DocumentTransform that returns the input document unchanged.
52
+ *
53
+ * @returns The input document
54
+ */
25
55
  static identity(): DocumentTransform;
56
+ /**
57
+ * Creates a DocumentTransform that conditionally applies one of two transforms.
58
+ *
59
+ * @param predicate - Function that determines which transform to apply
60
+ * @param left - Transform to apply when `predicate` returns `true`
61
+ * @param right - Transform to apply when `predicate` returns `false`. If not provided, it defaults to `DocumentTransform.identity()`.
62
+ * @returns A DocumentTransform that conditionally applies a document transform based on the predicate
63
+ *
64
+ * @example
65
+ *
66
+ * ```ts
67
+ * import { isQueryOperation } from "@apollo/client/utilities";
68
+ *
69
+ * const conditionalTransform = DocumentTransform.split(
70
+ * (document) => isQueryOperation(document),
71
+ * queryTransform,
72
+ * mutationTransform
73
+ * );
74
+ * ```
75
+ */
26
76
  static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & {
27
77
  left: DocumentTransform;
28
78
  right: DocumentTransform;
29
79
  };
30
80
  constructor(transform: TransformFn, options?: DocumentTransformOptions);
31
81
  /**
32
- * Resets the internal cache of this transform, if it has one.
82
+ * Resets the internal cache of this transform, if it is cached.
33
83
  */
34
84
  resetCache(): void;
35
85
  private performWork;
86
+ /**
87
+ * Transforms a GraphQL document using the configured transform function.
88
+ *
89
+ * @remarks
90
+ *
91
+ * Note that `transformDocument` caches the transformed document. Calling
92
+ * `transformDocument` again with the already-transformed document will
93
+ * immediately return it.
94
+ *
95
+ * @param document - The GraphQL document to transform
96
+ * @returns The transformed document
97
+ *
98
+ * @example
99
+ *
100
+ * ```ts
101
+ * const document = gql`
102
+ * # ...
103
+ * `;
104
+ *
105
+ * const documentTransform = new DocumentTransform(transformFn);
106
+ * const transformedDocument = documentTransform.transformDocument(document);
107
+ * ```
108
+ */
36
109
  transformDocument(document: DocumentNode): DocumentNode;
110
+ /**
111
+ * Combines this document transform with another document transform. The
112
+ * returned document transform first applies the current document transform,
113
+ * then applies the other document transform.
114
+ *
115
+ * @param otherTransform - The transform to apply after this one
116
+ * @returns A new DocumentTransform that applies both transforms in sequence
117
+ *
118
+ * @example
119
+ *
120
+ * ```ts
121
+ * const combinedTransform = addTypenameTransform.concat(
122
+ * removeDirectivesTransform
123
+ * );
124
+ * ```
125
+ */
37
126
  concat(otherTransform: DocumentTransform): DocumentTransform;
38
127
  /**
39
128
  * @internal
@@ -1,6 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isFormattedExecutionResult = isFormattedExecutionResult;
4
+ /**
5
+ * Determines whether the given object is a valid GraphQL execution result
6
+ * according to the GraphQL specification.
7
+ *
8
+ * @remarks
9
+ *
10
+ * A valid execution result must be an object that contains only `data`,
11
+ * `errors`, and/or `extensions` properties. At least one of `data` or `errors`
12
+ * must be present.
13
+ *
14
+ * @param result - The object to test
15
+ * @returns `true` if the object conforms to the GraphQL execution result format
16
+ *
17
+ * @example
18
+ *
19
+ * ```ts
20
+ * import { isFormattedExecutionResult } from "@apollo/client/utilities";
21
+ *
22
+ * // Valid execution result
23
+ * const validResult = { data: { user: { name: "John" } } };
24
+ * console.log(isFormattedExecutionResult(validResult)); // true
25
+ *
26
+ * // Invalid - contains non-standard properties
27
+ * const invalidResult = { data: {}, customField: "value" };
28
+ * console.log(isFormattedExecutionResult(invalidResult)); // false
29
+ * ```
30
+ */
4
31
  function isFormattedExecutionResult(result) {
5
32
  return (!!result &&
6
33
  ("errors" in result || "data" in result) &&
@@ -1 +1 @@
1
- {"version":3,"file":"isFormattedExecutionResult.cjs","sources":["../../../../src/utilities/graphql/isFormattedExecutionResult.ts"],"sourcesContent":["import type { FormattedExecutionResult } from \"graphql\";\n\nexport function isFormattedExecutionResult(\n result?: object\n): result is FormattedExecutionResult {\n return (\n !!result &&\n (\"errors\" in result || \"data\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,CACU,EAAE,CADZ,EACe,CADf,CAAA,EAAA,CAAA,CAAA,EACuB,CADvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EACmC,CADnC,CAAA,EAAA,CAAA,CAAA,EAC2C,CAD3C,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EACqD,CADrD,CAAA,EAAA,CAAA,CAAA,EAC6D,CAD7D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACyE,CACpE,CACF;AACH;"}
1
+ {"version":3,"file":"isFormattedExecutionResult.cjs","sources":["../../../../src/utilities/graphql/isFormattedExecutionResult.ts"],"sourcesContent":["import type { FormattedExecutionResult } from \"graphql\";\n\n/**\n * Determines whether the given object is a valid GraphQL execution result\n * according to the GraphQL specification.\n *\n * @remarks\n *\n * A valid execution result must be an object that contains only `data`,\n * `errors`, and/or `extensions` properties. At least one of `data` or `errors`\n * must be present.\n *\n * @param result - The object to test\n * @returns `true` if the object conforms to the GraphQL execution result format\n *\n * @example\n *\n * ```ts\n * import { isFormattedExecutionResult } from \"@apollo/client/utilities\";\n *\n * // Valid execution result\n * const validResult = { data: { user: { name: \"John\" } } };\n * console.log(isFormattedExecutionResult(validResult)); // true\n *\n * // Invalid - contains non-standard properties\n * const invalidResult = { data: {}, customField: \"value\" };\n * console.log(isFormattedExecutionResult(invalidResult)); // false\n * ```\n */\nexport function isFormattedExecutionResult(\n result?: object\n): result is FormattedExecutionResult {\n return (\n !!result &&\n (\"errors\" in result || \"data\" in result) &&\n Object.keys(result).every(\n (key) => key === \"errors\" || key === \"data\" || key === \"extensions\"\n )\n );\n}\n"],"names":[],"mappings":";;AA6BA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA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A,CAAA,CAAA,EAC6D,CAD7D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACyE,CACpE,CACF;AACH;"}
@@ -1,3 +1,30 @@
1
1
  import type { FormattedExecutionResult } from "graphql";
2
+ /**
3
+ * Determines whether the given object is a valid GraphQL execution result
4
+ * according to the GraphQL specification.
5
+ *
6
+ * @remarks
7
+ *
8
+ * A valid execution result must be an object that contains only `data`,
9
+ * `errors`, and/or `extensions` properties. At least one of `data` or `errors`
10
+ * must be present.
11
+ *
12
+ * @param result - The object to test
13
+ * @returns `true` if the object conforms to the GraphQL execution result format
14
+ *
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * import { isFormattedExecutionResult } from "@apollo/client/utilities";
19
+ *
20
+ * // Valid execution result
21
+ * const validResult = { data: { user: { name: "John" } } };
22
+ * console.log(isFormattedExecutionResult(validResult)); // true
23
+ *
24
+ * // Invalid - contains non-standard properties
25
+ * const invalidResult = { data: {}, customField: "value" };
26
+ * console.log(isFormattedExecutionResult(invalidResult)); // false
27
+ * ```
28
+ */
2
29
  export declare function isFormattedExecutionResult(result?: object): result is FormattedExecutionResult;
3
30
  //# sourceMappingURL=isFormattedExecutionResult.d.cts.map
@@ -10,9 +10,26 @@ function isOperation(document, operation) {
10
10
  /**
11
11
  * Determine if a document is a mutation document.
12
12
  *
13
+ * @remarks
14
+ * If you are authoring an Apollo link, you might not need this utility.
15
+ * Prefer using the `operationType` property the `operation` object instead.
16
+ *
13
17
  * @param document - The GraphQL document to check
18
+ * @returns A boolean indicating if the document is a mutation operation
19
+ *
20
+ * @example
21
+ *
22
+ * ```ts
23
+ * import { isMutationOperation } from "@apollo/client/utilities";
14
24
  *
15
- * @since 3.8.0
25
+ * const mutation = gql`
26
+ * mutation MyMutation {
27
+ * # ...
28
+ * }
29
+ * `;
30
+ *
31
+ * isMutationOperation(mutation); // true
32
+ * ```
16
33
  */
17
34
  function isMutationOperation(document) {
18
35
  return isOperation(document, "mutation");
@@ -20,9 +37,26 @@ function isMutationOperation(document) {
20
37
  /**
21
38
  * Determine if a document is a query document.
22
39
  *
40
+ * @remarks
41
+ * If you are authoring an Apollo link, you might not need this utility.
42
+ * Prefer using the `operationType` property the `operation` object instead.
43
+ *
23
44
  * @param document - The GraphQL document to check
45
+ * @returns A boolean indicating if the document is a query operation
46
+ *
47
+ * @example
24
48
  *
25
- * @since 3.8.0
49
+ * ```ts
50
+ * import { isQueryOperation } from "@apollo/client/utilities";
51
+ *
52
+ * const query = gql`
53
+ * query MyQuery {
54
+ * # ...
55
+ * }
56
+ * `;
57
+ *
58
+ * isQueryOperation(query); // true
59
+ * ```
26
60
  */
27
61
  function isQueryOperation(document) {
28
62
  return isOperation(document, "query");
@@ -30,9 +64,26 @@ function isQueryOperation(document) {
30
64
  /**
31
65
  * Determine if a document is a subscription document.
32
66
  *
67
+ * @remarks
68
+ * If you are authoring an Apollo link, you might not need this utility.
69
+ * Prefer using the `operationType` property the `operation` object instead.
70
+ *
33
71
  * @param document - The GraphQL document to check
72
+ * @returns A boolean indicating if the document is a subscription operation
73
+ *
74
+ * @example
75
+ *
76
+ * ```ts
77
+ * import { isSubscriptionOperation } from "@apollo/client/utilities";
78
+ *
79
+ * const subscription = gql`
80
+ * subscription MySubscription {
81
+ * # ...
82
+ * }
83
+ * `;
34
84
  *
35
- * @since 3.8.0
85
+ * isSubscriptionOperation(subscription); // true
86
+ * ```
36
87
  */
37
88
  function isSubscriptionOperation(document) {
38
89
  return isOperation(document, "subscription");
@@ -1 +1 @@
1
- {"version":3,"file":"operations.cjs","sources":["../../../../src/utilities/graphql/operations.ts"],"sourcesContent":["import type { DocumentNode } from \"@apollo/client\";\nimport { getOperationDefinition } from \"@apollo/client/utilities/internal\";\n\nfunction isOperation(\n document: DocumentNode,\n operation: \"query\" | \"mutation\" | \"subscription\"\n) {\n return getOperationDefinition(document)?.operation === operation;\n}\n\n/**\n * Determine if a document is a mutation document.\n *\n * @param document - The GraphQL document to check\n *\n * @since 3.8.0\n */\nexport function isMutationOperation(document: DocumentNode) {\n return isOperation(document, \"mutation\");\n}\n\n/**\n * Determine if a document is a query document.\n *\n * @param document - The GraphQL document to check\n *\n * @since 3.8.0\n */\nexport function isQueryOperation(document: DocumentNode) {\n return isOperation(document, \"query\");\n}\n\n/**\n * Determine if a document is a subscription document.\n *\n * @param document - The GraphQL document to check\n *\n * @since 3.8.0\n */\nexport function isSubscriptionOperation(document: DocumentNode) {\n return isOperation(document, \"subscription\");\n}\n"],"names":[],"mappings":";;AAiBA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAWA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAWA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAtCA,CAAA,CAAA,CAAA,CAA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AC,CAArB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA6B,EAAE,CAA/B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA6C,CAAC;AAC9C;"}
1
+ {"version":3,"file":"operations.cjs","sources":["../../../../src/utilities/graphql/operations.ts"],"sourcesContent":["import type { DocumentNode } from \"@apollo/client\";\nimport { getOperationDefinition } from \"@apollo/client/utilities/internal\";\n\nfunction isOperation(\n document: DocumentNode,\n operation: \"query\" | \"mutation\" | \"subscription\"\n) {\n return getOperationDefinition(document)?.operation === operation;\n}\n\n/**\n * Determine if a document is a mutation document.\n *\n * @remarks\n * If you are authoring an Apollo link, you might not need this utility.\n * Prefer using the `operationType` property the `operation` object instead.\n *\n * @param document - The GraphQL document to check\n * @returns A boolean indicating if the document is a mutation operation\n *\n * @example\n *\n * ```ts\n * import { isMutationOperation } from \"@apollo/client/utilities\";\n *\n * const mutation = gql`\n * mutation MyMutation {\n * # ...\n * }\n * `;\n *\n * isMutationOperation(mutation); // true\n * ```\n */\nexport function isMutationOperation(document: DocumentNode) {\n return isOperation(document, \"mutation\");\n}\n\n/**\n * Determine if a document is a query document.\n *\n * @remarks\n * If you are authoring an Apollo link, you might not need this utility.\n * Prefer using the `operationType` property the `operation` object instead.\n *\n * @param document - The GraphQL document to check\n * @returns A boolean indicating if the document is a query operation\n *\n * @example\n *\n * ```ts\n * import { isQueryOperation } from \"@apollo/client/utilities\";\n *\n * const query = gql`\n * query MyQuery {\n * # ...\n * }\n * `;\n *\n * isQueryOperation(query); // true\n * ```\n */\nexport function isQueryOperation(document: DocumentNode) {\n return isOperation(document, \"query\");\n}\n\n/**\n * Determine if a document is a subscription document.\n *\n * @remarks\n * If you are authoring an Apollo link, you might not need this utility.\n * Prefer using the `operationType` property the `operation` object instead.\n *\n * @param document - The GraphQL document to check\n * @returns A boolean indicating if the document is a subscription operation\n *\n * @example\n *\n * ```ts\n * import { isSubscriptionOperation } from \"@apollo/client/utilities\";\n *\n * const subscription = gql`\n * subscription MySubscription {\n * # ...\n * }\n * `;\n *\n * isSubscriptionOperation(subscription); // true\n * ```\n */\nexport function isSubscriptionOperation(document: DocumentNode) {\n return isOperation(document, \"subscription\");\n}\n"],"names":[],"mappings":";;AAkCA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AA4BA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AA4BA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAzFA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,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A,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA6C,CAAC;AAC9C;"}
@@ -2,25 +2,76 @@ import type { DocumentNode } from "@apollo/client";
2
2
  /**
3
3
  * Determine if a document is a mutation document.
4
4
  *
5
+ * @remarks
6
+ * If you are authoring an Apollo link, you might not need this utility.
7
+ * Prefer using the `operationType` property the `operation` object instead.
8
+ *
5
9
  * @param document - The GraphQL document to check
10
+ * @returns A boolean indicating if the document is a mutation operation
11
+ *
12
+ * @example
13
+ *
14
+ * ```ts
15
+ * import { isMutationOperation } from "@apollo/client/utilities";
6
16
  *
7
- * @since 3.8.0
17
+ * const mutation = gql`
18
+ * mutation MyMutation {
19
+ * # ...
20
+ * }
21
+ * `;
22
+ *
23
+ * isMutationOperation(mutation); // true
24
+ * ```
8
25
  */
9
26
  export declare function isMutationOperation(document: DocumentNode): boolean;
10
27
  /**
11
28
  * Determine if a document is a query document.
12
29
  *
30
+ * @remarks
31
+ * If you are authoring an Apollo link, you might not need this utility.
32
+ * Prefer using the `operationType` property the `operation` object instead.
33
+ *
13
34
  * @param document - The GraphQL document to check
35
+ * @returns A boolean indicating if the document is a query operation
36
+ *
37
+ * @example
14
38
  *
15
- * @since 3.8.0
39
+ * ```ts
40
+ * import { isQueryOperation } from "@apollo/client/utilities";
41
+ *
42
+ * const query = gql`
43
+ * query MyQuery {
44
+ * # ...
45
+ * }
46
+ * `;
47
+ *
48
+ * isQueryOperation(query); // true
49
+ * ```
16
50
  */
17
51
  export declare function isQueryOperation(document: DocumentNode): boolean;
18
52
  /**
19
53
  * Determine if a document is a subscription document.
20
54
  *
55
+ * @remarks
56
+ * If you are authoring an Apollo link, you might not need this utility.
57
+ * Prefer using the `operationType` property the `operation` object instead.
58
+ *
21
59
  * @param document - The GraphQL document to check
60
+ * @returns A boolean indicating if the document is a subscription operation
61
+ *
62
+ * @example
63
+ *
64
+ * ```ts
65
+ * import { isSubscriptionOperation } from "@apollo/client/utilities";
66
+ *
67
+ * const subscription = gql`
68
+ * subscription MySubscription {
69
+ * # ...
70
+ * }
71
+ * `;
22
72
  *
23
- * @since 3.8.0
73
+ * isSubscriptionOperation(subscription); // true
74
+ * ```
24
75
  */
25
76
  export declare function isSubscriptionOperation(document: DocumentNode): boolean;
26
77
  //# sourceMappingURL=operations.d.cts.map
@@ -5,6 +5,15 @@ exports.isReference = isReference;
5
5
  * Determines if a given object is a reference object.
6
6
  *
7
7
  * @param obj - The object to check if its a reference object
8
+ *
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * import { isReference } from "@apollo/client/utilities";
13
+ *
14
+ * isReference({ __ref: "User:1" }); // true
15
+ * isReference({ __typename: "User", id: 1 }); // false
16
+ * ```
8
17
  */
9
18
  function isReference(obj) {
10
19
  return Boolean(obj && typeof obj === "object" && typeof obj.__ref === "string");
@@ -1 +1 @@
1
- {"version":3,"file":"storeUtils.cjs","sources":["../../../../src/utilities/graphql/storeUtils.ts"],"sourcesContent":["/**\n * Representation of a reference object inside the cache.\n */\nexport interface Reference {\n readonly __ref: string;\n}\n\n/**\n * Determines if a given object is a reference object.\n *\n * @param obj - The object to check if its a reference object\n */\nexport function isReference(obj: any): obj is Reference {\n return Boolean(\n obj && typeof obj === \"object\" && typeof obj.__ref === \"string\"\n );\n}\n\n/**\n * Represents the union of valid values that can be stored in the cache.\n */\nexport type StoreValue =\n | number\n | string\n | string[]\n | Reference\n | Reference[]\n | null\n | undefined\n | void\n | Object;\n\n/**\n * Represents an object that is stored in the cache.\n */\nexport interface StoreObject {\n __typename?: string;\n [storeFieldName: string]: StoreValue;\n}\n\n/**\n * Workaround for a TypeScript quirk:\n * types per default have an implicit index signature that makes them\n * assignable to `StoreObject`.\n * interfaces do not have that implicit index signature, so they cannot\n * be assigned to `StoreObject`.\n * This type just maps over a type or interface that is passed in,\n * implicitly adding the index signature.\n * That way, the result can be assigned to `StoreObject`.\n *\n * This is important if some user-defined interface is used e.g.\n * in cache.modify, where the `toReference` method expects a\n * `StoreObject` as input.\n */\nexport type AsStoreObject<T extends { __typename?: string }> = {\n [K in keyof T]: T[K];\n};\n"],"names":[],"mappings":";;AAYA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AALA,CAAA,CAAA;;;;CAIA,CAAA;AACA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAgB,CAAhB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA2B,CAAC,CAA5B,CAAA,CAAoC,EAApC;IACE,CAAF,CAAA,CAAA,CAAA,CAAA,EAAS,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgB,CACZ,CADJ,CAAA,EAAA,CAAA,EACW,CADX,CAAA,CAAA,CAAA,CAAA,EACkB,CADlB,CAAA,EAAA,CAAA,CAAA,EAC0B,CAD1B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EACsC,CADtC,CAAA,CAAA,CAAA,CAAA,EAC6C,CAD7C,CAAA,CACgD,CAAC,CADjD,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAC2D,CAD3D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACmE,CAChE;AACH;"}
1
+ {"version":3,"file":"storeUtils.cjs","sources":["../../../../src/utilities/graphql/storeUtils.ts"],"sourcesContent":["/**\n * Representation of a reference object inside the cache.\n */\nexport interface Reference {\n readonly __ref: string;\n}\n\n/**\n * Determines if a given object is a reference object.\n *\n * @param obj - The object to check if its a reference object\n *\n * @example\n *\n * ```ts\n * import { isReference } from \"@apollo/client/utilities\";\n *\n * isReference({ __ref: \"User:1\" }); // true\n * isReference({ __typename: \"User\", id: 1 }); // false\n * ```\n */\nexport function isReference(obj: any): obj is Reference {\n return Boolean(\n obj && typeof obj === \"object\" && typeof obj.__ref === \"string\"\n );\n}\n\n/**\n * Represents the union of valid values that can be stored in the cache.\n */\nexport type StoreValue =\n | number\n | string\n | string[]\n | Reference\n | Reference[]\n | null\n | undefined\n | void\n | Object;\n\n/**\n * Represents an object that is stored in the cache.\n */\nexport interface StoreObject {\n __typename?: string;\n [storeFieldName: string]: StoreValue;\n}\n\n/**\n * Workaround for a TypeScript quirk:\n * types per default have an implicit index signature that makes them\n * assignable to `StoreObject`.\n * interfaces do not have that implicit index signature, so they cannot\n * be assigned to `StoreObject`.\n * This type just maps over a type or interface that is passed in,\n * implicitly adding the index signature.\n * That way, the result can be assigned to `StoreObject`.\n *\n * This is important if some user-defined interface is used e.g.\n * in cache.modify, where the `toReference` method expects a\n * `StoreObject` as input.\n */\nexport type AsStoreObject<T extends { __typename?: string }> = {\n [K in keyof T]: T[K];\n};\n"],"names":[],"mappings":";;AAqBA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAdA,CAAA,CAAA;;;;;;;;;;;;;CAaA,CAAA;AACA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAgB,CAAhB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA2B,CAAC,CAA5B,CAAA,CAAoC,EAApC;IACE,CAAF,CAAA,CAAA,CAAA,CAAA,EAAS,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgB,CACZ,CADJ,CAAA,EAAA,CAAA,EACW,CADX,CAAA,CAAA,CAAA,CAAA,EACkB,CADlB,CAAA,EAAA,CAAA,CAAA,EAC0B,CAD1B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EACsC,CADtC,CAAA,CAAA,CAAA,CAAA,EAC6C,CAD7C,CAAA,CACgD,CAAC,CADjD,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAC2D,CAD3D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACmE,CAChE;AACH;"}
@@ -8,6 +8,15 @@ export interface Reference {
8
8
  * Determines if a given object is a reference object.
9
9
  *
10
10
  * @param obj - The object to check if its a reference object
11
+ *
12
+ * @example
13
+ *
14
+ * ```ts
15
+ * import { isReference } from "@apollo/client/utilities";
16
+ *
17
+ * isReference({ __ref: "User:1" }); // true
18
+ * isReference({ __typename: "User", id: 1 }); // false
19
+ * ```
11
20
  */
12
21
  export declare function isReference(obj: any): obj is Reference;
13
22
  /**
@@ -10,9 +10,20 @@ const TYPENAME_FIELD = {
10
10
  },
11
11
  };
12
12
  /**
13
- * Adds `__typename` to all selection sets in the document.
13
+ * Adds `__typename` to all selection sets in the document except for the root
14
+ * selection set.
14
15
  *
15
16
  * @param doc - The `ASTNode` to add `__typename` to
17
+ *
18
+ * @example
19
+ *
20
+ * ```ts
21
+ * const document = gql`
22
+ * # ...
23
+ * `;
24
+ *
25
+ * const withTypename = addTypenameToDocument(document);
26
+ * ```
16
27
  */
17
28
  exports.addTypenameToDocument = Object.assign(function (doc) {
18
29
  return (0, graphql_1.visit)(doc, {
@@ -1 +1 @@
1
- {"version":3,"file":"transform.cjs","sources":["../../../../src/utilities/graphql/transform.ts"],"sourcesContent":["import type { ASTNode, FieldNode, OperationDefinitionNode } from \"graphql\";\nimport { Kind, visit } from \"graphql\";\n\nconst TYPENAME_FIELD: FieldNode = {\n kind: Kind.FIELD,\n name: {\n kind: Kind.NAME,\n value: \"__typename\",\n },\n};\n\n/**\n * Adds `__typename` to all selection sets in the document.\n *\n * @param doc - The `ASTNode` to add `__typename` to\n */\nexport const addTypenameToDocument = Object.assign(\n function <TNode extends ASTNode>(doc: TNode): TNode {\n return visit(doc, {\n SelectionSet: {\n enter(node, _key, parent) {\n // Don't add __typename to OperationDefinitions.\n if (\n parent &&\n (parent as OperationDefinitionNode).kind ===\n Kind.OPERATION_DEFINITION\n ) {\n return;\n }\n\n // No changes if no selections.\n const { selections } = node;\n if (!selections) {\n return;\n }\n\n // If selections already have a __typename, or are part of an\n // introspection query, do nothing.\n const skip = selections.some((selection) => {\n return (\n selection.kind === Kind.FIELD &&\n (selection.name.value === \"__typename\" ||\n selection.name.value.lastIndexOf(\"__\", 0) === 0)\n );\n });\n if (skip) {\n return;\n }\n\n // If this SelectionSet is @export-ed as an input variable, it should\n // not have a __typename field (see issue #4691).\n const field = parent as FieldNode;\n if (\n field.kind === Kind.FIELD &&\n field.directives &&\n field.directives.some((d) => d.name.value === \"export\")\n ) {\n return;\n }\n\n // Create and return a new SelectionSet with a __typename Field.\n return {\n ...node,\n selections: [...selections, TYPENAME_FIELD],\n };\n },\n },\n });\n },\n {\n added(field: FieldNode): boolean {\n return field === TYPENAME_FIELD;\n },\n }\n);\n"],"names":[],"mappings":";;;AACA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAEA,CAAA,CAAA,CAAA,CAAA,EAAM,CAAN,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAkC;IAChC,CAAF,CAAA,CAAA,CAAM,EAAE,CAAR,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAY,CAAC,CAAb,CAAA,CAAA,CAAA,CAAkB;IAChB,CAAF,CAAA,CAAA,CAAM,EAAE;QACJ,CAAJ,CAAA,CAAA,CAAQ,EAAE,CAAV,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,C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CAAA,EAAuB,CAAvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAqC;IACjC,CAAC;AACL,CAAG,CACF;"}
1
+ {"version":3,"file":"transform.cjs","sources":["../../../../src/utilities/graphql/transform.ts"],"sourcesContent":["import type { ASTNode, FieldNode, OperationDefinitionNode } from \"graphql\";\nimport { Kind, visit } from \"graphql\";\n\nconst TYPENAME_FIELD: FieldNode = {\n kind: Kind.FIELD,\n name: {\n kind: Kind.NAME,\n value: \"__typename\",\n },\n};\n\n/**\n * Adds `__typename` to all selection sets in the document except for the root\n * selection set.\n *\n * @param doc - The `ASTNode` to add `__typename` to\n *\n * @example\n *\n * ```ts\n * const document = gql`\n * # ...\n * `;\n *\n * const withTypename = addTypenameToDocument(document);\n * ```\n */\nexport const addTypenameToDocument = Object.assign(\n function <TNode extends ASTNode>(doc: TNode): TNode {\n return visit(doc, {\n SelectionSet: {\n enter(node, _key, parent) {\n // Don't add __typename to OperationDefinitions.\n if (\n parent &&\n (parent as OperationDefinitionNode).kind ===\n Kind.OPERATION_DEFINITION\n ) {\n return;\n }\n\n // No changes if no selections.\n const { selections } = node;\n if (!selections) {\n return;\n }\n\n // If selections already have a __typename, or are part of an\n // introspection query, do nothing.\n const skip = selections.some((selection) => {\n return (\n selection.kind === Kind.FIELD &&\n (selection.name.value === \"__typename\" ||\n selection.name.value.lastIndexOf(\"__\", 0) === 0)\n );\n });\n if (skip) {\n return;\n }\n\n // If this SelectionSet is @export-ed as an input variable, it should\n // not have a __typename field (see issue #4691).\n const field = parent as FieldNode;\n if (\n field.kind === Kind.FIELD &&\n field.directives &&\n field.directives.some((d) => d.name.value === \"export\")\n ) {\n return;\n }\n\n // Create and return a new SelectionSet with a __typename Field.\n return {\n ...node,\n selections: [...selections, TYPENAME_FIELD],\n };\n },\n },\n });\n },\n {\n added(field: FieldNode): boolean {\n return field === TYPENAME_FIELD;\n },\n }\n);\n"],"names":[],"mappings":";;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A,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA;gBACU,CAAV,CAAA,CAAA,CAAA,CAAA,EAAiB;oBACL,CAAZ,CAAA,CAAe,CAAf,CAAA,CAAA,CAAmB;oBACP,CAAZ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsB,EAAE,CAAC,CAAzB,CAAA,CAA4B,CAA5B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsC,EAAE,CAAxC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsD,CAAC;gBACvD,CAAW;YACH,CAAC;QACT,CAAO;IACP,CAAK,CAAC;AACJ,CAAC,EACD;IACE,CAAJ,CAAA,CAAA,CAAA,CAAS,CAAC,CAAV,CAAA,CAAA,CAAA,CAA0B,EAA1B;QACM,CAAN,CAAA,CAAA,CAAA,CAAA,EAAa,CAAb,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAuB,CAAvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAqC;IACjC,CAAC;AACL,CAAG,CACF;"}
@@ -1,8 +1,19 @@
1
1
  import type { ASTNode, FieldNode } from "graphql";
2
2
  /**
3
- * Adds `__typename` to all selection sets in the document.
3
+ * Adds `__typename` to all selection sets in the document except for the root
4
+ * selection set.
4
5
  *
5
6
  * @param doc - The `ASTNode` to add `__typename` to
7
+ *
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * const document = gql`
12
+ * # ...
13
+ * `;
14
+ *
15
+ * const withTypename = addTypenameToDocument(document);
16
+ * ```
6
17
  */
7
18
  export declare const addTypenameToDocument: (<TNode extends ASTNode>(doc: TNode) => TNode) & {
8
19
  added(field: FieldNode): boolean;
@@ -6,21 +6,44 @@ const sizes_js_1 = require("../caching/sizes.cjs");
6
6
  const caches_js_1 = require("./caches.cjs");
7
7
  const getMemoryInternals_js_1 = require("./getMemoryInternals.cjs");
8
8
  /**
9
- * Like JSON.stringify, but with object keys always sorted in the same order.
9
+ * Serializes a value to JSON with object keys in a consistent, sorted order.
10
10
  *
11
- * To achieve performant sorting, this function uses a Map from JSON-serialized
11
+ * @remarks
12
+ *
13
+ * Unlike `JSON.stringify()`, this function ensures that object keys are always
14
+ * serialized in the same alphabetical order, regardless of their original order.
15
+ * This makes it suitable for creating consistent cache keys from objects,
16
+ * comparing objects by their serialized representation, or generating
17
+ * deterministic hashes of objects.
18
+ *
19
+ * To achieve performant sorting, this function uses a `Map` from JSON-serialized
12
20
  * arrays of keys (in any order) to sorted arrays of the same keys, with a
13
21
  * single sorted array reference shared by all permutations of the keys.
14
22
  *
15
- * As a drawback, this function will add a little bit more memory for every
16
- * object encountered that has different (more, less, a different order of) keys
17
- * than in the past.
23
+ * As a drawback, this function will add a little more memory for every object
24
+ * encountered that has different (more, less, a different order of) keys than
25
+ * in the past.
18
26
  *
19
27
  * In a typical application, this extra memory usage should not play a
20
28
  * significant role, as `canonicalStringify` will be called for only a limited
21
29
  * number of object shapes, and the cache will not grow beyond a certain point.
22
- * But in some edge cases, this could be a problem, so we provide
23
- * canonicalStringify.reset() as a way of clearing the cache.
30
+ * But in some edge cases, this could be a problem. Use canonicalStringify.reset()
31
+ * as a way to clear the memoization cache.
32
+ *
33
+ * @param value - The value to stringify
34
+ * @returns JSON string with consistently ordered object keys
35
+ *
36
+ * @example
37
+ *
38
+ * ```ts
39
+ * import { canonicalStringify } from "@apollo/client/utilities";
40
+ *
41
+ * const obj1 = { b: 2, a: 1 };
42
+ * const obj2 = { a: 1, b: 2 };
43
+ *
44
+ * console.log(canonicalStringify(obj1)); // '{"a":1,"b":2}'
45
+ * console.log(canonicalStringify(obj2)); // '{"a":1,"b":2}'
46
+ * ```
24
47
  */
25
48
  exports.canonicalStringify = Object.assign(function canonicalStringify(value) {
26
49
  return JSON.stringify(value, stableObjectReplacer);