Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-query-rewriter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-query-rewriter - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0

55

dist/index.es5.js

@@ -258,7 +258,19 @@ import { parse, print, parseType } from 'graphql';

if (path.length === 0)
return callback(results);
return results;
var curPathElm = path[0];
var remainingPath = path.slice(1);
var newResults = __assign({}, results);
var curResults = results[curPathElm];
if (path.length === 1) {
if (Array.isArray(curResults)) {
newResults[curPathElm] = curResults.map(function (_, index) {
var newValue = callback(curResults, index);
return newValue;
});
}
else {
newResults[curPathElm] = callback(results, curPathElm);
}
return newResults;
}
var remainingPath = path.slice(1);
// if the path stops here, just return results without any rewriting

@@ -268,9 +280,9 @@ if (curResults === undefined || curResults === null)

if (Array.isArray(curResults)) {
newResults[curPathElm] = curResults.reduce(function (acc, resultElm) {
var elmResults = rewriteResultsAtPath(resultElm, remainingPath, callback);
return acc.concat(elmResults);
}, []);
return newResults;
newResults[curPathElm] = curResults.map(function (result) {
return rewriteResultsAtPath(result, remainingPath, callback);
});
}
newResults[curPathElm] = rewriteResultsAtPath(curResults, remainingPath, callback);
else {
newResults[curPathElm] = rewriteResultsAtPath(curResults, remainingPath, callback);
}
return newResults;

@@ -343,4 +355,4 @@ };

