Skip to content

Commit 9c3d2ee

Browse files
committed
use checkDocument instead of verifyDocumentType
1 parent ca9089b commit 9c3d2ee

File tree

10 files changed

+25
-166
lines changed

10 files changed

+25
-166
lines changed

src/__tests__/__snapshots__/exports.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ Array [
461461
"stringifyForDisplay",
462462
"stripTypename",
463463
"valueToObjectRepresentation",
464-
"verifyDocumentType",
465464
"wrapPromiseWithState",
466465
]
467466
`;

src/core/ApolloClient.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,6 @@ export class ApolloClient implements DataProxy {
891891
* ```json
892892
*{
893893
* limits: {
894-
* parser: 1000,
895894
* canonicalStringify: 1000,
896895
* print: 2000,
897896
* 'documentTransform.cache': 2000,
@@ -907,7 +906,6 @@ export class ApolloClient implements DataProxy {
907906
* 'inMemoryCache.executeSubSelectedArray': 5000
908907
* },
909908
* sizes: {
910-
* parser: 26,
911909
* canonicalStringify: 4,
912910
* print: 14,
913911
* addTypenameDocumentTransform: [

src/core/QueryManager.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ import { execute } from "@apollo/client/link/core";
3333
import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
3434
import { maskFragment, maskOperation } from "@apollo/client/masking";
3535
import type { DeepPartial } from "@apollo/client/utilities";
36-
import { print, verifyDocumentType } from "@apollo/client/utilities";
36+
import {
37+
checkDocument,
38+
print,
39+
verifyDocumentType,
40+
} from "@apollo/client/utilities";
3741
import { AutoCleanedWeakCache, cacheSizes } from "@apollo/client/utilities";
3842
import {
3943
addNonReactiveToNamedFragments,
@@ -274,7 +278,7 @@ export class QueryManager {
274278
"mutation option is required. You must specify your GraphQL document in the mutation option."
275279
);
276280

277-
verifyDocumentType(mutation, OperationTypeNode.MUTATION);
281+
checkDocument(mutation, OperationTypeNode.MUTATION);
278282

279283
invariant(
280284
fetchPolicy === "network-only" || fetchPolicy === "no-cache",
@@ -788,7 +792,7 @@ export class QueryManager {
788792
T,
789793
TVariables extends OperationVariables = OperationVariables,
790794
>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables> {
791-
verifyDocumentType(options.query, OperationTypeNode.QUERY);
795+
checkDocument(options.query, OperationTypeNode.QUERY);
792796

793797
const query = this.transform(options.query);
794798

@@ -826,7 +830,7 @@ export class QueryManager {
826830
options: QueryOptions<TVars, TData>,
827831
queryId = this.generateQueryId()
828832
): Promise<QueryResult<MaybeMasked<TData>>> {
829-
verifyDocumentType(options.query, OperationTypeNode.QUERY);
833+
checkDocument(options.query, OperationTypeNode.QUERY);
830834

831835
const query = this.transform(options.query);
832836

@@ -1031,7 +1035,7 @@ export class QueryManager {
10311035
extensions = {},
10321036
} = options;
10331037

1034-
verifyDocumentType(query, OperationTypeNode.SUBSCRIPTION);
1038+
checkDocument(query, OperationTypeNode.SUBSCRIPTION);
10351039

10361040
query = this.transform(query);
10371041
variables = this.getVariables(query, variables);

src/react/hooks/__tests__/useSuspenseQuery.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ describe("useSuspenseQuery", () => {
374374
});
375375
}).toThrowError(
376376
new InvariantError(
377-
"Running a Query requires a graphql Query, but a Mutation was used instead."
377+
"Running a query requires a graphql query, but a mutation was used instead."
378378
)
379379
);
380380
});

src/utilities/caching/__tests__/getMemoryInternals.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
} from "@apollo/client/core";
1111
import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries";
1212
import { removeTypenameFromVariables } from "@apollo/client/link/remove-typename";
13-
// importing react so the `parser` cache initializes
14-
import "@apollo/client/react";
1513
import { cacheSizes } from "@apollo/client/utilities";
1614

1715
// this is compiled away so we need to import it from sources
@@ -69,7 +67,6 @@ it("returns information about cache usage (empty caches)", () => {
6967
expect(client.getMemoryInternals?.()).toEqual({
7068
limits: defaultCacheSizesAsObject,
7169
sizes: {
72-
parser: 0,
7370
canonicalStringify: 0,
7471
print: 0,
7572
addTypenameDocumentTransform: [
@@ -148,7 +145,6 @@ it("returns information about cache usage (some query triggered)", () => {
148145
expect(client.getMemoryInternals?.()).toStrictEqual({
149146
limits: defaultCacheSizesAsObject,
150147
sizes: {
151-
parser: 0,
152148
canonicalStringify: 0,
153149
print: 1,
154150
addTypenameDocumentTransform: [

src/utilities/graphql/__tests__/verifyDocumentType.test.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/utilities/graphql/getFromAST.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
DocumentNode,
33
FragmentDefinitionNode,
44
OperationDefinitionNode,
5+
OperationTypeNode,
56
ValueNode,
67
} from "graphql";
78

@@ -17,7 +18,10 @@ type OperationDefinitionWithName = OperationDefinitionNode & {
1718
};
1819

1920
// Checks the document for errors and throws an exception if there is an error.
20-
export function checkDocument(doc: DocumentNode) {
21+
export function checkDocument(
22+
doc: DocumentNode,
23+
expectedType?: OperationTypeNode
24+
) {
2125
invariant(
2226
doc && doc.kind === "Document",
2327
`Expecting a parsed GraphQL document. Perhaps you need to wrap the query \
@@ -42,6 +46,16 @@ string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`
4246
operations.length
4347
);
4448

49+
if (expectedType) {
50+
invariant(
51+
operations.length == 1 && operations[0].operation === expectedType,
52+
`Running a %s requires a graphql ` + `%s, but a %s was used instead.`,
53+
expectedType,
54+
expectedType,
55+
operations[0].operation
56+
);
57+
}
58+
4559
return doc;
4660
}
4761

src/utilities/graphql/verifyDocumentType.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/utilities/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ export {
9191
isSubscriptionOperation,
9292
} from "./graphql/operations.js";
9393

94-
export { verifyDocumentType } from "./graphql/verifyDocumentType.js";
95-
9694
export {
9795
concatPagination,
9896
offsetLimitPagination,

src/utilities/internal/getMemoryInternals.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ function _getApolloClientMemoryInternals(this: ApolloClient) {
137137
limits: getCurrentCacheSizes(),
138138
sizes: {
139139
print: globalCaches.print?.(),
140-
parser: globalCaches.parser?.(),
141140
canonicalStringify: globalCaches.canonicalStringify?.(),
142141
links: linkInfo(this.link),
143142
queryManager: {

0 commit comments

Comments
 (0)