Skip to content

Instantly share code, notes, and snippets.

@elnygren
Created April 9, 2019 01:01
Show Gist options
  • Save elnygren/240c3a1d2beca3e29672bf6f64c82849 to your computer and use it in GitHub Desktop.
Save elnygren/240c3a1d2beca3e29672bf6f64c82849 to your computer and use it in GitHub Desktop.
ReasonML snippets
/**
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