graphql-query-rewriter-rc
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -373,7 +373,7 @@ import { Kind, parse, print, isValueNode, parseType } from 'graphql'; | ||
} | ||
_this.matches.push({ | ||
rewriter: rewriter, | ||
_this.matches.push(__assign({ rewriter: rewriter, | ||
fieldPaths: fieldPaths, | ||
allPaths: allPaths | ||
}); | ||
allPaths: allPaths }, (rewriter.saveNode | ||
? { nodeMatchAndParents: parents.concat([rewrittenNodeAndVars.node]) } | ||
: {}))); | ||
} | ||
@@ -397,6 +397,8 @@ return isMatch; | ||
this.matches.reverse().forEach(function (_a) { | ||
var rewriter = _a.rewriter, fieldPaths = _a.fieldPaths, allPaths = _a.allPaths; | ||
var rewriter = _a.rewriter, fieldPaths = _a.fieldPaths, allPaths = _a.allPaths, nodeMatchAndParents = _a.nodeMatchAndParents; | ||
var paths = rewriter.matchAnyPath ? allPaths : fieldPaths; | ||
paths.forEach(function (path) { | ||
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key, index) { return rewriter.rewriteResponse(parentResponse, key, index); }); | ||
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key, index) { | ||
return rewriter.rewriteResponse(parentResponse, key, index, nodeMatchAndParents); | ||
}); | ||
}); | ||
@@ -415,4 +417,5 @@ }); | ||
function Rewriter(_a) { | ||
var fieldName = _a.fieldName, rootTypes = _a.rootTypes, matchConditions = _a.matchConditions, _b = _a.matchAnyPath, matchAnyPath = _b === void 0 ? false : _b; | ||
var fieldName = _a.fieldName, rootTypes = _a.rootTypes, matchConditions = _a.matchConditions, _b = _a.matchAnyPath, matchAnyPath = _b === void 0 ? false : _b, _c = _a.saveNode, saveNode = _c === void 0 ? false : _c; | ||
this.matchAnyPath = false; | ||
this.saveNode = false; | ||
this.rootTypes = ['query', 'mutation', 'fragment']; | ||
@@ -422,2 +425,3 @@ this.fieldName = fieldName; | ||
this.matchAnyPath = matchAnyPath; | ||
this.saveNode = saveNode; | ||
if (!this.fieldName && !this.matchConditions) { | ||
@@ -462,3 +466,3 @@ throw new Error('Neither a fieldName or matchConditions were provided. Please choose to pass either one in order to be able to detect which fields to rewrite.'); | ||
*/ | ||
Rewriter.prototype.rewriteResponse = function (response, key, index) { | ||
Rewriter.prototype.rewriteResponse = function (response, key, index, nodeMatchAndParents) { | ||
return response; | ||
@@ -1004,4 +1008,4 @@ }; | ||
}; | ||
CustomRewriter.prototype.rewriteResponse = function (response, key, index) { | ||
return this.rewriteResponseFn(response, key, index); | ||
CustomRewriter.prototype.rewriteResponse = function (response, key, index, nodeMatchAndParents) { | ||
return this.rewriteResponseFn(response, key, index, nodeMatchAndParents); | ||
}; | ||
@@ -1008,0 +1012,0 @@ return CustomRewriter; |
@@ -377,7 +377,7 @@ (function (global, factory) { | ||
} | ||
_this.matches.push({ | ||
rewriter: rewriter, | ||
_this.matches.push(__assign({ rewriter: rewriter, | ||
fieldPaths: fieldPaths, | ||
allPaths: allPaths | ||
}); | ||
allPaths: allPaths }, (rewriter.saveNode | ||
? { nodeMatchAndParents: parents.concat([rewrittenNodeAndVars.node]) } | ||
: {}))); | ||
} | ||
@@ -401,6 +401,8 @@ return isMatch; | ||
this.matches.reverse().forEach(function (_a) { | ||
var rewriter = _a.rewriter, fieldPaths = _a.fieldPaths, allPaths = _a.allPaths; | ||
var rewriter = _a.rewriter, fieldPaths = _a.fieldPaths, allPaths = _a.allPaths, nodeMatchAndParents = _a.nodeMatchAndParents; | ||
var paths = rewriter.matchAnyPath ? allPaths : fieldPaths; | ||
paths.forEach(function (path) { | ||
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key, index) { return rewriter.rewriteResponse(parentResponse, key, index); }); | ||
rewrittenResponse = rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key, index) { | ||
return rewriter.rewriteResponse(parentResponse, key, index, nodeMatchAndParents); | ||
}); | ||
}); | ||
@@ -419,4 +421,5 @@ }); | ||
function Rewriter(_a) { | ||
var fieldName = _a.fieldName, rootTypes = _a.rootTypes, matchConditions = _a.matchConditions, _b = _a.matchAnyPath, matchAnyPath = _b === void 0 ? false : _b; | ||
var fieldName = _a.fieldName, rootTypes = _a.rootTypes, matchConditions = _a.matchConditions, _b = _a.matchAnyPath, matchAnyPath = _b === void 0 ? false : _b, _c = _a.saveNode, saveNode = _c === void 0 ? false : _c; | ||
this.matchAnyPath = false; | ||
this.saveNode = false; | ||
this.rootTypes = ['query', 'mutation', 'fragment']; | ||
@@ -426,2 +429,3 @@ this.fieldName = fieldName; | ||
this.matchAnyPath = matchAnyPath; | ||
this.saveNode = saveNode; | ||
if (!this.fieldName && !this.matchConditions) { | ||
@@ -466,3 +470,3 @@ throw new Error('Neither a fieldName or matchConditions were provided. Please choose to pass either one in order to be able to detect which fields to rewrite.'); | ||
*/ | ||
Rewriter.prototype.rewriteResponse = function (response, key, index) { | ||
Rewriter.prototype.rewriteResponse = function (response, key, index, nodeMatchAndParents) { | ||
return response; | ||
@@ -1008,4 +1012,4 @@ }; | ||
}; | ||
CustomRewriter.prototype.rewriteResponse = function (response, key, index) { | ||
return this.rewriteResponseFn(response, key, index); | ||
CustomRewriter.prototype.rewriteResponse = function (response, key, index, nodeMatchAndParents) { | ||
return this.rewriteResponseFn(response, key, index, nodeMatchAndParents); | ||
}; | ||
@@ -1012,0 +1016,0 @@ return CustomRewriter; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -48,7 +59,7 @@ var graphql_1 = require("graphql"); | ||
} | ||
_this.matches.push({ | ||
rewriter: rewriter, | ||
_this.matches.push(__assign({ rewriter: rewriter, | ||
fieldPaths: fieldPaths, | ||
allPaths: allPaths | ||
}); | ||
allPaths: allPaths }, (rewriter.saveNode | ||
? { nodeMatchAndParents: parents.concat([rewrittenNodeAndVars.node]) } | ||
: {}))); | ||
} | ||
@@ -72,6 +83,8 @@ return isMatch; | ||
this.matches.reverse().forEach(function (_a) { | ||
var rewriter = _a.rewriter, fieldPaths = _a.fieldPaths, allPaths = _a.allPaths; | ||
var rewriter = _a.rewriter, fieldPaths = _a.fieldPaths, allPaths = _a.allPaths, nodeMatchAndParents = _a.nodeMatchAndParents; | ||
var paths = rewriter.matchAnyPath ? allPaths : fieldPaths; | ||
paths.forEach(function (path) { | ||
rewrittenResponse = ast_1.rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key, index) { return rewriter.rewriteResponse(parentResponse, key, index); }); | ||
rewrittenResponse = ast_1.rewriteResultsAtPath(rewrittenResponse, path, function (parentResponse, key, index) { | ||
return rewriter.rewriteResponse(parentResponse, key, index, nodeMatchAndParents); | ||
}); | ||
}); | ||
@@ -78,0 +91,0 @@ }); |
@@ -58,4 +58,4 @@ "use strict"; | ||
}; | ||
CustomRewriter.prototype.rewriteResponse = function (response, key, index) { | ||
return this.rewriteResponseFn(response, key, index); | ||
CustomRewriter.prototype.rewriteResponse = function (response, key, index, nodeMatchAndParents) { | ||
return this.rewriteResponseFn(response, key, index, nodeMatchAndParents); | ||
}; | ||
@@ -62,0 +62,0 @@ return CustomRewriter; |
@@ -9,4 +9,5 @@ "use strict"; | ||
function Rewriter(_a) { | ||
var fieldName = _a.fieldName, rootTypes = _a.rootTypes, matchConditions = _a.matchConditions, _b = _a.matchAnyPath, matchAnyPath = _b === void 0 ? false : _b; | ||
var fieldName = _a.fieldName, rootTypes = _a.rootTypes, matchConditions = _a.matchConditions, _b = _a.matchAnyPath, matchAnyPath = _b === void 0 ? false : _b, _c = _a.saveNode, saveNode = _c === void 0 ? false : _c; | ||
this.matchAnyPath = false; | ||
this.saveNode = false; | ||
this.rootTypes = ['query', 'mutation', 'fragment']; | ||
@@ -16,2 +17,3 @@ this.fieldName = fieldName; | ||
this.matchAnyPath = matchAnyPath; | ||
this.saveNode = saveNode; | ||
if (!this.fieldName && !this.matchConditions) { | ||
@@ -56,3 +58,3 @@ throw new Error('Neither a fieldName or matchConditions were provided. Please choose to pass either one in order to be able to detect which fields to rewrite.'); | ||
*/ | ||
Rewriter.prototype.rewriteResponse = function (response, key, index) { | ||
Rewriter.prototype.rewriteResponse = function (response, key, index, nodeMatchAndParents) { | ||
return response; | ||
@@ -59,0 +61,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { ASTNode } from 'graphql'; | ||
import Rewriter, { Variables } from './rewriters/Rewriter'; | ||
@@ -6,2 +7,3 @@ interface RewriterMatch { | ||
allPaths: ReadonlyArray<ReadonlyArray<string>>; | ||
nodeMatchAndParents?: ASTNode[]; | ||
} | ||
@@ -8,0 +10,0 @@ /** |
@@ -7,3 +7,3 @@ import { ASTNode } from 'graphql'; | ||
rewriteQueryFn?: (nodeAndVarDefs: NodeAndVarDefs, variables: Variables) => NodeAndVarDefs; | ||
rewriteResponseFn?: (response: any, key: string, index?: number) => NodeAndVarDefs; | ||
rewriteResponseFn?: (response: any, key: string, index?: number, nodeMatchAndParents?: ASTNode[]) => NodeAndVarDefs; | ||
} | ||
@@ -17,8 +17,8 @@ /** | ||
protected rewriteQueryFn: (nodeAndVarDefs: NodeAndVarDefs, variables: Variables) => NodeAndVarDefs; | ||
protected rewriteResponseFn: (response: any, key: string, index?: number) => NodeAndVarDefs; | ||
protected rewriteResponseFn: (response: any, key: string, index?: number, nodeMatchAndParents?: ASTNode[]) => NodeAndVarDefs; | ||
constructor(options: CustomRewriterOpts); | ||
matches(nodeAndVarDefs: NodeAndVarDefs, parents: ReadonlyArray<ASTNode>): boolean; | ||
rewriteQuery(nodeAndVarDefs: NodeAndVarDefs, variables: Variables): NodeAndVarDefs; | ||
rewriteResponse(response: any, key: string, index?: number): NodeAndVarDefs; | ||
rewriteResponse(response: any, key: string, index?: number, nodeMatchAndParents?: ASTNode[]): NodeAndVarDefs; | ||
} | ||
export default CustomRewriter; |
@@ -13,2 +13,3 @@ import { ASTNode } from 'graphql'; | ||
matchAnyPath?: boolean; | ||
saveNode?: boolean; | ||
} | ||
@@ -21,10 +22,11 @@ /** | ||
matchAnyPath: boolean; | ||
saveNode: boolean; | ||
protected rootTypes: RootType[]; | ||
protected fieldName?: string; | ||
protected matchConditions?: matchCondition[]; | ||
constructor({ fieldName, rootTypes, matchConditions, matchAnyPath }: RewriterOpts); | ||
constructor({ fieldName, rootTypes, matchConditions, matchAnyPath, saveNode }: RewriterOpts); | ||
matches(nodeAndVarDefs: NodeAndVarDefs, parents: ReadonlyArray<ASTNode>): boolean; | ||
rewriteQuery(nodeAndVarDefs: NodeAndVarDefs, variables: Variables): NodeAndVarDefs; | ||
rewriteVariables(nodeAndVarDefs: NodeAndVarDefs, variables: Variables): Variables; | ||
rewriteResponse(response: any, key: string, index?: number): any; | ||
rewriteResponse(response: any, key: string, index?: number, nodeMatchAndParents?: ASTNode[]): any; | ||
protected extractReponseElement(response: any, key: string, index?: number): any; | ||
@@ -31,0 +33,0 @@ protected rewriteResponseElement(response: any, newElement: any, key: string, index?: number): any; |
{ | ||
"name": "graphql-query-rewriter-rc", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
388945
3840