@4c/graphql-node-resource
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,1 +1,8 @@ | ||
## [1.0.2](https://github.com/4Catalyzer/graphql-server/compare/v1.0.1...v1.0.2) (2019-03-22) | ||
### Bug Fixes | ||
* Fix resource caching for batches ([#37](https://github.com/4Catalyzer/graphql-server/issues/37)) ([a5aaa4a](https://github.com/4Catalyzer/graphql-server/commit/a5aaa4a)) | ||
## [1.0.1](https://github.com/4Catalyzer/graphql-server/compare/v1.0.0...v1.0.1) (2019-03-20) | ||
@@ -2,0 +9,0 @@ |
@@ -7,3 +7,3 @@ import HttpResource from './resources/HttpResource'; | ||
import fetch from './api/fetch'; | ||
import createNodeType from './types/NodeType'; | ||
import createNodeType, { RESOURCE_CACHE_KEY } from './types/NodeType'; | ||
import asType from './utils/asType'; | ||
@@ -19,3 +19,3 @@ import resolveThunk from './utils/resolveThunk'; | ||
}; | ||
export { HttpApi, HttpError, fetch, HttpResource, PaginatedHttpResource, Resource, createNodeType }; | ||
export { createNodeType, fetch, HttpApi, HttpError, HttpResource, PaginatedHttpResource, Resource, RESOURCE_CACHE_KEY }; | ||
export { NodeFieldResolver, NodeFieldConfig, NodeFieldConfigMap, CreateNodeTypeArgs } from './types/NodeType'; |
@@ -11,2 +11,6 @@ /* eslint-disable no-underscore-dangle */ | ||
import Resource from '../resources/Resource'; | ||
// Apollo Server shallowly clones the context for each request in a batch, | ||
// making the context object inappropriate as a batch-level cache key. Use this | ||
// to manually assign a cache key for the full batch. | ||
export const RESOURCE_CACHE_KEY = Symbol('resource cache key'); | ||
export default function createNodeType({ | ||
@@ -169,3 +173,4 @@ fieldNameResolver = d => d, | ||
getResource(context) { | ||
let resources = Resources.get(context); | ||
const cacheKey = context[RESOURCE_CACHE_KEY] || context; | ||
let resources = Resources.get(cacheKey); | ||
@@ -175,3 +180,3 @@ if (!resources) { | ||
resources = new Map(); | ||
Resources.set(context, resources); | ||
Resources.set(cacheKey, resources); | ||
} | ||
@@ -178,0 +183,0 @@ |
@@ -33,2 +33,3 @@ "use strict"; | ||
exports.createNodeType = _NodeType.default; | ||
exports.RESOURCE_CACHE_KEY = _NodeType.RESOURCE_CACHE_KEY; | ||
exports.NodeFieldResolver = _NodeType.NodeFieldResolver; | ||
@@ -35,0 +36,0 @@ exports.NodeFieldConfig = _NodeType.NodeFieldConfig; |
@@ -5,2 +5,3 @@ "use strict"; | ||
exports.default = createNodeType; | ||
exports.RESOURCE_CACHE_KEY = void 0; | ||
@@ -28,2 +29,8 @@ var _graphql = require("graphql"); | ||
/* eslint-disable no-underscore-dangle */ | ||
// Apollo Server shallowly clones the context for each request in a batch, | ||
// making the context object inappropriate as a batch-level cache key. Use this | ||
// to manually assign a cache key for the full batch. | ||
const RESOURCE_CACHE_KEY = Symbol('resource cache key'); | ||
exports.RESOURCE_CACHE_KEY = RESOURCE_CACHE_KEY; | ||
function createNodeType({ | ||
@@ -186,3 +193,4 @@ fieldNameResolver = d => d, | ||
getResource(context) { | ||
let resources = Resources.get(context); | ||
const cacheKey = context[RESOURCE_CACHE_KEY] || context; | ||
let resources = Resources.get(cacheKey); | ||
@@ -192,3 +200,3 @@ if (!resources) { | ||
resources = new Map(); | ||
Resources.set(context, resources); | ||
Resources.set(cacheKey, resources); | ||
} | ||
@@ -195,0 +203,0 @@ |
{ | ||
"name": "@4c/graphql-node-resource", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
86925
1019