@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
@@ -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.ts.map
@@ -5,9 +5,26 @@ function isOperation(document, operation) {
5
5
  /**
6
6
  * Determine if a document is a mutation document.
7
7
  *
8
+ * @remarks
9
+ * If you are authoring an Apollo link, you might not need this utility.
10
+ * Prefer using the `operationType` property the `operation` object instead.
11
+ *
8
12
  * @param document - The GraphQL document to check
13
+ * @returns A boolean indicating if the document is a mutation operation
14
+ *
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * import { isMutationOperation } from "@apollo/client/utilities";
9
19
  *
10
- * @since 3.8.0
20
+ * const mutation = gql`
21
+ * mutation MyMutation {
22
+ * # ...
23
+ * }
24
+ * `;
25
+ *
26
+ * isMutationOperation(mutation); // true
27
+ * ```
11
28
  */
12
29
  export function isMutationOperation(document) {
13
30
  return isOperation(document, "mutation");
@@ -15,9 +32,26 @@ export function isMutationOperation(document) {
15
32
  /**
16
33
  * Determine if a document is a query document.
17
34
  *
35
+ * @remarks
36
+ * If you are authoring an Apollo link, you might not need this utility.
37
+ * Prefer using the `operationType` property the `operation` object instead.
38
+ *
18
39
  * @param document - The GraphQL document to check
40
+ * @returns A boolean indicating if the document is a query operation
41
+ *
42
+ * @example
19
43
  *
20
- * @since 3.8.0
44
+ * ```ts
45
+ * import { isQueryOperation } from "@apollo/client/utilities";
46
+ *
47
+ * const query = gql`
48
+ * query MyQuery {
49
+ * # ...
50
+ * }
51
+ * `;
52
+ *
53
+ * isQueryOperation(query); // true
54
+ * ```
21
55
  */
22
56
  export function isQueryOperation(document) {
23
57
  return isOperation(document, "query");
@@ -25,9 +59,26 @@ export function isQueryOperation(document) {
25
59
  /**
26
60
  * Determine if a document is a subscription document.
27
61
  *
62
+ * @remarks
63
+ * If you are authoring an Apollo link, you might not need this utility.
64
+ * Prefer using the `operationType` property the `operation` object instead.
65
+ *
28
66
  * @param document - The GraphQL document to check
67
+ * @returns A boolean indicating if the document is a subscription operation
68
+ *
69
+ * @example
70
+ *
71
+ * ```ts
72
+ * import { isSubscriptionOperation } from "@apollo/client/utilities";
73
+ *
74
+ * const subscription = gql`
75
+ * subscription MySubscription {
76
+ * # ...
77
+ * }
78
+ * `;
29
79
  *
30
- * @since 3.8.0
80
+ * isSubscriptionOperation(subscription); // true
81
+ * ```
31
82
  */
32
83
  export function isSubscriptionOperation(document) {
33
84
  return isOperation(document, "subscription");
@@ -1 +1 @@
1
- {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/utilities/graphql/operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,SAAS,WAAW,CAClB,QAAsB,EACtB,SAAgD;IAEhD,OAAO,sBAAsB,CAAC,QAAQ,CAAC,EAAE,SAAS,KAAK,SAAS,CAAC;AACnE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,OAAO,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACrD,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAsB;IAC5D,OAAO,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAC/C,CAAC","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"]}
1
+ {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/utilities/graphql/operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,SAAS,WAAW,CAClB,QAAsB,EACtB,SAAgD;IAEhD,OAAO,sBAAsB,CAAC,QAAQ,CAAC,EAAE,SAAS,KAAK,SAAS,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,OAAO,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACrD,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAsB;IAC5D,OAAO,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAC/C,CAAC","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"]}
@@ -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
  /**
@@ -2,6 +2,15 @@
2
2
  * Determines if a given object is a reference object.
3
3
  *
4
4
  * @param obj - The object to check if its a reference object
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import { isReference } from "@apollo/client/utilities";
10
+ *
11
+ * isReference({ __ref: "User:1" }); // true
12
+ * isReference({ __typename: "User", id: 1 }); // false
13
+ * ```
5
14
  */
6
15
  export function isReference(obj) {
7
16
  return Boolean(obj && typeof obj === "object" && typeof obj.__ref === "string");
@@ -1 +1 @@
1
- {"version":3,"file":"storeUtils.js","sourceRoot":"","sources":["../../../src/utilities/graphql/storeUtils.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAQ;IAClC,OAAO,OAAO,CACZ,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAChE,CAAC;AACJ,CAAC","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"]}
1
+ {"version":3,"file":"storeUtils.js","sourceRoot":"","sources":["../../../src/utilities/graphql/storeUtils.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,GAAQ;IAClC,OAAO,OAAO,CACZ,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAChE,CAAC;AACJ,CAAC","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"]}
@@ -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;
@@ -7,9 +7,20 @@ const TYPENAME_FIELD = {
7
7
  },
8
8
  };
9
9
  /**
10
- * Adds `__typename` to all selection sets in the document.
10
+ * Adds `__typename` to all selection sets in the document except for the root
11
+ * selection set.
11
12
  *
12
13
  * @param doc - The `ASTNode` to add `__typename` to
14
+ *
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * const document = gql`
19
+ * # ...
20
+ * `;
21
+ *
22
+ * const withTypename = addTypenameToDocument(document);
23
+ * ```
13
24
  */
14
25
  export const addTypenameToDocument = Object.assign(function (doc) {
15
26
  return visit(doc, {
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/utilities/graphql/transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,cAAc,GAAc;IAChC,IAAI,EAAE,IAAI,CAAC,KAAK;IAChB,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,YAAY;KACpB;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAChD,UAAiC,GAAU;IACzC,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,YAAY,EAAE;YACZ,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM;gBACtB,gDAAgD;gBAChD,IACE,MAAM;oBACL,MAA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port { 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"]}
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/utilities/graphql/transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,cAAc,GAAc;IAChC,IAAI,EAAE,IAAI,CAAC,KAAK;IAChB,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,YAAY;KACpB;CACF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,qBAA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;YACJ,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC,EACD;IACE,KAAK,CAAC,KAAgB;QACpB,OAAO,KAAK,KAAK,cAAc,CAAC;IAClC,CAAC;CACF,CACF,CAAC","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"]}
@@ -1,19 +1,42 @@
1
1
  /**
2
- * Like JSON.stringify, but with object keys always sorted in the same order.
2
+ * Serializes a value to JSON with object keys in a consistent, sorted order.
3
3
  *
4
- * To achieve performant sorting, this function uses a Map from JSON-serialized
4
+ * @remarks
5
+ *
6
+ * Unlike `JSON.stringify()`, this function ensures that object keys are always
7
+ * serialized in the same alphabetical order, regardless of their original order.
8
+ * This makes it suitable for creating consistent cache keys from objects,
9
+ * comparing objects by their serialized representation, or generating
10
+ * deterministic hashes of objects.
11
+ *
12
+ * To achieve performant sorting, this function uses a `Map` from JSON-serialized
5
13
  * arrays of keys (in any order) to sorted arrays of the same keys, with a
6
14
  * single sorted array reference shared by all permutations of the keys.
7
15
  *
8
- * As a drawback, this function will add a little bit more memory for every
9
- * object encountered that has different (more, less, a different order of) keys
10
- * than in the past.
16
+ * As a drawback, this function will add a little more memory for every object
17
+ * encountered that has different (more, less, a different order of) keys than
18
+ * in the past.
11
19
  *
12
20
  * In a typical application, this extra memory usage should not play a
13
21
  * significant role, as `canonicalStringify` will be called for only a limited
14
22
  * number of object shapes, and the cache will not grow beyond a certain point.
15
- * But in some edge cases, this could be a problem, so we provide
16
- * canonicalStringify.reset() as a way of clearing the cache.
23
+ * But in some edge cases, this could be a problem. Use canonicalStringify.reset()
24
+ * as a way to clear the memoization cache.
25
+ *
26
+ * @param value - The value to stringify
27
+ * @returns JSON string with consistently ordered object keys
28
+ *
29
+ * @example
30
+ *
31
+ * ```ts
32
+ * import { canonicalStringify } from "@apollo/client/utilities";
33
+ *
34
+ * const obj1 = { b: 2, a: 1 };
35
+ * const obj2 = { a: 1, b: 2 };
36
+ *
37
+ * console.log(canonicalStringify(obj1)); // '{"a":1,"b":2}'
38
+ * console.log(canonicalStringify(obj2)); // '{"a":1,"b":2}'
39
+ * ```
17
40
  */
18
41
  export declare const canonicalStringify: ((value: any) => string) & {
19
42
  reset(): void;
@@ -3,21 +3,44 @@ import { cacheSizes } from "../caching/sizes.js";
3
3
  import { AutoCleanedStrongCache } from "./caches.js";
4
4
  import { registerGlobalCache } from "./getMemoryInternals.js";
5
5
  /**
6
- * Like JSON.stringify, but with object keys always sorted in the same order.
6
+ * Serializes a value to JSON with object keys in a consistent, sorted order.
7
7
  *
8
- * To achieve performant sorting, this function uses a Map from JSON-serialized
8
+ * @remarks
9
+ *
10
+ * Unlike `JSON.stringify()`, this function ensures that object keys are always
11
+ * serialized in the same alphabetical order, regardless of their original order.
12
+ * This makes it suitable for creating consistent cache keys from objects,
13
+ * comparing objects by their serialized representation, or generating
14
+ * deterministic hashes of objects.
15
+ *
16
+ * To achieve performant sorting, this function uses a `Map` from JSON-serialized
9
17
  * arrays of keys (in any order) to sorted arrays of the same keys, with a
10
18
  * single sorted array reference shared by all permutations of the keys.
11
19
  *
12
- * As a drawback, this function will add a little bit more memory for every
13
- * object encountered that has different (more, less, a different order of) keys
14
- * than in the past.
20
+ * As a drawback, this function will add a little more memory for every object
21
+ * encountered that has different (more, less, a different order of) keys than
22
+ * in the past.
15
23
  *
16
24
  * In a typical application, this extra memory usage should not play a
17
25
  * significant role, as `canonicalStringify` will be called for only a limited
18
26
  * number of object shapes, and the cache will not grow beyond a certain point.
19
- * But in some edge cases, this could be a problem, so we provide
20
- * canonicalStringify.reset() as a way of clearing the cache.
27
+ * But in some edge cases, this could be a problem. Use canonicalStringify.reset()
28
+ * as a way to clear the memoization cache.
29
+ *
30
+ * @param value - The value to stringify
31
+ * @returns JSON string with consistently ordered object keys
32
+ *
33
+ * @example
34
+ *
35
+ * ```ts
36
+ * import { canonicalStringify } from "@apollo/client/utilities";
37
+ *
38
+ * const obj1 = { b: 2, a: 1 };
39
+ * const obj2 = { a: 1, b: 2 };
40
+ *
41
+ * console.log(canonicalStringify(obj1)); // '{"a":1,"b":2}'
42
+ * console.log(canonicalStringify(obj2)); // '{"a":1,"b":2}'
43
+ * ```
21
44
  */
22
45
  export const canonicalStringify = Object.assign(function canonicalStringify(value) {
23
46
  return JSON.stringify(value, stableObjectReplacer);
@@ -1 +1 @@
1
- {"version":3,"file":"canonicalStringify.js","sourceRoot":"","sources":["../../../src/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o/client/utilities/environment\";\n\nimport { cacheSizes, defaultCacheSizes } from \"../caching/sizes.js\";\n\nimport { AutoCleanedStrongCache } from \"./caches.js\";\nimport { registerGlobalCache } from \"./getMemoryInternals.js\";\n\n/**\n * Like JSON.stringify, but with object keys always sorted in the same order.\n *\n * To achieve performant sorting, this function uses a Map from JSON-serialized\n * arrays of keys (in any order) to sorted arrays of the same keys, with a\n * single sorted array reference shared by all permutations of the keys.\n *\n * As a drawback, this function will add a little bit more memory for every\n * object encountered that has different (more, less, a different order of) keys\n * than in the past.\n *\n * In a typical application, this extra memory usage should not play a\n * significant role, as `canonicalStringify` will be called for only a limited\n * number of object shapes, and the cache will not grow beyond a certain point.\n * But in some edge cases, this could be a problem, so we provide\n * canonicalStringify.reset() as a way of clearing the cache.\n */\nexport const canonicalStringify = Object.assign(\n function canonicalStringify(value: any): string {\n return JSON.stringify(value, stableObjectReplacer);\n },\n {\n reset() {\n // Clearing the sortingMap will reclaim all cached memory, without\n // affecting the logical results of canonicalStringify, but potentially\n // sacrificing performance until the cache is refilled.\n sortingMap = new AutoCleanedStrongCache<string, readonly string[]>(\n cacheSizes.canonicalStringify || defaultCacheSizes.canonicalStringify\n );\n },\n }\n);\n\nif (__DEV__) {\n registerGlobalCache(\"canonicalStringify\", () => sortingMap.size);\n}\n\n// Values are JSON-serialized arrays of object keys (in any order), and values\n// are sorted arrays of the same keys.\nlet sortingMap!: AutoCleanedStrongCache<string, readonly string[]>;\ncanonicalStringify.reset();\n\n// The JSON.stringify function takes an optional second argument called a\n// replacer function. This function is called for each key-value pair in the\n// object being stringified, and its return value is used instead of the\n// original value. If the replacer function returns a new value, that value is\n// stringified as JSON instead of the original value of the property.\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter\nfunction stableObjectReplacer(key: string, value: any) {\n if (value && typeof value === \"object\") {\n const proto = Object.getPrototypeOf(value);\n // We don't want to mess with objects that are not \"plain\" objects, which\n // means their prototype is either Object.prototype or null. This check also\n // prevents needlessly rearranging the indices of arrays.\n if (proto === Object.prototype || proto === null) {\n const keys = Object.keys(value);\n // If keys is already sorted, let JSON.stringify serialize the original\n // value instead of creating a new object with keys in the same order.\n if (keys.every(everyKeyInOrder)) return value;\n const unsortedKey = JSON.stringify(keys);\n let sortedKeys = sortingMap.get(unsortedKey);\n if (!sortedKeys) {\n keys.sort();\n const sortedKey = JSON.stringify(keys);\n // Checking for sortedKey in the sortingMap allows us to share the same\n // sorted array reference for all permutations of the same set of keys.\n sortedKeys = sortingMap.get(sortedKey) || keys;\n sortingMap.set(unsortedKey, sortedKeys);\n sortingMap.set(sortedKey, sortedKeys);\n }\n const sortedObject = Object.create(proto);\n // Reassigning the keys in sorted order will cause JSON.stringify to\n // serialize them in sorted order.\n sortedKeys.forEach((key) => {\n sortedObject[key] = value[key];\n });\n return sortedObject;\n }\n }\n return value;\n}\n\n// Since everything that happens in stableObjectReplacer benefits from being as\n// efficient as possible, we use a static function as the callback for\n// keys.every in order to test if the provided keys are already sorted without\n// allocating extra memory for a callback.\nfunction everyKeyInOrder(\n key: string,\n i: number,\n keys: readonly string[]\n): boolean {\n return i === 0 || keys[i - 1] <= key;\n}\n"]}
1
+ {"version":3,"file":"canonicalStringify.js","sourceRoot":"","sources":["../../../src/utilities/internal/canonicalStringify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAC7C,SAAS,kBAAkB,CAAC,KAAU;IACpC,OAAO,IAAI,CAAC,SAAS,CAAC,KAA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AC,IAAI,CAAC,CAAC;gBACvC,uEAAuE;gBACvE,uEAAuE;gBACvE,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;gBAC/C,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;gBACxC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YACxC,CAAC;YACD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1C,oEAAoE;YACpE,kCAAkC;YAClC,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACzB,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;YACH,OAAO,YAAY,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,+EAA+E;AAC/E,sEAAsE;AACtE,8EAA8E;AAC9E,0CAA0C;AAC1C,SAAS,eAAe,CACtB,GAAW,EACX,CAAS,EACT,IAAuB;IAEvB,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;AACvC,CAAC","sourcesContent":["import { __DEV__ } from \"@apollo/client/utilities/environment\";\n\nimport { cacheSizes, defaultCacheSizes } from \"../caching/sizes.js\";\n\nimport { AutoCleanedStrongCache } from \"./caches.js\";\nimport { registerGlobalCache } from \"./getMemoryInternals.js\";\n\n/**\n * Serializes a value to JSON with object keys in a consistent, sorted order.\n *\n * @remarks\n *\n * Unlike `JSON.stringify()`, this function ensures that object keys are always\n * serialized in the same alphabetical order, regardless of their original order.\n * This makes it suitable for creating consistent cache keys from objects,\n * comparing objects by their serialized representation, or generating\n * deterministic hashes of objects.\n *\n * To achieve performant sorting, this function uses a `Map` from JSON-serialized\n * arrays of keys (in any order) to sorted arrays of the same keys, with a\n * single sorted array reference shared by all permutations of the keys.\n *\n * As a drawback, this function will add a little more memory for every object\n * encountered that has different (more, less, a different order of) keys than\n * in the past.\n *\n * In a typical application, this extra memory usage should not play a\n * significant role, as `canonicalStringify` will be called for only a limited\n * number of object shapes, and the cache will not grow beyond a certain point.\n * But in some edge cases, this could be a problem. Use canonicalStringify.reset()\n * as a way to clear the memoization cache.\n *\n * @param value - The value to stringify\n * @returns JSON string with consistently ordered object keys\n *\n * @example\n *\n * ```ts\n * import { canonicalStringify } from \"@apollo/client/utilities\";\n *\n * const obj1 = { b: 2, a: 1 };\n * const obj2 = { a: 1, b: 2 };\n *\n * console.log(canonicalStringify(obj1)); // '{\"a\":1,\"b\":2}'\n * console.log(canonicalStringify(obj2)); // '{\"a\":1,\"b\":2}'\n * ```\n */\nexport const canonicalStringify = Object.assign(\n function canonicalStringify(value: any): string {\n return JSON.stringify(value, stableObjectReplacer);\n },\n {\n reset() {\n // Clearing the sortingMap will reclaim all cached memory, without\n // affecting the logical results of canonicalStringify, but potentially\n // sacrificing performance until the cache is refilled.\n sortingMap = new AutoCleanedStrongCache<string, readonly string[]>(\n cacheSizes.canonicalStringify || defaultCacheSizes.canonicalStringify\n );\n },\n }\n);\n\nif (__DEV__) {\n registerGlobalCache(\"canonicalStringify\", () => sortingMap.size);\n}\n\n// Values are JSON-serialized arrays of object keys (in any order), and values\n// are sorted arrays of the same keys.\nlet sortingMap!: AutoCleanedStrongCache<string, readonly string[]>;\ncanonicalStringify.reset();\n\n// The JSON.stringify function takes an optional second argument called a\n// replacer function. This function is called for each key-value pair in the\n// object being stringified, and its return value is used instead of the\n// original value. If the replacer function returns a new value, that value is\n// stringified as JSON instead of the original value of the property.\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter\nfunction stableObjectReplacer(key: string, value: any) {\n if (value && typeof value === \"object\") {\n const proto = Object.getPrototypeOf(value);\n // We don't want to mess with objects that are not \"plain\" objects, which\n // means their prototype is either Object.prototype or null. This check also\n // prevents needlessly rearranging the indices of arrays.\n if (proto === Object.prototype || proto === null) {\n const keys = Object.keys(value);\n // If keys is already sorted, let JSON.stringify serialize the original\n // value instead of creating a new object with keys in the same order.\n if (keys.every(everyKeyInOrder)) return value;\n const unsortedKey = JSON.stringify(keys);\n let sortedKeys = sortingMap.get(unsortedKey);\n if (!sortedKeys) {\n keys.sort();\n const sortedKey = JSON.stringify(keys);\n // Checking for sortedKey in the sortingMap allows us to share the same\n // sorted array reference for all permutations of the same set of keys.\n sortedKeys = sortingMap.get(sortedKey) || keys;\n sortingMap.set(unsortedKey, sortedKeys);\n sortingMap.set(sortedKey, sortedKeys);\n }\n const sortedObject = Object.create(proto);\n // Reassigning the keys in sorted order will cause JSON.stringify to\n // serialize them in sorted order.\n sortedKeys.forEach((key) => {\n sortedObject[key] = value[key];\n });\n return sortedObject;\n }\n }\n return value;\n}\n\n// Since everything that happens in stableObjectReplacer benefits from being as\n// efficient as possible, we use a static function as the callback for\n// keys.every in order to test if the provided keys are already sorted without\n// allocating extra memory for a callback.\nfunction everyKeyInOrder(\n key: string,\n i: number,\n keys: readonly string[]\n): boolean {\n return i === 0 || keys[i - 1] <= key;\n}\n"]}
@@ -1,12 +1,40 @@
1
1
  import type { DocumentNode, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
2
2
  /**
3
- * Returns the first operation definition found in this document.
4
- * If no operation definition is found, the first fragment definition will be returned.
5
- * If no definitions are found, an error will be thrown.
6
- *
7
- * @internal
8
- *
9
- * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
10
- */
3
+ * Returns the first operation definition from a GraphQL document. The function
4
+ * prioritizes operation definitions over fragment definitions, which makes it
5
+ * suitable for documents that may contain both. If no operation definition is
6
+ * found, the first fragment definition will be returned. If no definitions are
7
+ * found, an error is thrown.
8
+ *
9
+ * @remarks
10
+ *
11
+ * Use this function when you need to perform more advanced tasks with the main
12
+ * definition AST node. If you want to determine when a document is a specific
13
+ * operation type, prefer the `isQueryOperation`, `isMutationOperation`, and
14
+ * `isSubscriptionOperation` utility functions instead.
15
+ *
16
+ * @param queryDoc - The GraphQL document to extract the definition from
17
+ * @returns The main operation or fragment definition AST node
18
+ *
19
+ * @example
20
+ *
21
+ * ```ts
22
+ * import { gql } from "@apollo/client";
23
+ * import { getMainDefinition } from "@apollo/client/utilities";
24
+ *
25
+ * const query = gql`
26
+ * query GetUser($id: ID!) {
27
+ * user(id: $id) {
28
+ * name
29
+ * email
30
+ * }
31
+ * }
32
+ * `;
33
+ *
34
+ * const definition = getMainDefinition(query);
35
+ * ```
36
+ *
37
+ * @throws When the document contains no operation or fragment definitions
38
+ */
11
39
  export declare function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode;
12
- //# sourceMappingURL=getMainDefinition.d.ts.map
40
+ //# sourceMappingURL=getMainDefinition.d.ts.map
@@ -1,14 +1,42 @@
1
1
  import { newInvariantError } from "@apollo/client/utilities/invariant";
2
2
  import { checkDocument } from "./checkDocument.js";
3
3
  /**
4
- * Returns the first operation definition found in this document.
5
- * If no operation definition is found, the first fragment definition will be returned.
6
- * If no definitions are found, an error will be thrown.
7
- *
8
- * @internal
9
- *
10
- * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
11
- */
4
+ * Returns the first operation definition from a GraphQL document. The function
5
+ * prioritizes operation definitions over fragment definitions, which makes it
6
+ * suitable for documents that may contain both. If no operation definition is
7
+ * found, the first fragment definition will be returned. If no definitions are
8
+ * found, an error is thrown.
9
+ *
10
+ * @remarks
11
+ *
12
+ * Use this function when you need to perform more advanced tasks with the main
13
+ * definition AST node. If you want to determine when a document is a specific
14
+ * operation type, prefer the `isQueryOperation`, `isMutationOperation`, and
15
+ * `isSubscriptionOperation` utility functions instead.
16
+ *
17
+ * @param queryDoc - The GraphQL document to extract the definition from
18
+ * @returns The main operation or fragment definition AST node
19
+ *
20
+ * @example
21
+ *
22
+ * ```ts
23
+ * import { gql } from "@apollo/client";
24
+ * import { getMainDefinition } from "@apollo/client/utilities";
25
+ *
26
+ * const query = gql`
27
+ * query GetUser($id: ID!) {
28
+ * user(id: $id) {
29
+ * name
30
+ * email
31
+ * }
32
+ * }
33
+ * `;
34
+ *
35
+ * const definition = getMainDefinition(query);
36
+ * ```
37
+ *
38
+ * @throws When the document contains no operation or fragment definitions
39
+ */
12
40
  export function getMainDefinition(queryDoc) {
13
41
  checkDocument(queryDoc);
14
42
  let fragmentDefinition;
@@ -1 +1 @@
1
- {"version":3,"file":"getMainDefinition.js","sources":["../../../src/utilities/internal/getMainDefinition.ts"],"sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n OperationDefinitionNode,\n} from \"graphql\";\n\nimport { newInvariantError } from \"@apollo/client/utilities/invariant\";\n\nimport { checkDocument } from \"./checkDocument.js\";\n\n/**\n * Returns the first operation definition found in this document.\n * If no operation definition is found, the first fragment definition will be returned.\n * If no definitions are found, an error will be thrown.\n *\n * @internal\n */\nexport function getMainDefinition(\n queryDoc: DocumentNode\n): OperationDefinitionNode | FragmentDefinitionNode {\n checkDocument(queryDoc);\n\n let fragmentDefinition;\n\n for (let definition of queryDoc.definitions) {\n if (definition.kind === \"OperationDefinition\") {\n return definition;\n }\n\n if (definition.kind === \"FragmentDefinition\" && !fragmentDefinition) {\n // we do this because we want to allow multiple fragment definitions\n // to precede an operation definition.\n fragmentDefinition = definition;\n }\n }\n\n if (fragmentDefinition) {\n return fragmentDefinition;\n }\n\n throw newInvariantError(\n \"Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.\"\n );\n}\n"],"names":[],"mappings":"AAMA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAkC,CAAlC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CA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AAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;YACM,CAAN,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAA2B,CAA3B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAqC;QACjC;IACF;IAEA,CAAF,EAAA,CAAM,CAAN,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAwB,EAAE;QACtB,CAAJ,CAAA,CAAA,CAAA,CAAA,EAAW,CAAX,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA6B;IAC3B;IAEA,CAAF,CAAA,CAAA,CAAA,EAAQ,CAAR,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAEG;AACH;"}
1
+ {"version":3,"file":"getMainDefinition.js","sources":["../../../src/utilities/internal/getMainDefinition.ts"],"sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n OperationDefinitionNode,\n} from \"graphql\";\n\nimport { newInvariantError } from \"@apollo/client/utilities/invariant\";\n\nimport { checkDocument } from \"./checkDocument.js\";\n\n/**\n * Returns the first operation definition from a GraphQL document. The function\n * prioritizes operation definitions over fragment definitions, which makes it\n * suitable for documents that may contain both. If no operation definition is\n * found, the first fragment definition will be returned. If no definitions are\n * found, an error is thrown.\n *\n * @remarks\n *\n * Use this function when you need to perform more advanced tasks with the main\n * definition AST node. If you want to determine when a document is a specific\n * operation type, prefer the `isQueryOperation`, `isMutationOperation`, and\n * `isSubscriptionOperation` utility functions instead.\n *\n * @param queryDoc - The GraphQL document to extract the definition from\n * @returns The main operation or fragment definition AST node\n *\n * @example\n *\n * ```ts\n * import { gql } from \"@apollo/client\";\n * import { getMainDefinition } from \"@apollo/client/utilities\";\n *\n * const query = gql`\n * query GetUser($id: ID!) {\n * user(id: $id) {\n * name\n * email\n * }\n * }\n * `;\n *\n * const definition = getMainDefinition(query);\n * ```\n *\n * @throws When the document contains no operation or fragment definitions\n */\nexport function getMainDefinition(\n queryDoc: DocumentNode\n): OperationDefinitionNode | FragmentDefinitionNode {\n checkDocument(queryDoc);\n\n let fragmentDefinition;\n\n for (let definition of queryDoc.definitions) {\n if (definition.kind === \"OperationDefinition\") {\n return definition;\n }\n\n if (definition.kind === \"FragmentDefinition\" && !fragmentDefinition) {\n // we do this because we want to allow multiple fragment definitions\n // to precede an operation definition.\n fragmentDefinition = definition;\n }\n }\n\n if (fragmentDefinition) {\n return fragmentDefinition;\n }\n\n throw newInvariantError(\n \"Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.\"\n );\n}\n"],"names":[],"mappings":"AAMA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAkC,CAAlC,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,CAAA,CAAA,CAAA,CAAsE;AAEtE,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAA8B,CAA9B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA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CAAF,EAAA,CAAM,CAAN,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAwB,EAAE;QACtB,CAAJ,CAAA,CAAA,CAAA,CAAA,EAAW,CAAX,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA6B;IAC3B;IAEA,CAAF,CAAA,CAAA,CAAA,EAAQ,CAAR,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAEG;AACH;"}
@@ -52,7 +52,7 @@ export declare namespace DocumentationTypes {
52
52
  */
53
53
  error?: ErrorLike;
54
54
  /**
55
- * If `true`, the query is still in flight and results have not yet been returned.
55
+ * If `true`, the query is still in flight.
56
56
  *
57
57
  * @docGroup 2. Network info
58
58
  */