UNPKG

graphql-paper

Version:

A flexible in-memory store based on a GraphQL Schema

24 lines (22 loc) 709 B
'use strict'; var getDocumentKey = require('../document/get-document-key.js'); function removeOperation(context, keyOrDocument) { const { store } = context; const key = getDocumentKey.getDocumentKey(keyOrDocument); let document; Object.entries(store).forEach(([type, documents]) => { const found = documents.find(document => getDocumentKey.getDocumentKey(document) === key); if (found) { store[type] = documents.filter(document => document !== found); document = found; } }); if (!document) { throw new Error(`Could not find document with ${key} to remove`); } return document; } exports.removeOperation = removeOperation; //# sourceMappingURL=remove.js.map