UNPKG

908 BJavaScriptView Raw
1import { __assign } from "tslib";
2import { visit } from "graphql";
3export function filterOperationVariables(variables, query) {
4 var result = __assign({}, variables);
5 var unusedNames = new Set(Object.keys(variables));
6 visit(query, {
7 Variable: function (node, _key, parent) {
8 // A variable type definition at the top level of a query is not
9 // enough to silence server-side errors about the variable being
10 // unused, so variable definitions do not count as usage.
11 // https://spec.graphql.org/draft/#sec-All-Variables-Used
12 if (parent &&
13 parent.kind !== "VariableDefinition") {
14 unusedNames.delete(node.name.value);
15 }
16 },
17 });
18 unusedNames.forEach(function (name) {
19 delete result[name];
20 });
21 return result;
22}
23//# sourceMappingURL=filterOperationVariables.js.map
\No newline at end of file