@apollo/client/core#MutationOptions TypeScript Examples

The following examples show how to use @apollo/client/core#MutationOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: execute-pr-actions.ts    From dt-mergebot with MIT License 6 votes vote down vote up
export async function executePrActions(actions: Actions, pr: PR_repository_pullRequest, dry?: boolean) {
    const botComments: ParsedComment[] = getBotComments(pr);
    const mutations = noNullish([
        // the mutations are ordered for presentation in the timeline:
        // * welcome comment is always first
        // * then labels, as a short "here's what I noticed"
        // * column changes after that (follow the labels since this is the consequence)
        // * state changes next, similar to column changes
        // * finally, any other comments (better to see label changes and then a comment that explains what happens now)
        ...getMutationsForComments(actions, pr.id, botComments, true),
        ...await getMutationsForLabels(actions, pr),
        ...await getMutationsForProjectChanges(actions, pr),
        ...getMutationsForCommentRemovals(actions, botComments),
        ...getMutationsForChangingPRState(actions, pr),
        ...getMutationsForComments(actions, pr.id, botComments, false),
    ]);
    const restCalls = getMutationsForReRunningCI(actions);
    if (!dry) {
        // Perform mutations one at a time
        for (const mutation of mutations)
            await client.mutate(mutation as MutationOptions<void, typeof mutations[number]["variables"]>);
        for (const restCall of restCalls)
            await doRestCall(restCall);
    }
    return [...mutations, ...restCalls];
}
Example #2
Source File: graphql-client.ts    From dt-mergebot with MIT License 6 votes vote down vote up
export function createMutation<T>(name: keyof schema.Mutation, input: T, subquery?: string): MutationOptions<void, { input: T }> {
    const mutation = {
        toJSON: () => print(mutation),
        ...(gql`mutation($input: ${name[0]!.toUpperCase() + name.slice(1)}Input!) {
                    ${name}(input: $input) {
                        __typename
                        ${subquery || ""}
                    }
                }` as TypedDocumentNode<void, { input: T }>),
    };
    return { mutation, variables: { input } };
}