paths.forEach(function (path) {
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (responseAtPath) {
return rewriter.rewriteResponse(responseAtPath);
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key) {
return rewriter.rewriteResponse(parentResponse, key);
});

@@ -391,4 +403,4 @@ });

};
Rewriter.prototype.rewriteResponse = function (response) {
return response;
Rewriter.prototype.rewriteResponse = function (response, key) {
return response[key];
};

@@ -603,7 +615,9 @@ return Rewriter;

};
NestFieldOutputsRewriter.prototype.rewriteResponse = function (response) {
if (typeof response === 'object') {
NestFieldOutputsRewriter.prototype.rewriteResponse = function (response, key) {
var pathResponse = _super.prototype.rewriteResponse.call(this, response, key);
if (typeof pathResponse === 'object') {
// undo the nesting in the response so it matches the original query
if (response[this.newOutputName] && typeof response[this.newOutputName] === 'object') {
var rewrittenResponse = __assign({}, response, response[this.newOutputName]);
if (pathResponse[this.newOutputName] &&
typeof pathResponse[this.newOutputName] === 'object') {
var rewrittenResponse = __assign({}, pathResponse, pathResponse[this.newOutputName]);
delete rewrittenResponse[this.newOutputName];

@@ -613,3 +627,3 @@ return rewrittenResponse;

}
return response;
return pathResponse;
};

@@ -659,8 +673,9 @@ return NestFieldOutputsRewriter;

};
ScalarFieldToObjectFieldRewriter.prototype.rewriteResponse = function (response) {
ScalarFieldToObjectFieldRewriter.prototype.rewriteResponse = function (response, key) {
var pathResponse = _super.prototype.rewriteResponse.call(this, response, key);
if (typeof response === 'object') {
// undo the nesting in the response so it matches the original query
return response[this.objectFieldName];
return pathResponse[this.objectFieldName];
}
return response;
return pathResponse;
};

@@ -667,0 +682,0 @@ return ScalarFieldToObjectFieldRewriter;

@@ -262,7 +262,19 @@ (function (global, factory) {

if (path.length === 0)
return callback(results);
return results;
var curPathElm = path[0];
var remainingPath = path.slice(1);
var newResults = __assign({}, results);
var curResults = results[curPathElm];
if (path.length === 1) {
if (Array.isArray(curResults)) {
newResults[curPathElm] = curResults.map(function (_, index) {
var newValue = callback(curResults, index);
return newValue;
});
}
else {
newResults[curPathElm] = callback(results, curPathElm);
}
return newResults;
}
var remainingPath = path.slice(1);
// if the path stops here, just return results without any rewriting

@@ -272,9 +284,9 @@ if (curResults === undefined || curResults === null)

if (Array.isArray(curResults)) {
newResults[curPathElm] = curResults.reduce(function (acc, resultElm) {
var elmResults = rewriteResultsAtPath(resultElm, remainingPath, callback);
return acc.concat(elmResults);
}, []);
return newResults;
newResults[curPathElm] = curResults.map(function (result) {
return rewriteResultsAtPath(result, remainingPath, callback);
});
}
newResults[curPathElm] = rewriteResultsAtPath(curResults, remainingPath, callback);
else {
newResults[curPathElm] = rewriteResultsAtPath(curResults, remainingPath, callback);
}
return newResults;

@@ -347,4 +359,4 @@ };

paths.forEach(function (path) {
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (responseAtPath) {
return rewriter.rewriteResponse(responseAtPath);
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key) {
return rewriter.rewriteResponse(parentResponse, key);
});

@@ -395,4 +407,4 @@ });

};
Rewriter.prototype.rewriteResponse = function (response) {
return response;
Rewriter.prototype.rewriteResponse = function (response, key) {
return response[key];
};

@@ -607,7 +619,9 @@ return Rewriter;

};
NestFieldOutputsRewriter.prototype.rewriteResponse = function (response) {
if (typeof response === 'object') {
NestFieldOutputsRewriter.prototype.rewriteResponse = function (response, key) {
var pathResponse = _super.prototype.rewriteResponse.call(this, response, key);
if (typeof pathResponse === 'object') {
// undo the nesting in the response so it matches the original query
if (response[this.newOutputName] && typeof response[this.newOutputName] === 'object') {
var rewrittenResponse = __assign({}, response, response[this.newOutputName]);
if (pathResponse[this.newOutputName] &&
typeof pathResponse[this.newOutputName] === 'object') {
var rewrittenResponse = __assign({}, pathResponse, pathResponse[this.newOutputName]);
delete rewrittenResponse[this.newOutputName];

@@ -617,3 +631,3 @@ return rewrittenResponse;

}
return response;
return pathResponse;
};

@@ -663,8 +677,9 @@ return NestFieldOutputsRewriter;

};
ScalarFieldToObjectFieldRewriter.prototype.rewriteResponse = function (response) {
ScalarFieldToObjectFieldRewriter.prototype.rewriteResponse = function (response, key) {
var pathResponse = _super.prototype.rewriteResponse.call(this, response, key);
if (typeof response === 'object') {
// undo the nesting in the response so it matches the original query
return response[this.objectFieldName];
return pathResponse[this.objectFieldName];
}
return response;
return pathResponse;
};

@@ -671,0 +686,0 @@ return ScalarFieldToObjectFieldRewriter;

@@ -222,7 +222,19 @@ "use strict";

if (path.length === 0)
return callback(results);
return results;
var curPathElm = path[0];
var remainingPath = path.slice(1);
var newResults = __assign({}, results);
var curResults = results[curPathElm];
if (path.length === 1) {
if (Array.isArray(curResults)) {
newResults[curPathElm] = curResults.map(function (_, index) {
var newValue = callback(curResults, index);
return newValue;
});
}
else {
newResults[curPathElm] = callback(results, curPathElm);
}
return newResults;
}
var remainingPath = path.slice(1);
// if the path stops here, just return results without any rewriting

@@ -232,11 +244,11 @@ if (curResults === undefined || curResults === null)

if (Array.isArray(curResults)) {
newResults[curPathElm] = curResults.reduce(function (acc, resultElm) {
var elmResults = exports.rewriteResultsAtPath(resultElm, remainingPath, callback);
return acc.concat(elmResults);
}, []);
return newResults;
newResults[curPathElm] = curResults.map(function (result) {
return exports.rewriteResultsAtPath(result, remainingPath, callback);
});
}
newResults[curPathElm] = exports.rewriteResultsAtPath(curResults, remainingPath, callback);
else {
newResults[curPathElm] = exports.rewriteResultsAtPath(curResults, remainingPath, callback);
}
return newResults;
};
//# sourceMappingURL=ast.js.map

@@ -69,4 +69,4 @@ "use strict";

paths.forEach(function (path) {
rewrittenResponse = ast_1.rewriteResultsAtPath(rewrittenResponse, path, function (responseAtPath) {
return rewriter.rewriteResponse(responseAtPath);
rewrittenResponse = ast_1.rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key) {
return rewriter.rewriteResponse(parentResponse, key);
});

@@ -73,0 +73,0 @@ });

@@ -77,7 +77,9 @@ "use strict";

};
NestFieldOutputsRewriter.prototype.rewriteResponse = function (response) {
if (typeof response === 'object') {
NestFieldOutputsRewriter.prototype.rewriteResponse = function (response, key) {
var pathResponse = _super.prototype.rewriteResponse.call(this, response, key);
if (typeof pathResponse === 'object') {
// undo the nesting in the response so it matches the original query
if (response[this.newOutputName] && typeof response[this.newOutputName] === 'object') {
var rewrittenResponse = __assign({}, response, response[this.newOutputName]);
if (pathResponse[this.newOutputName] &&
typeof pathResponse[this.newOutputName] === 'object') {
var rewrittenResponse = __assign({}, pathResponse, pathResponse[this.newOutputName]);
delete rewrittenResponse[this.newOutputName];

@@ -87,3 +89,3 @@ return rewrittenResponse;

}
return response;
return pathResponse;
};

@@ -90,0 +92,0 @@ return NestFieldOutputsRewriter;

@@ -40,4 +40,4 @@ "use strict";

};
Rewriter.prototype.rewriteResponse = function (response) {
return response;
Rewriter.prototype.rewriteResponse = function (response, key) {
return response[key];
};

@@ -44,0 +44,0 @@ return Rewriter;

@@ -68,8 +68,9 @@ "use strict";

};
ScalarFieldToObjectFieldRewriter.prototype.rewriteResponse = function (response) {
ScalarFieldToObjectFieldRewriter.prototype.rewriteResponse = function (response, key) {
var pathResponse = _super.prototype.rewriteResponse.call(this, response, key);
if (typeof response === 'object') {
// undo the nesting in the response so it matches the original query
return response[this.objectFieldName];
return pathResponse[this.objectFieldName];
}
return response;
return pathResponse;
};

@@ -76,0 +77,0 @@ return ScalarFieldToObjectFieldRewriter;

@@ -46,3 +46,3 @@ import { ASTNode, DocumentNode, VariableDefinitionNode } from 'graphql';

/** @hidden */
export declare const rewriteResultsAtPath: (results: ResultObj, path: ReadonlyArray<string>, callback: (resultsAtPath: any) => any) => ResultObj;
export declare const rewriteResultsAtPath: (results: ResultObj, path: ReadonlyArray<string>, callback: (parentResult: any, key: string | number) => any) => ResultObj;
export {};

@@ -18,4 +18,4 @@ import { ASTNode } from 'graphql';

rewriteQuery(nodeAndVarDefs: NodeAndVarDefs): NodeAndVarDefs;
rewriteResponse(response: any): any;
rewriteResponse(response: any, key: string | number): any;
}
export default NestFieldOutputsRewriter;

@@ -25,4 +25,4 @@ import { ASTNode } from 'graphql';

rewriteVariables(nodeAndVarDefs: NodeAndVarDefs, variables: Variables): Variables;
rewriteResponse(response: any): any;
rewriteResponse(response: any, key: string | number): any;
}
export default Rewriter;

@@ -16,4 +16,4 @@ import { ASTNode } from 'graphql';

rewriteQuery(nodeAndVarDefs: NodeAndVarDefs): NodeAndVarDefs;
rewriteResponse(response: any): any;
rewriteResponse(response: any, key: string | number): any;
}
export default ScalarFieldToObjectFieldRewriter;
{
"name": "graphql-query-rewriter",
"version": "1.4.0",
"version": "2.0.0",
"description": "",

@@ -5,0 +5,0 @@ "keywords": [],

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc