Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import gql from 'graphql-tag';
import { IFieldResolver } from 'graphql-tools';
import { Mutation } from 'react-apollo';
import { ISSUE_PARTS as issueQueryFragments } from '../flows';
import { IssueStepParts, UpdateIssuename, UpdateIssueNameVariables } from '../../graphql-types';
import { ResolverContext } from '.';
export const QUERY = gql`
mutation UpdateIssueName($input: UpdateIssueNameInput!) {
pdateIssueName(input: $input) @client
}
`;
export class UpdateIssueNameMutation extends Mutation<UpdateIssueName, UpdateIssueNameVariables> {}
const updateIssuename: IFieldResolver<void, ResolverContext, any> = (
_obj,
args: UpdateIssueNameVariables,
context,
) => {
const { input } = args;
const { cache, getCacheKey } = context;
// 1. Get the id of the object in the cache using the actual issue id
const id = getCacheKey({ __typename: 'Issue', id: input.id });
const fragment = gql`
${issueQueryFragments}
fragment IssueParts on Issue {
id
name
}
`;
// 2. Get the data from the cache
const step: IssueParts | null = cache.readFragment({
fragment,
fragmentName: 'IssueParts',
id,
});
if (!issue) {
return null;
}
// 3. Update the data locally
const updateIssue = {
...issue,
name: input.name,
};
// 4. Write the data back to the cache
cache.writeFragment({
fragment,
fragmentName: 'IssueParts',
id,
data: updatedStep,
});
return null;
};
export default updateIssuename;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.