Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Apollo Client Delete Fragment

node v6.17.1
version: master
endpointsharetweet
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