@common-stack/graphql-api 0.5.1-alpha.4 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +69 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/cache-paginated-queries.factory.d.ts +11 -0
- package/lib/utils/index.d.ts +1 -0
- package/package.json +4 -3
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -70,6 +70,7 @@ const root_schema_graphqls_1 = __webpack_require__(/*! ./api/root-schema.graphql
|
|
|
70
70
|
exports.rootSchemaDef = root_schema_graphqls_1.default;
|
|
71
71
|
__exportStar(__webpack_require__(/*! ./api/resolver */ "./src/api/resolver.ts"), exports);
|
|
72
72
|
__exportStar(__webpack_require__(/*! ./scalars */ "./src/scalars/index.ts"), exports);
|
|
73
|
+
__exportStar(__webpack_require__(/*! ./utils */ "./src/utils/index.ts"), exports);
|
|
73
74
|
|
|
74
75
|
|
|
75
76
|
/***/ }),
|
|
@@ -131,6 +132,64 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
131
132
|
__exportStar(__webpack_require__(/*! ./anyobject */ "./src/scalars/anyobject.ts"), exports);
|
|
132
133
|
|
|
133
134
|
|
|
135
|
+
/***/ }),
|
|
136
|
+
|
|
137
|
+
/***/ "./src/utils/cache-paginated-queries.factory.ts":
|
|
138
|
+
/*!******************************************************!*\
|
|
139
|
+
!*** ./src/utils/cache-paginated-queries.factory.ts ***!
|
|
140
|
+
\******************************************************/
|
|
141
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
145
|
+
exports.cachePaginatedQueriesFactory = exports.DEFAULT_LIMIT = exports.DEFAULT_SKIP = void 0;
|
|
146
|
+
const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
|
|
147
|
+
exports.DEFAULT_SKIP = 0;
|
|
148
|
+
exports.DEFAULT_LIMIT = 10;
|
|
149
|
+
const cachePaginatedQueriesFactory = (queries) => {
|
|
150
|
+
return queries.reduce((acc, query) => {
|
|
151
|
+
const queryName = typeof query === 'string' ? query : query.name;
|
|
152
|
+
const keyArgs = typeof query === 'string' ? ['criteria', 'sort'] : query.keyArgs;
|
|
153
|
+
const skipKey = typeof query === 'string' ? 'skip' : query.skipKey;
|
|
154
|
+
const limitKey = typeof query === 'string' ? 'limit' : query.limitKey;
|
|
155
|
+
return Object.assign(Object.assign({}, acc), { [queryName]: {
|
|
156
|
+
keyArgs,
|
|
157
|
+
merge(existing, incoming, { args }) {
|
|
158
|
+
const skip = (0, lodash_1.get)(args, skipKey) || exports.DEFAULT_SKIP;
|
|
159
|
+
const merged = (existing === null || existing === void 0 ? void 0 : existing.data.length) > 0 ? existing.data.slice(0) : [];
|
|
160
|
+
incoming === null || incoming === void 0 ? void 0 : incoming.data.forEach((curr, index) => {
|
|
161
|
+
merged[skip + index] = curr;
|
|
162
|
+
});
|
|
163
|
+
return Object.assign(Object.assign({}, incoming), { data: merged });
|
|
164
|
+
},
|
|
165
|
+
read(existing, { args }) {
|
|
166
|
+
var _a;
|
|
167
|
+
const skip = (0, lodash_1.get)(args, skipKey) || exports.DEFAULT_SKIP;
|
|
168
|
+
const limit = (0, lodash_1.get)(args, limitKey) || exports.DEFAULT_LIMIT;
|
|
169
|
+
const data = (existing === null || existing === void 0 ? void 0 : existing.data) && ((_a = existing === null || existing === void 0 ? void 0 : existing.data) === null || _a === void 0 ? void 0 : _a.slice(skip, skip + limit));
|
|
170
|
+
return Object.assign(Object.assign({}, existing), { data });
|
|
171
|
+
},
|
|
172
|
+
} });
|
|
173
|
+
}, {});
|
|
174
|
+
};
|
|
175
|
+
exports.cachePaginatedQueriesFactory = cachePaginatedQueriesFactory;
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
/***/ }),
|
|
179
|
+
|
|
180
|
+
/***/ "./src/utils/index.ts":
|
|
181
|
+
/*!****************************!*\
|
|
182
|
+
!*** ./src/utils/index.ts ***!
|
|
183
|
+
\****************************/
|
|
184
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
188
|
+
exports.cachePaginatedQueriesFactory = void 0;
|
|
189
|
+
var cache_paginated_queries_factory_1 = __webpack_require__(/*! ./cache-paginated-queries.factory */ "./src/utils/cache-paginated-queries.factory.ts");
|
|
190
|
+
Object.defineProperty(exports, "cachePaginatedQueriesFactory", ({ enumerable: true, get: function () { return cache_paginated_queries_factory_1.cachePaginatedQueriesFactory; } }));
|
|
191
|
+
|
|
192
|
+
|
|
134
193
|
/***/ }),
|
|
135
194
|
|
|
136
195
|
/***/ "@cdmbase/graphql-type-uri":
|
|
@@ -171,6 +230,16 @@ module.exports = require("graphql-iso-date");
|
|
|
171
230
|
|
|
172
231
|
module.exports = require("graphql-type-json");
|
|
173
232
|
|
|
233
|
+
/***/ }),
|
|
234
|
+
|
|
235
|
+
/***/ "lodash":
|
|
236
|
+
/*!*************************!*\
|
|
237
|
+
!*** external "lodash" ***!
|
|
238
|
+
\*************************/
|
|
239
|
+
/***/ ((module) => {
|
|
240
|
+
|
|
241
|
+
module.exports = require("lodash");
|
|
242
|
+
|
|
174
243
|
/***/ })
|
|
175
244
|
|
|
176
245
|
/******/ });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;AAAA,iEAAe,mRAAmR,wBAAwB,4DAA4D,iEAAiE,mIAAmI,8FAA8F,0EAA0E,qDAAqD,qBAAqB,yCAAyC,eAAe,6CAA6C,kBAAkB,uBAAuB,gBAAgB,mFAAmF,mBAAmB,mBAAmB,uBAAuB,mBAAmB,6BAA6B,mBAAmB,+FAA+F,cAAc,qBAAqB,oBAAoB,cAAc,6EAA6E,KAAK;;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EA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;UENA;UACA;UACA;UACA","sources":["webpack://@common-stack/graphql-api/./src/api/root-schema.graphqls","webpack://@common-stack/graphql-api/./src/api/resolver.ts","webpack://@common-stack/graphql-api/./src/index.ts","webpack://@common-stack/graphql-api/./src/scalars/anyobject.ts","webpack://@common-stack/graphql-api/./src/scalars/index.ts","webpack://@common-stack/graphql-api/external commonjs \"@cdmbase/graphql-type-uri\"","webpack://@common-stack/graphql-api/external commonjs \"graphql\"","webpack://@common-stack/graphql-api/external commonjs \"graphql-iso-date\"","webpack://@common-stack/graphql-api/external commonjs \"graphql-type-json\"","webpack://@common-stack/graphql-api/webpack/bootstrap","webpack://@common-stack/graphql-api/webpack/runtime/define property getters","webpack://@common-stack/graphql-api/webpack/runtime/hasOwnProperty shorthand","webpack://@common-stack/graphql-api/webpack/runtime/make namespace object","webpack://@common-stack/graphql-api/webpack/before-startup","webpack://@common-stack/graphql-api/webpack/startup","webpack://@common-stack/graphql-api/webpack/after-startup"],"sourcesContent":["export default \"scalar AnyObject\\nscalar Date\\nscalar Time\\nscalar DateTime\\nscalar URI\\nscalar URIInput\\nscalar Observable\\n\\nscalar JSON\\nscalar JSONObject\\n\\ndirective @cacheControl(maxAge: Int, scope: CacheControlScope) on FIELD_DEFINITION | OBJECT | INTERFACE\\nenum CacheControlScope {\\n PUBLIC\\n PRIVATE\\n}\\n\\n\\\"\\\"\\\"\\n An object with an ID.\\n\\\"\\\"\\\"\\ninterface Node {\\n \\\"\\\"\\\"\\n The ID of the node.\\n \\\"\\\"\\\"\\n id: ID!\\n}\\n\\n# Pagination information. See https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo.\\ntype PageInfo {\\n # Whether there is a next page of nodes in the connection.\\n hasNextPage: Boolean!\\n}\\n\\n\\\"\\\"\\\"\\n Represents a null return value.\\n\\\"\\\"\\\"\\ntype EmptyResponse {\\n # A dummy null value.\\n alwaysNil: String\\n}\\n\\ntype FieldError {\\n field: String!\\n message: String!\\n}\\n\\ninput Sort{\\n key: String!,\\n value: SortEnum!,\\n}\\n\\nenum SortEnum{\\n ASC,\\n DESC\\n}\\n\\ntype Query {\\n \\\"\\\"\\\"\\n Looks up a node by ID.\\n \\\"\\\"\\\"\\n node(id: ID!): Node\\n\\n}\\n\\ntype Mutation {\\n dummy: Int\\n}\\n\\ntype Subscription {\\n dummy: Int\\n}\\n\\n\\ntype AdminIdeSettings {\\n dummy: Int\\n}\\n\\n\\\"\\\"\\\" All Moleculer Topic names are extended from this.\\\"\\\"\\\"\\nenum MoleculerServiceName {\\n dummy\\n}\\n\\n#interface Node {\\n# id: ID!\\n#}\\n\\n\\nschema {\\n query: Query\\n mutation: Mutation\\n subscription: Subscription\\n}\\n\\n\";","import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';\nimport { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date';\nimport GraphQLURI from '@cdmbase/graphql-type-uri';\nimport { GraphQLAnyObject } from '../scalars/anyobject';\n\nexport const resolvers = {\n AnyObject: GraphQLAnyObject,\n Date: GraphQLDate,\n Time: GraphQLTime,\n URI: GraphQLURI('URI'),\n URIInput: GraphQLURI('URIInput'),\n DateTime: GraphQLDateTime,\n JSON: GraphQLJSON,\n JSONObject: GraphQLJSONObject,\n};\n","import rootSchemaDef from './api/root-schema.graphqls';\n\nexport * from './api/resolver';\nexport { rootSchemaDef };\nexport * from './scalars';","// add any scalar types\nimport { GraphQLError, GraphQLScalarType, Kind } from 'graphql';\n\n//https://stackoverflow.com/questions/41557536/custom-map-keys-in-graphql-response\nexport const GraphQLAnyObject = new GraphQLScalarType({\n name: 'AnyObject',\n description: 'Any JSON object. This type bypasses type checking.',\n serialize: value => {\n return value;\n },\n parseValue: value => {\n return value;\n },\n parseLiteral: ast => {\n if (ast.kind !== Kind.OBJECT) {\n throw new GraphQLError(\"Query error: Can only parse object but got a: \" + ast.kind, [ast]);\n }\n return ast.fields;\n }\n});\n\n","export * from './anyobject';\n","module.exports = require(\"@cdmbase/graphql-type-uri\");","module.exports = require(\"graphql\");","module.exports = require(\"graphql-iso-date\");","module.exports = require(\"graphql-type-json\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(\"./src/index.ts\");\n",""],"names":[],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;AAAA,iEAAe,mRAAmR,wBAAwB,4DAA4D,iEAAiE,mIAAmI,8FAA8F,0EAA0E,qDAAqD,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wBACnC,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC;oBAChC,CAAC,CAAE;oBACH,uCAAY,QAAQ,KAAE,IAAI,EAAE,MAAM,IAAG;gBACzC,CAAC;gBACD,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE;;oBACnB,MAAM,IAAI,GAAG,gBAAG,EAAC,IAAI,EAAE,OAAO,CAAC,IAAI,oBAAY,CAAC;oBAChD,MAAM,KAAK,GAAG,gBAAG,EAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,qBAAa,CAAC;oBACnD,MAAM,IAAI,GAAG,SAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAI,cAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,0CAAE,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC,EAAC;oBACzE,uCACO,QAAQ,KACX,IAAI,IACP;gBACL,CAAC;aACJ,IACJ;IACL,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AA9BY,oCAA4B,gCA8BxC;;;;;;;;;;;;;;AC5CD,uJAAiF;AAAxE,4KAA4B;;;;;;;;;;;ACArC;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;UENA;UACA;UACA;UACA","sources":["webpack://@common-stack/graphql-api/./src/api/root-schema.graphqls","webpack://@common-stack/graphql-api/./src/api/resolver.ts","webpack://@common-stack/graphql-api/./src/index.ts","webpack://@common-stack/graphql-api/./src/scalars/anyobject.ts","webpack://@common-stack/graphql-api/./src/scalars/index.ts","webpack://@common-stack/graphql-api/./src/utils/cache-paginated-queries.factory.ts","webpack://@common-stack/graphql-api/./src/utils/index.ts","webpack://@common-stack/graphql-api/external commonjs \"@cdmbase/graphql-type-uri\"","webpack://@common-stack/graphql-api/external commonjs \"graphql\"","webpack://@common-stack/graphql-api/external commonjs \"graphql-iso-date\"","webpack://@common-stack/graphql-api/external commonjs \"graphql-type-json\"","webpack://@common-stack/graphql-api/external commonjs \"lodash\"","webpack://@common-stack/graphql-api/webpack/bootstrap","webpack://@common-stack/graphql-api/webpack/runtime/define property getters","webpack://@common-stack/graphql-api/webpack/runtime/hasOwnProperty shorthand","webpack://@common-stack/graphql-api/webpack/runtime/make namespace object","webpack://@common-stack/graphql-api/webpack/before-startup","webpack://@common-stack/graphql-api/webpack/startup","webpack://@common-stack/graphql-api/webpack/after-startup"],"sourcesContent":["export default \"scalar AnyObject\\nscalar Date\\nscalar Time\\nscalar DateTime\\nscalar URI\\nscalar URIInput\\nscalar Observable\\n\\nscalar JSON\\nscalar JSONObject\\n\\ndirective @cacheControl(maxAge: Int, scope: CacheControlScope) on FIELD_DEFINITION | OBJECT | INTERFACE\\nenum CacheControlScope {\\n PUBLIC\\n PRIVATE\\n}\\n\\n\\\"\\\"\\\"\\n An object with an ID.\\n\\\"\\\"\\\"\\ninterface Node {\\n \\\"\\\"\\\"\\n The ID of the node.\\n \\\"\\\"\\\"\\n id: ID!\\n}\\n\\n# Pagination information. See https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo.\\ntype PageInfo {\\n # Whether there is a next page of nodes in the connection.\\n hasNextPage: Boolean!\\n}\\n\\n\\\"\\\"\\\"\\n Represents a null return value.\\n\\\"\\\"\\\"\\ntype EmptyResponse {\\n # A dummy null value.\\n alwaysNil: String\\n}\\n\\ntype FieldError {\\n field: String!\\n message: String!\\n}\\n\\ninput Sort{\\n key: String!,\\n value: SortEnum!,\\n}\\n\\nenum SortEnum{\\n ASC,\\n DESC\\n}\\n\\ntype Query {\\n \\\"\\\"\\\"\\n Looks up a node by ID.\\n \\\"\\\"\\\"\\n node(id: ID!): Node\\n\\n}\\n\\ntype Mutation {\\n dummy: Int\\n}\\n\\ntype Subscription {\\n dummy: Int\\n}\\n\\n\\ntype AdminIdeSettings {\\n dummy: Int\\n}\\n\\n\\\"\\\"\\\" All Moleculer Topic names are extended from this.\\\"\\\"\\\"\\nenum MoleculerServiceName {\\n dummy\\n}\\n\\n#interface Node {\\n# id: ID!\\n#}\\n\\n\\nschema {\\n query: Query\\n mutation: Mutation\\n subscription: Subscription\\n}\\n\\n\";","import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';\nimport { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date';\nimport GraphQLURI from '@cdmbase/graphql-type-uri';\nimport { GraphQLAnyObject } from '../scalars/anyobject';\n\nexport const resolvers = {\n AnyObject: GraphQLAnyObject,\n Date: GraphQLDate,\n Time: GraphQLTime,\n URI: GraphQLURI('URI'),\n URIInput: GraphQLURI('URIInput'),\n DateTime: GraphQLDateTime,\n JSON: GraphQLJSON,\n JSONObject: GraphQLJSONObject,\n};\n","import rootSchemaDef from './api/root-schema.graphqls';\n\nexport * from './api/resolver';\nexport { rootSchemaDef };\nexport * from './scalars';\nexport * from './utils';\n","// add any scalar types\nimport { GraphQLError, GraphQLScalarType, Kind } from 'graphql';\n\n//https://stackoverflow.com/questions/41557536/custom-map-keys-in-graphql-response\nexport const GraphQLAnyObject = new GraphQLScalarType({\n name: 'AnyObject',\n description: 'Any JSON object. This type bypasses type checking.',\n serialize: value => {\n return value;\n },\n parseValue: value => {\n return value;\n },\n parseLiteral: ast => {\n if (ast.kind !== Kind.OBJECT) {\n throw new GraphQLError(\"Query error: Can only parse object but got a: \" + ast.kind, [ast]);\n }\n return ast.fields;\n }\n});\n\n","export * from './anyobject';\n","import { get } from 'lodash';\nimport { TypePolicies } from '@apollo/client';\n\ninterface QueryOptionsInterface {\n name: string,\n keyArgs?: (string[] | string)[]\n skipKey?: string,\n limitKey?: string,\n}\n\n\nexport const DEFAULT_SKIP = 0;\nexport const DEFAULT_LIMIT = 10;\n\nexport const cachePaginatedQueriesFactory = (queries: (string | QueryOptionsInterface)[]): TypePolicies => {\n return queries.reduce((acc, query) => {\n const queryName = typeof query === 'string' ? query : query.name;\n const keyArgs = typeof query === 'string' ? ['criteria', 'sort'] : query.keyArgs;\n const skipKey = typeof query === 'string' ? 'skip' : query.skipKey;\n const limitKey = typeof query === 'string' ? 'limit' : query.limitKey;\n return {\n ...acc,\n [queryName]: {\n keyArgs,\n merge(existing, incoming, { args }) {\n const skip = get(args, skipKey) || DEFAULT_SKIP;\n const merged = existing?.data.length > 0 ? existing.data.slice(0) : [];\n incoming?.data.forEach((curr, index) => {\n merged[skip + index] = curr;\n },)\n return { ...incoming, data: merged };\n },\n read(existing, { args }) {\n const skip = get(args, skipKey) || DEFAULT_SKIP;\n const limit = get(args, limitKey) || DEFAULT_LIMIT;\n const data = existing?.data && existing?.data?.slice(skip, skip + limit);\n return {\n ...existing,\n data,\n }\n },\n }\n }\n }, {})\n}\n","export { cachePaginatedQueriesFactory } from './cache-paginated-queries.factory';\n","module.exports = require(\"@cdmbase/graphql-type-uri\");","module.exports = require(\"graphql\");","module.exports = require(\"graphql-iso-date\");","module.exports = require(\"graphql-type-json\");","module.exports = require(\"lodash\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(\"./src/index.ts\");\n",""],"names":[],"sourceRoot":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TypePolicies } from '@apollo/client';
|
|
2
|
+
interface QueryOptionsInterface {
|
|
3
|
+
name: string;
|
|
4
|
+
keyArgs?: (string[] | string)[];
|
|
5
|
+
skipKey?: string;
|
|
6
|
+
limitKey?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const DEFAULT_SKIP = 0;
|
|
9
|
+
export declare const DEFAULT_LIMIT = 10;
|
|
10
|
+
export declare const cachePaginatedQueriesFactory: (queries: (string | QueryOptionsInterface)[]) => TypePolicies;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { cachePaginatedQueriesFactory } from './cache-paginated-queries.factory';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/graphql-api",
|
|
3
|
-
"version": "0.5.1
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "graphql api for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -44,12 +44,13 @@
|
|
|
44
44
|
"graphql-type-json": "^0.3.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@cdm-logger/core": ">=7.0.12"
|
|
47
|
+
"@cdm-logger/core": ">=7.0.12",
|
|
48
|
+
"lodash": "^4.17.21"
|
|
48
49
|
},
|
|
49
50
|
"publishConfig": {
|
|
50
51
|
"access": "public"
|
|
51
52
|
},
|
|
52
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "538ae6c1d76cf8734f8244225470047c68d0c4aa",
|
|
53
54
|
"typescript": {
|
|
54
55
|
"definition": "lib/index.d.ts"
|
|
55
56
|
}
|