Skip to content

Instantly share code, notes, and snippets.

@mlg87
Created July 21, 2020 21:00
Show Gist options
  • Save mlg87/e0a7b5759b36221ff04951d1b25bbba2 to your computer and use it in GitHub Desktop.
Save mlg87/e0a7b5759b36221ff04951d1b25bbba2 to your computer and use it in GitHub Desktop.
Using Apollo Client for global state management code samples - src/Balloon/mutations.ts
// src/Balloon/mutations.ts
import { Resolver } from "apollo-client";
import gql from "graphql-tag";
//
// ─── GQL TAGS ───────────────────────────────────────────────────────────────────
//
export const SetSelectedBalloonLocal = gql`
mutation SetSelectedBalloonLocal($selectedBalloon: BalloonInput!) {
setSelectedBalloon(selectedBalloon: $selectedBalloon) @client
}
`;
//
// ─── RESOLVERS ──────────────────────────────────────────────────────────────────
//
export const setSelectedBalloonMutationResolver: Resolver = (
_root,
{ selectedBalloon },
{ cache }
) => {
try {
cache.writeData({ data: { selectedBalloon } });
} catch (error) {
console.error("Error writing selectedBalloon to local cache: ", error);
}
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment