@pact-foundation/pact
Version:
Pact for all things Javascript
91 lines (90 loc) • 3.11 kB
TypeScript
import type { ASTNode } from 'graphql';
import { type GraphQLVariables } from '../../common/graphQL/graphQL';
import type { JsonMap } from '../../common/jsonTypes';
import { PactV3 } from '../pact';
import type { V3Request, V3Response } from '../types';
/**
* Expose a V3 compatible GraphQL interface
*
* Code borrowed/inspired from https://gist.github.com/wabrit/2d1e1f9520aa133908f0a3716338e5ff
*/
export declare class GraphQLPactV3 extends PactV3 {
private operation?;
private variables?;
private query;
private req?;
given(providerState: string, parameters?: JsonMap): GraphQLPactV3;
uponReceiving(description: string): GraphQLPactV3;
/**
* The GraphQL operation name, if used.
* @param operation {string} the name of the operation
* @return this object
*/
withOperation(operation: string): GraphQLPactV3;
/**
* Add variables used in the Query.
* @param variables {GraphQLVariables}
* @return this object
*/
withVariables(variables: GraphQLVariables): GraphQLPactV3;
/**
* The actual GraphQL query as a string.
*
* NOTE: spaces are not important, Pact will auto-generate a space-insensitive matcher
*
* e.g. the value for the "query" field in the GraphQL HTTP payload:
* '{ "query": "{
* Category(id:7) {
* id,
* name,
* subcategories {
* id,
* name
* }
* }
* }"
* }'
* @param query {string|ASTNode} parsed or unparsed query
* @return this object
*/
withQuery(query: string | ASTNode): GraphQLPactV3;
/**
* The actual GraphQL mutation as a string or parse tree.
*
* NOTE: spaces are not important, Pact will auto-generate a space-insensitive matcher
*
* e.g. the value for the "query" field in the GraphQL HTTP payload:
*
* mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
* createReview(episode: $ep, review: $review) {
* stars
* commentary
* }
* }
* @param mutation {string|ASTNode} parsed or unparsed mutation
* @return this object
*/
withMutation(mutation: string | ASTNode): GraphQLPactV3;
/**
* Used to pass in the method, path and content-type; the body detail would
* not typically be passed here as that will be internally constructed from
* withQuery/withMutation/withVariables calls.
*
* @see {@link withQuery}
* @see {@link withMutation}
* @see {@link withVariables}
* @param req {V3Request} request
* @return this object
*/
withRequest(req: V3Request): GraphQLPactV3;
/**
* Overridden as this is the "trigger point" by which we should have received all
* request information.
* @param res {V3Response} the expected response
* @returns this object
*/
willRespondWith(res: V3Response): GraphQLPactV3;
addInteraction(): GraphQLPactV3;
withRequestBinaryFile(): PactV3;
withRequestMultipartFileUpload(): PactV3;
}