Created
April 9, 2019 01:01
-
-
Save elnygren/240c3a1d2beca3e29672bf6f64c82849 to your computer and use it in GitHub Desktop.
ReasonML snippets
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
/** | |
Very nasty way to control Apollo cache in reason-apollo | |
*/ | |
[@bs.module] external gql: ReasonApolloTypes.gql = "graphql-tag"; | |
let shifts_query = | |
gql(. | |
"fragment shiftDraftStatus on shifts_listedshift { | |
uuid | |
draft | |
}", | |
); | |
let shifts_query_update_cache = [%raw | |
{| | |
function update(cache, data) { | |
const {uuid, draft} = data.data.update_shifts_listedshift.returning[0] | |
const fragmentId = `shifts_listedshift:${uuid}` | |
const shift = cache.readFragment({ | |
id: fragmentId, | |
fragment: shifts_query, | |
}) | |
cache.writeFragment({ | |
id: fragmentId, | |
fragment: shifts_query, | |
data: { draft, __typename: "shifts_listedshift" } | |
}); | |
} | |
|} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment