Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
Apollo Client Delete Fragment
node v6.17.1
version:
master
endpoint
share
tweet
const ApolloClient = require('apollo-client'); require('graphql/language/parser'); // just to make runkit happy const gql = require('graphql-tag'); const client = new ApolloClient.ApolloClient({ dataIdFromObject(obj) { return obj.id; }, addTypeName: true }); const fragment = gql`fragment update on person{ id __typename }`; const id = 'person-01'; const __typename = '__typename';
Write a fragment in and read it back out:
client.writeFragment({ fragment, id, data: { id, __typename } }); client.readFragment({ fragment, id }); // should get { __typename: '__typename', id: 'person-1' }
Now, how do I delete that fragment back out?
Trying to `writeFragment` with `null` as the data:
client.writeFragment({ fragment, id, data: null }); client.readFragment({ fragment, id }); // fragment is still there
Trying to `writeFragment` with an empty object:
client.writeFragment({ fragment, id, data: {} }); client.readFragment({ fragment, id }); // fragment is still there
client.writeFragment({ fragment, id, data: undefined }); client.readFragment({ fragment, id }); // fragment is still there
Loading…
no comments
sign in
to comment