UNPKG

graphql-paper

Version:

A flexible in-memory store based on a GraphQL Schema

51 lines (48 loc) 3.1 kB
'use strict'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var constants = require('../constants.js'); var generateDocumentKey = require('./generate-document-key.js'); // eslint-disable-next-line @typescript-eslint/no-explicit-any function createDocument(typename, // eslint-disable-next-line @typescript-eslint/no-explicit-any partial, key) { var _ref, _partial$constants$DO, _partial$constants$DO2; if (!typename) { throw new Error('The document type name is a required argument'); } const document = _objectSpread({}, partial); Object.defineProperty(document, constants.DOCUMENT_KEY_SYMBOL, { enumerable: false, configurable: false, // eslint-disable-next-line @typescript-eslint/no-explicit-any value: (_ref = (_partial$constants$DO = partial[constants.DOCUMENT_KEY_SYMBOL]) !== null && _partial$constants$DO !== void 0 ? _partial$constants$DO : key) !== null && _ref !== void 0 ? _ref : generateDocumentKey.generateDocumentKey() }); Object.defineProperty(document, constants.DOCUMENT_GRAPHQL_TYPENAME, { enumerable: false, configurable: false, value: typename }); Object.defineProperty(document, constants.DOCUMENT_CONNECTIONS_SYMBOL, { enumerable: false, configurable: false, // eslint-disable-next-line @typescript-eslint/no-explicit-any value: (_partial$constants$DO2 = partial[constants.DOCUMENT_CONNECTIONS_SYMBOL]) !== null && _partial$constants$DO2 !== void 0 ? _partial$constants$DO2 : {} }); Object.defineProperty(document, '__typename', { configurable: false, enumerable: false, get() { return document[constants.DOCUMENT_GRAPHQL_TYPENAME]; }, set() { throw new Error('__typename on the document cannot be set'); } }); return document; } exports.createDocument = createDocument; //# sourceMappingURL=create-document.js.map