Created
July 21, 2020 21:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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