Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public fragmentMatches(
fragment: InlineFragmentNode | FragmentDefinitionNode,
typename: string,
): boolean {
if (!fragment.typeCondition) return true;
const supertype = fragment.typeCondition.name.value;
invariant(
typename,
`Attempted to match fragment ${
fragment.kind === "InlineFragment" ? "" : fragment.name.value + " "
}with type condition ${supertype} against object with unknown __typename`,
);
if (typename === supertype) return true;
if (this.usingPossibleTypes) {
const workQueue = [this.getSubtypeSet(supertype, false)];
// It's important to keep evaluating workQueue.length each time through
// the loop, because the queue can grow while we're iterating over it.
for (let i = 0; i < workQueue.length; ++i) {
const subtypes = workQueue[i];
if (subtypes) {
if (subtypes.has(typename)) return true;
specifier.forEach(s => {
if (Array.isArray(s)) {
if (typeof prevKey === "string") {
const subsets = aliasMap && aliasMap.subsets;
const subset = subsets && subsets[prevKey];
keyObj[prevKey] = computeKeyObject(response[prevKey], s, subset);
}
} else {
const aliases = aliasMap && aliasMap.aliases;
const responseName = aliases && aliases[s] || s;
invariant(
hasOwn.call(response, responseName),
// TODO Make this appropriate for keyArgs as well
`Missing field ${responseName} while computing key fields`,
);
keyObj[prevKey = s] = response[responseName];
}
});
return keyObj;
private setRootTypename(
which: "Query" | "Mutation" | "Subscription",
typename: string,
) {
const rootId = "ROOT_" + which.toUpperCase();
const old = this.rootTypenamesById[rootId];
if (typename !== old) {
invariant(old === which, `Cannot change root ${which} __typename more than once`);
(this.rootTypenamesById as any)[rootId] = typename;
}
}