@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 +20 -27
- package/esm/plugin.js +20 -27
- package/package.json +1 -1
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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;
|