-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathoperations.ts
More file actions
81 lines (77 loc) · 1.83 KB
/
Copy pathoperations.ts
File metadata and controls
81 lines (77 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import type { DocumentNode } from "@apollo/client";
import { getOperationDefinition } from "@apollo/client/utilities/internal";
function isOperation(
document: DocumentNode,
operation: "query" | "mutation" | "subscription"
) {
return getOperationDefinition(document)?.operation === operation;
}
/**
* Determine if a document is a mutation document.
*
* @param document - The GraphQL document to check
* @returns A boolean indicating if the document is a mutation operation
*
* @example
*
* ```ts
* import { isMutationOperation } from "@apollo/client/utilities";
*
* const mutation = gql`
* mutation MyMutation {
* # ...
* }
* `;
*
* isMutationOperation(mutation); // true
* ```
*/
export function isMutationOperation(document: DocumentNode) {
return isOperation(document, "mutation");
}
/**
* Determine if a document is a query document.
*
* @param document - The GraphQL document to check
* @returns A boolean indicating if the document is a query operation
*
* @example
*
* ```ts
* import { isQueryOperation } from "@apollo/client/utilities";
*
* const query = gql`
* query MyQuery {
* # ...
* }
* `;
*
* isQueryOperation(query); // true
* ```
*/
export function isQueryOperation(document: DocumentNode) {
return isOperation(document, "query");
}
/**
* Determine if a document is a subscription document.
*
* @param document - The GraphQL document to check
* @returns A boolean indicating if the document is a subscription operation
*
* @example
*
* ```ts
* import { isSubscriptionOperation } from "@apollo/client/utilities";
*
* const subscription = gql`
* subscription MySubscription {
* # ...
* }
* `;
*
* isSubscriptionOperation(subscription); // true
* ```
*/
export function isSubscriptionOperation(document: DocumentNode) {
return isOperation(document, "subscription");
}