@envelop/response-cache 6.2.0 → 6.2.1-alpha-20240716141815-02fb524e

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/cjs/plugin.js CHANGED
@@ -67,32 +67,25 @@ const getDocumentWithMetadataAndTTL = (0, utils_1.memoize4)(function addTypeName
67
67
  SelectionSet(node, _key) {
68
68
  const parentType = typeInfo.getParentType();
69
69
  const idField = parentType && idFieldByTypeName.get(parentType.name);
70
- return {
71
- ...node,
72
- selections: [
73
- {
74
- kind: graphql_1.Kind.FIELD,
75
- name: {
76
- kind: graphql_1.Kind.NAME,
77
- value: '__typename',
78
- },
79
- alias: {
80
- kind: graphql_1.Kind.NAME,
81
- value: '__responseCacheTypeName',
82
- },
83
- },
84
- ...(idField
85
- ? [
86
- {
87
- kind: graphql_1.Kind.FIELD,
88
- name: { kind: graphql_1.Kind.NAME, value: idField },
89
- alias: { kind: graphql_1.Kind.NAME, value: '__responseCacheId' },
90
- },
91
- ]
92
- : []),
93
- ...node.selections,
94
- ],
95
- };
70
+ const hasTypeNameSelection = node.selections.find(selection => selection.kind === graphql_1.Kind.FIELD &&
71
+ selection.name.value === '__typename' &&
72
+ !selection.alias);
73
+ const selections = [...node.selections];
74
+ if (!hasTypeNameSelection) {
75
+ selections.push({
76
+ kind: graphql_1.Kind.FIELD,
77
+ name: { kind: graphql_1.Kind.NAME, value: '__typename' },
78
+ alias: { kind: graphql_1.Kind.NAME, value: '__responseCacheTypeName' },
79
+ });
80
+ }
81
+ if (idField) {
82
+ selections.push({
83
+ kind: graphql_1.Kind.FIELD,
84
+ name: { kind: graphql_1.Kind.NAME, value: idField },
85
+ alias: { kind: graphql_1.Kind.NAME, value: '__responseCacheId' },
86
+ });
87
+ }
88
+ return { ...node, selections };
96
89
  },
97
90
  };
98
91
  return [(0, graphql_1.visit)(document, (0, graphql_1.visitWithTypeInfo)(typeInfo, visitor)), ttl];
@@ -198,7 +191,7 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
198
191
  }
199
192
  return;
200
193
  }
201
- const typename = data.__responseCacheTypeName;
194
+ const typename = data.__responseCacheTypeName ?? data.__typename;
202
195
  delete data.__responseCacheTypeName;
203
196
  const entityId = data.__responseCacheId;
204
197
  delete data.__responseCacheId;
package/esm/plugin.js CHANGED
@@ -60,32 +60,25 @@ const getDocumentWithMetadataAndTTL = memoize4(function addTypeNameToDocument(do
60
60
  SelectionSet(node, _key) {
61
61
  const parentType = typeInfo.getParentType();
62
62
  const idField = parentType && idFieldByTypeName.get(parentType.name);
63
- return {
64
- ...node,
65
- selections: [
66
- {
67
- kind: Kind.FIELD,
68
- name: {
69
- kind: Kind.NAME,
70
- value: '__typename',
71
- },
72
- alias: {
73
- kind: Kind.NAME,
74
- value: '__responseCacheTypeName',
75
- },
76
- },
77
- ...(idField
78
- ? [
79
- {
80
- kind: Kind.FIELD,
81
- name: { kind: Kind.NAME, value: idField },
82
- alias: { kind: Kind.NAME, value: '__responseCacheId' },
83
- },
84
- ]
85
- : []),
86
- ...node.selections,
87
- ],
88
- };
63
+ const hasTypeNameSelection = node.selections.find(selection => selection.kind === Kind.FIELD &&
64
+ selection.name.value === '__typename' &&
65
+ !selection.alias);
66
+ const selections = [...node.selections];
67
+ if (!hasTypeNameSelection) {
68
+ selections.push({
69
+ kind: Kind.FIELD,
70
+ name: { kind: Kind.NAME, value: '__typename' },
71
+ alias: { kind: Kind.NAME, value: '__responseCacheTypeName' },
72
+ });
73
+ }
74
+ if (idField) {
75
+ selections.push({
76
+ kind: Kind.FIELD,
77
+ name: { kind: Kind.NAME, value: idField },
78
+ alias: { kind: Kind.NAME, value: '__responseCacheId' },
79
+ });
80
+ }
81
+ return { ...node, selections };
89
82
  },
90
83
  };
91
84
  return [visit(document, visitWithTypeInfo(typeInfo, visitor)), ttl];
@@ -191,7 +184,7 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
191
184
  }
192
185
  return;
193
186
  }
194
- const typename = data.__responseCacheTypeName;
187
+ const typename = data.__responseCacheTypeName ?? data.__typename;
195
188
  delete data.__responseCacheTypeName;
196
189
  const entityId = data.__responseCacheId;
197
190
  delete data.__responseCacheId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/response-cache",
3
- "version": "6.2.0",
3
+ "version": "6.2.1-alpha-20240716141815-02fb524e",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@envelop/core": "^5.0.0",