@apollo/client
Version:
A fully-featured caching GraphQL client.
92 lines (91 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMutationOperation = isMutationOperation;
exports.isQueryOperation = isQueryOperation;
exports.isSubscriptionOperation = isSubscriptionOperation;
const internal_1 = require("@apollo/client/utilities/internal");
function isOperation(document, operation) {
return (0, internal_1.getOperationDefinition)(document)?.operation === operation;
}
/**
* Determine if a document is a mutation document.
*
* @remarks
* If you are authoring an Apollo link, you might not need this utility.
* Prefer using the `operationType` property the `operation` object instead.
*
* @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
* ```
*/
function isMutationOperation(document) {
return isOperation(document, "mutation");
}
/**
* Determine if a document is a query document.
*
* @remarks
* If you are authoring an Apollo link, you might not need this utility.
* Prefer using the `operationType` property the `operation` object instead.
*
* @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
* ```
*/
function isQueryOperation(document) {
return isOperation(document, "query");
}
/**
* Determine if a document is a subscription document.
*
* @remarks
* If you are authoring an Apollo link, you might not need this utility.
* Prefer using the `operationType` property the `operation` object instead.
*
* @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
* ```
*/
function isSubscriptionOperation(document) {
return isOperation(document, "subscription");
}
//# sourceMappingURL=operations.cjs.map