graphql-query-rewriter
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -1,2 +0,2 @@ | ||
import { parse, print, parseType } from 'graphql'; | ||
import { parse, print, isValueNode, Kind, parseType } from 'graphql'; | ||
@@ -313,3 +313,3 @@ /*! ***************************************************************************** | ||
rewrittenVariables = rewriter.rewriteVariables(rewrittenNodeAndVars, rewrittenVariables); | ||
rewrittenNodeAndVars = rewriter.rewriteQuery(rewrittenNodeAndVars); | ||
rewrittenNodeAndVars = rewriter.rewriteQuery(rewrittenNodeAndVars, rewrittenVariables); | ||
var simplePath = extractPath(parents.concat([rewrittenNodeAndVars.node])); | ||
@@ -366,2 +366,5 @@ var paths = [simplePath]; | ||
this.matchConditions = matchConditions; | ||
if (!this.fieldName && !this.matchConditions) { | ||
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.'); | ||
} | ||
if (rootTypes) | ||
@@ -372,4 +375,9 @@ this.rootTypes = rootTypes; | ||
var node = nodeAndVarDefs.node; | ||
if (node.kind !== 'Field' || node.name.value !== this.fieldName) | ||
// If no fieldName is provided, check for defined matchConditions. | ||
// This avoids having to define one rewriter for many fields individually. | ||
// Alternatively, regex matching for fieldName could be implemented. | ||
if (node.kind !== 'Field' || | ||
(this.fieldName ? node.name.value !== this.fieldName : !this.matchConditions)) { | ||
return false; | ||
} | ||
var root = parents[0]; | ||
@@ -389,3 +397,3 @@ if (root.kind === 'OperationDefinition' && | ||
}; | ||
Rewriter.prototype.rewriteQuery = function (nodeAndVarDefs) { | ||
Rewriter.prototype.rewriteQuery = function (nodeAndVarDefs, variables) { | ||
return nodeAndVarDefs; | ||
@@ -544,2 +552,3 @@ }; | ||
_this.coerceVariable = options.coerceVariable || identifyFunc; | ||
_this.coerceArgumentValue = options.coerceArgumentValue || identifyFunc; | ||
return _this; | ||
@@ -556,36 +565,78 @@ } | ||
return false; | ||
if (node.name.value !== this.fieldName || !node.arguments) | ||
// does this field contain arguments? | ||
if (!node.arguments) | ||
return false; | ||
// is there an argument with the correct name and type in a variable? | ||
var matchingArgument = node.arguments.find(function (arg) { return arg.name.value === _this.argName; }); | ||
if (!matchingArgument || matchingArgument.value.kind !== 'Variable') | ||
if (!matchingArgument) | ||
return false; | ||
var varRef = matchingArgument.value.name.value; | ||
// does the referenced variable have the correct type? | ||
for (var _i = 0, variableDefinitions_1 = variableDefinitions; _i < variableDefinitions_1.length; _i++) { | ||
var varDefinition = variableDefinitions_1[_i]; | ||
if (varDefinition.variable.name.value === varRef) { | ||
return nodesMatch(this.oldTypeNode, varDefinition.type); | ||
// argument value is stored in a variable | ||
if (matchingArgument.value.kind === 'Variable') { | ||
var varRef = matchingArgument.value.name.value; | ||
// does the referenced variable have the correct type? | ||
for (var _i = 0, variableDefinitions_1 = variableDefinitions; _i < variableDefinitions_1.length; _i++) { | ||
var varDefinition = variableDefinitions_1[_i]; | ||
if (varDefinition.variable.name.value === varRef) { | ||
return nodesMatch(this.oldTypeNode, varDefinition.type); | ||
} | ||
} | ||
} | ||
// argument value comes in query doc. | ||
else { | ||
var argValueNode = matchingArgument.value; | ||
return isValueNode(argValueNode); | ||
// Would be ideal to do a nodesMatch in here, however argument value nodes | ||
// have different format for their values than when passed as variables. | ||
// For instance, are parsed with Kinds as "graphql.Kind" (e.g., INT="IntValue") and not "graphql.TokenKinds" (e.g., INT="Int") | ||
// So they might not match correctly. Also they dont contain additional parsed syntax | ||
// as the non-optional symbol "!". So just return true if the argument.value is a ValueNode. | ||
// | ||
// return nodesMatch(this.oldTypeNode, parseType(argRef.kind)); | ||
} | ||
return false; | ||
}; | ||
FieldArgTypeRewriter.prototype.rewriteQuery = function (_a) { | ||
FieldArgTypeRewriter.prototype.rewriteQuery = function (_a, variables) { | ||
var _this = this; | ||
var node = _a.node, variableDefinitions = _a.variableDefinitions; | ||
var astNode = _a.node, variableDefinitions = _a.variableDefinitions; | ||
var node = astNode; | ||
var varRefName = this.extractMatchingVarRefName(node); | ||
var newVarDefs = variableDefinitions.map(function (varDef) { | ||
if (varDef.variable.name.value !== varRefName) | ||
return varDef; | ||
return __assign({}, varDef, { type: _this.newTypeNode }); | ||
}); | ||
return { node: node, variableDefinitions: newVarDefs }; | ||
// If argument value is stored in a variable | ||
if (varRefName) { | ||
var newVarDefs = variableDefinitions.map(function (varDef) { | ||
if (varDef.variable.name.value !== varRefName) | ||
return varDef; | ||
return __assign({}, varDef, { type: _this.newTypeNode }); | ||
}); | ||
return { node: node, variableDefinitions: newVarDefs }; | ||
} | ||
// If argument value is not stored in a variable but in the query node. | ||
var matchingArgument = (node.arguments || []).find(function (arg) { return arg.name.value === _this.argName; }); | ||
if (node.arguments && matchingArgument) { | ||
var args = node.arguments.slice(); | ||
var newValue = this.coerceArgumentValue(matchingArgument.value, { variables: variables, args: args }); | ||
/** | ||
* TODO: If somewhow we can get the schema here, we could make the coerceArgumentValue | ||
* even easier, as we would be able to construct the ast node for the argument value. | ||
* as of now, the user has to take care of correctly constructing the argument value ast node herself. | ||
* | ||
* const schema = makeExecutableSchema({typeDefs}) | ||
* const myCustomType = schema.getType("MY_CUSTOM_TYPE_NAME") | ||
* const newArgValue = astFromValue(newValue, myCustomType) | ||
* Object.assign(matchingArgument, { value: newArgValue }) | ||
*/ | ||
if (newValue) | ||
Object.assign(matchingArgument, { value: newValue }); | ||
} | ||
return { node: node, variableDefinitions: variableDefinitions }; | ||
}; | ||
FieldArgTypeRewriter.prototype.rewriteVariables = function (_a, variables) { | ||
var node = _a.node; | ||
var astNode = _a.node; | ||
var _b; | ||
var node = astNode; | ||
if (!variables) | ||
return variables; | ||
var varRefName = this.extractMatchingVarRefName(node); | ||
return __assign({}, variables, (_b = {}, _b[varRefName] = this.coerceVariable(variables[varRefName]), _b)); | ||
var args = (node.arguments ? node.arguments : []).slice(); | ||
return __assign({}, variables, (varRefName | ||
? (_b = {}, _b[varRefName] = this.coerceVariable(variables[varRefName], { variables: variables, args: args }), _b) : {})); | ||
}; | ||
@@ -595,3 +646,4 @@ FieldArgTypeRewriter.prototype.extractMatchingVarRefName = function (node) { | ||
var matchingArgument = (node.arguments || []).find(function (arg) { return arg.name.value === _this.argName; }); | ||
return matchingArgument.value.name.value; | ||
var variableNode = matchingArgument.value; | ||
return variableNode.kind === Kind.VARIABLE && variableNode.name.value; | ||
}; | ||
@@ -598,0 +650,0 @@ return FieldArgTypeRewriter; |
@@ -317,3 +317,3 @@ (function (global, factory) { | ||
rewrittenVariables = rewriter.rewriteVariables(rewrittenNodeAndVars, rewrittenVariables); | ||
rewrittenNodeAndVars = rewriter.rewriteQuery(rewrittenNodeAndVars); | ||
rewrittenNodeAndVars = rewriter.rewriteQuery(rewrittenNodeAndVars, rewrittenVariables); | ||
var simplePath = extractPath(parents.concat([rewrittenNodeAndVars.node])); | ||
@@ -370,2 +370,5 @@ var paths = [simplePath]; | ||
this.matchConditions = matchConditions; | ||
if (!this.fieldName && !this.matchConditions) { | ||
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.'); | ||
} | ||
if (rootTypes) | ||
@@ -376,4 +379,9 @@ this.rootTypes = rootTypes; | ||
var node = nodeAndVarDefs.node; | ||
if (node.kind !== 'Field' || node.name.value !== this.fieldName) | ||
// If no fieldName is provided, check for defined matchConditions. | ||
// This avoids having to define one rewriter for many fields individually. | ||
// Alternatively, regex matching for fieldName could be implemented. | ||
if (node.kind !== 'Field' || | ||
(this.fieldName ? node.name.value !== this.fieldName : !this.matchConditions)) { | ||
return false; | ||
} | ||
var root = parents[0]; | ||
@@ -393,3 +401,3 @@ if (root.kind === 'OperationDefinition' && | ||
}; | ||
Rewriter.prototype.rewriteQuery = function (nodeAndVarDefs) { | ||
Rewriter.prototype.rewriteQuery = function (nodeAndVarDefs, variables) { | ||
return nodeAndVarDefs; | ||
@@ -548,2 +556,3 @@ }; | ||
_this.coerceVariable = options.coerceVariable || identifyFunc; | ||
_this.coerceArgumentValue = options.coerceArgumentValue || identifyFunc; | ||
return _this; | ||
@@ -560,36 +569,78 @@ } | ||
return false; | ||
if (node.name.value !== this.fieldName || !node.arguments) | ||
// does this field contain arguments? | ||
if (!node.arguments) | ||
return false; | ||
// is there an argument with the correct name and type in a variable? | ||
var matchingArgument = node.arguments.find(function (arg) { return arg.name.value === _this.argName; }); | ||
if (!matchingArgument || matchingArgument.value.kind !== 'Variable') | ||
if (!matchingArgument) | ||
return false; | ||
var varRef = matchingArgument.value.name.value; | ||
// does the referenced variable have the correct type? | ||
for (var _i = 0, variableDefinitions_1 = variableDefinitions; _i < variableDefinitions_1.length; _i++) { | ||
var varDefinition = variableDefinitions_1[_i]; | ||
if (varDefinition.variable.name.value === varRef) { | ||
return nodesMatch(this.oldTypeNode, varDefinition.type); | ||
// argument value is stored in a variable | ||
if (matchingArgument.value.kind === 'Variable') { | ||
var varRef = matchingArgument.value.name.value; | ||
// does the referenced variable have the correct type? | ||
for (var _i = 0, variableDefinitions_1 = variableDefinitions; _i < variableDefinitions_1.length; _i++) { | ||
var varDefinition = variableDefinitions_1[_i]; | ||
if (varDefinition.variable.name.value === varRef) { | ||
return nodesMatch(this.oldTypeNode, varDefinition.type); | ||
} | ||
} | ||
} | ||
// argument value comes in query doc. | ||
else { | ||
var argValueNode = matchingArgument.value; | ||
return graphql.isValueNode(argValueNode); | ||
// Would be ideal to do a nodesMatch in here, however argument value nodes | ||
// have different format for their values than when passed as variables. | ||
// For instance, are parsed with Kinds as "graphql.Kind" (e.g., INT="IntValue") and not "graphql.TokenKinds" (e.g., INT="Int") | ||
// So they might not match correctly. Also they dont contain additional parsed syntax | ||
// as the non-optional symbol "!". So just return true if the argument.value is a ValueNode. | ||
// | ||
// return nodesMatch(this.oldTypeNode, parseType(argRef.kind)); | ||
} | ||
return false; | ||
}; | ||
FieldArgTypeRewriter.prototype.rewriteQuery = function (_a) { | ||
FieldArgTypeRewriter.prototype.rewriteQuery = function (_a, variables) { | ||
var _this = this; | ||
var node = _a.node, variableDefinitions = _a.variableDefinitions; | ||
var astNode = _a.node, variableDefinitions = _a.variableDefinitions; | ||
var node = astNode; | ||
var varRefName = this.extractMatchingVarRefName(node); | ||
var newVarDefs = variableDefinitions.map(function (varDef) { | ||
if (varDef.variable.name.value !== varRefName) | ||
return varDef; | ||
return __assign({}, varDef, { type: _this.newTypeNode }); | ||
}); | ||
return { node: node, variableDefinitions: newVarDefs }; | ||
// If argument value is stored in a variable | ||
if (varRefName) { | ||
var newVarDefs = variableDefinitions.map(function (varDef) { | ||
if (varDef.variable.name.value !== varRefName) | ||
return varDef; | ||
return __assign({}, varDef, { type: _this.newTypeNode }); | ||
}); | ||
return { node: node, variableDefinitions: newVarDefs }; | ||
} | ||
// If argument value is not stored in a variable but in the query node. | ||
var matchingArgument = (node.arguments || []).find(function (arg) { return arg.name.value === _this.argName; }); | ||
if (node.arguments && matchingArgument) { | ||
var args = node.arguments.slice(); | ||
var newValue = this.coerceArgumentValue(matchingArgument.value, { variables: variables, args: args }); | ||
/** | ||
* TODO: If somewhow we can get the schema here, we could make the coerceArgumentValue | ||
* even easier, as we would be able to construct the ast node for the argument value. | ||
* as of now, the user has to take care of correctly constructing the argument value ast node herself. | ||
* | ||
* const schema = makeExecutableSchema({typeDefs}) | ||
* const myCustomType = schema.getType("MY_CUSTOM_TYPE_NAME") | ||
* const newArgValue = astFromValue(newValue, myCustomType) | ||
* Object.assign(matchingArgument, { value: newArgValue }) | ||
*/ | ||
if (newValue) | ||
Object.assign(matchingArgument, { value: newValue }); | ||
} | ||
return { node: node, variableDefinitions: variableDefinitions }; | ||
}; | ||
FieldArgTypeRewriter.prototype.rewriteVariables = function (_a, variables) { | ||
var node = _a.node; | ||
var astNode = _a.node; | ||
var _b; | ||
var node = astNode; | ||
if (!variables) | ||
return variables; | ||
var varRefName = this.extractMatchingVarRefName(node); | ||
return __assign({}, variables, (_b = {}, _b[varRefName] = this.coerceVariable(variables[varRefName]), _b)); | ||
var args = (node.arguments ? node.arguments : []).slice(); | ||
return __assign({}, variables, (varRefName | ||
? (_b = {}, _b[varRefName] = this.coerceVariable(variables[varRefName], { variables: variables, args: args }), _b) : {})); | ||
}; | ||
@@ -599,3 +650,4 @@ FieldArgTypeRewriter.prototype.extractMatchingVarRefName = function (node) { | ||
var matchingArgument = (node.arguments || []).find(function (arg) { return arg.name.value === _this.argName; }); | ||
return matchingArgument.value.name.value; | ||
var variableNode = matchingArgument.value; | ||
return variableNode.kind === graphql.Kind.VARIABLE && variableNode.name.value; | ||
}; | ||
@@ -602,0 +654,0 @@ return FieldArgTypeRewriter; |
@@ -35,3 +35,3 @@ "use strict"; | ||
rewrittenVariables = rewriter.rewriteVariables(rewrittenNodeAndVars, rewrittenVariables); | ||
rewrittenNodeAndVars = rewriter.rewriteQuery(rewrittenNodeAndVars); | ||
rewrittenNodeAndVars = rewriter.rewriteQuery(rewrittenNodeAndVars, rewrittenVariables); | ||
var simplePath = ast_1.extractPath(parents.concat([rewrittenNodeAndVars.node])); | ||
@@ -38,0 +38,0 @@ var paths = [simplePath]; |
@@ -43,2 +43,3 @@ "use strict"; | ||
_this.coerceVariable = options.coerceVariable || utils_1.identifyFunc; | ||
_this.coerceArgumentValue = options.coerceArgumentValue || utils_1.identifyFunc; | ||
return _this; | ||
@@ -55,36 +56,78 @@ } | ||
return false; | ||
if (node.name.value !== this.fieldName || !node.arguments) | ||
// does this field contain arguments? | ||
if (!node.arguments) | ||
return false; | ||
// is there an argument with the correct name and type in a variable? | ||
var matchingArgument = node.arguments.find(function (arg) { return arg.name.value === _this.argName; }); | ||
if (!matchingArgument || matchingArgument.value.kind !== 'Variable') | ||
if (!matchingArgument) | ||
return false; | ||
var varRef = matchingArgument.value.name.value; | ||
// does the referenced variable have the correct type? | ||
for (var _i = 0, variableDefinitions_1 = variableDefinitions; _i < variableDefinitions_1.length; _i++) { | ||
var varDefinition = variableDefinitions_1[_i]; | ||
if (varDefinition.variable.name.value === varRef) { | ||
return ast_1.nodesMatch(this.oldTypeNode, varDefinition.type); | ||
// argument value is stored in a variable | ||
if (matchingArgument.value.kind === 'Variable') { | ||
var varRef = matchingArgument.value.name.value; | ||
// does the referenced variable have the correct type? | ||
for (var _i = 0, variableDefinitions_1 = variableDefinitions; _i < variableDefinitions_1.length; _i++) { | ||
var varDefinition = variableDefinitions_1[_i]; | ||
if (varDefinition.variable.name.value === varRef) { | ||
return ast_1.nodesMatch(this.oldTypeNode, varDefinition.type); | ||
} | ||
} | ||
} | ||
// argument value comes in query doc. | ||
else { | ||
var argValueNode = matchingArgument.value; | ||
return graphql_1.isValueNode(argValueNode); | ||
// Would be ideal to do a nodesMatch in here, however argument value nodes | ||
// have different format for their values than when passed as variables. | ||
// For instance, are parsed with Kinds as "graphql.Kind" (e.g., INT="IntValue") and not "graphql.TokenKinds" (e.g., INT="Int") | ||
// So they might not match correctly. Also they dont contain additional parsed syntax | ||
// as the non-optional symbol "!". So just return true if the argument.value is a ValueNode. | ||
// | ||
// return nodesMatch(this.oldTypeNode, parseType(argRef.kind)); | ||
} | ||
return false; | ||
}; | ||
FieldArgTypeRewriter.prototype.rewriteQuery = function (_a) { | ||
FieldArgTypeRewriter.prototype.rewriteQuery = function (_a, variables) { | ||
var _this = this; | ||
var node = _a.node, variableDefinitions = _a.variableDefinitions; | ||
var astNode = _a.node, variableDefinitions = _a.variableDefinitions; | ||
var node = astNode; | ||
var varRefName = this.extractMatchingVarRefName(node); | ||
var newVarDefs = variableDefinitions.map(function (varDef) { | ||
if (varDef.variable.name.value !== varRefName) | ||
return varDef; | ||
return __assign({}, varDef, { type: _this.newTypeNode }); | ||
}); | ||
return { node: node, variableDefinitions: newVarDefs }; | ||
// If argument value is stored in a variable | ||
if (varRefName) { | ||
var newVarDefs = variableDefinitions.map(function (varDef) { | ||
if (varDef.variable.name.value !== varRefName) | ||
return varDef; | ||
return __assign({}, varDef, { type: _this.newTypeNode }); | ||
}); | ||
return { node: node, variableDefinitions: newVarDefs }; | ||
} | ||
// If argument value is not stored in a variable but in the query node. | ||
var matchingArgument = (node.arguments || []).find(function (arg) { return arg.name.value === _this.argName; }); | ||
if (node.arguments && matchingArgument) { | ||
var args = node.arguments.slice(); | ||
var newValue = this.coerceArgumentValue(matchingArgument.value, { variables: variables, args: args }); | ||
/** | ||
* TODO: If somewhow we can get the schema here, we could make the coerceArgumentValue | ||
* even easier, as we would be able to construct the ast node for the argument value. | ||
* as of now, the user has to take care of correctly constructing the argument value ast node herself. | ||
* | ||
* const schema = makeExecutableSchema({typeDefs}) | ||
* const myCustomType = schema.getType("MY_CUSTOM_TYPE_NAME") | ||
* const newArgValue = astFromValue(newValue, myCustomType) | ||
* Object.assign(matchingArgument, { value: newArgValue }) | ||
*/ | ||
if (newValue) | ||
Object.assign(matchingArgument, { value: newValue }); | ||
} | ||
return { node: node, variableDefinitions: variableDefinitions }; | ||
}; | ||
FieldArgTypeRewriter.prototype.rewriteVariables = function (_a, variables) { | ||
var node = _a.node; | ||
var astNode = _a.node; | ||
var _b; | ||
var node = astNode; | ||
if (!variables) | ||
return variables; | ||
var varRefName = this.extractMatchingVarRefName(node); | ||
return __assign({}, variables, (_b = {}, _b[varRefName] = this.coerceVariable(variables[varRefName]), _b)); | ||
var args = (node.arguments ? node.arguments : []).slice(); | ||
return __assign({}, variables, (varRefName | ||
? (_b = {}, _b[varRefName] = this.coerceVariable(variables[varRefName], { variables: variables, args: args }), _b) : {})); | ||
}; | ||
@@ -94,3 +137,4 @@ FieldArgTypeRewriter.prototype.extractMatchingVarRefName = function (node) { | ||
var matchingArgument = (node.arguments || []).find(function (arg) { return arg.name.value === _this.argName; }); | ||
return matchingArgument.value.name.value; | ||
var variableNode = matchingArgument.value; | ||
return variableNode.kind === graphql_1.Kind.VARIABLE && variableNode.name.value; | ||
}; | ||
@@ -97,0 +141,0 @@ return FieldArgTypeRewriter; |
@@ -13,2 +13,5 @@ "use strict"; | ||
this.matchConditions = matchConditions; | ||
if (!this.fieldName && !this.matchConditions) { | ||
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.'); | ||
} | ||
if (rootTypes) | ||
@@ -19,4 +22,9 @@ this.rootTypes = rootTypes; | ||
var node = nodeAndVarDefs.node; | ||
if (node.kind !== 'Field' || node.name.value !== this.fieldName) | ||
// If no fieldName is provided, check for defined matchConditions. | ||
// This avoids having to define one rewriter for many fields individually. | ||
// Alternatively, regex matching for fieldName could be implemented. | ||
if (node.kind !== 'Field' || | ||
(this.fieldName ? node.name.value !== this.fieldName : !this.matchConditions)) { | ||
return false; | ||
} | ||
var root = parents[0]; | ||
@@ -36,3 +44,3 @@ if (root.kind === 'OperationDefinition' && | ||
}; | ||
Rewriter.prototype.rewriteQuery = function (nodeAndVarDefs) { | ||
Rewriter.prototype.rewriteQuery = function (nodeAndVarDefs, variables) { | ||
return nodeAndVarDefs; | ||
@@ -39,0 +47,0 @@ }; |
@@ -1,2 +0,3 @@ | ||
import { ASTNode, TypeNode } from 'graphql'; | ||
import { ArgumentNode, ASTNode, FieldNode, TypeNode, ValueNode } from 'graphql'; | ||
import Maybe from 'graphql/tsutils/Maybe'; | ||
import { NodeAndVarDefs } from '../ast'; | ||
@@ -8,3 +9,16 @@ import Rewriter, { RewriterOpts, Variables } from './Rewriter'; | ||
newType: string; | ||
coerceVariable?: (variable: any) => any; | ||
coerceVariable?: (variable: any, context: { | ||
variables: Variables; | ||
args: ArgumentNode[]; | ||
}) => any; | ||
/** | ||
* EXPERIMENTAL: | ||
* This allows to coerce value of argument when their value is not stored in a variable | ||
* but comes in the query node itself. | ||
* NOTE: At the moment, the user has to return the ast value node herself. | ||
*/ | ||
coerceArgumentValue?: (variable: any, context: { | ||
variables: Variables; | ||
args: ArgumentNode[]; | ||
}) => Maybe<ValueNode>; | ||
} | ||
@@ -19,10 +33,17 @@ /** | ||
protected newTypeNode: TypeNode; | ||
protected coerceVariable: (variable: any) => any; | ||
protected coerceVariable: (variable: any, context: { | ||
variables: Variables; | ||
args: ArgumentNode[]; | ||
}) => any; | ||
protected coerceArgumentValue: (variable: any, context: { | ||
variables: Variables; | ||
args: ArgumentNode[]; | ||
}) => Maybe<ValueNode>; | ||
constructor(options: FieldArgTypeRewriterOpts); | ||
matches(nodeAndVars: NodeAndVarDefs, parents: ASTNode[]): boolean; | ||
rewriteQuery({ node, variableDefinitions }: NodeAndVarDefs): { | ||
node: ASTNode; | ||
variableDefinitions: import("graphql").VariableDefinitionNode[]; | ||
rewriteQuery({ node: astNode, variableDefinitions }: NodeAndVarDefs, variables: Variables): { | ||
node: FieldNode; | ||
variableDefinitions: ReadonlyArray<import("graphql").VariableDefinitionNode>; | ||
}; | ||
rewriteVariables({ node }: NodeAndVarDefs, variables: Variables): { | ||
rewriteVariables({ node: astNode }: NodeAndVarDefs, variables: Variables): { | ||
[x: string]: any; | ||
@@ -29,0 +50,0 @@ } | undefined; |
@@ -9,3 +9,3 @@ import { ASTNode } from 'graphql'; | ||
export interface RewriterOpts { | ||
fieldName: string; | ||
fieldName?: string; | ||
rootTypes?: RootType[]; | ||
@@ -19,8 +19,8 @@ matchConditions?: matchCondition[]; | ||
declare abstract class Rewriter { | ||
protected fieldName: string; | ||
protected rootTypes: RootType[]; | ||
protected fieldName?: string; | ||
protected matchConditions?: matchCondition[]; | ||
constructor({ fieldName, rootTypes, matchConditions }: RewriterOpts); | ||
matches(nodeAndVarDefs: NodeAndVarDefs, parents: ReadonlyArray<ASTNode>): boolean; | ||
rewriteQuery(nodeAndVarDefs: NodeAndVarDefs): NodeAndVarDefs; | ||
rewriteQuery(nodeAndVarDefs: NodeAndVarDefs, variables: Variables): NodeAndVarDefs; | ||
rewriteVariables(nodeAndVarDefs: NodeAndVarDefs, variables: Variables): Variables; | ||
@@ -27,0 +27,0 @@ rewriteResponse(response: any, key: string, index?: number): any; |
{ | ||
"name": "graphql-query-rewriter", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
# GraphQL Query Rewriter | ||
[![CircleCI](https://circleci.com/gh/ef-eng/graphql-query-rewriter/tree/master.svg?style=shield)](https://circleci.com/gh/ef-eng/graphql-query-rewriter/tree/master) | ||
[![CircleCI](https://circleci.com/gh/graphql-query-rewriter/core/tree/master.svg?style=shield)](https://circleci.com/gh/ef-eng/graphql-query-rewriter/tree/master) | ||
[![Coverage Status](https://coveralls.io/repos/github/chanind/graphql-query-rewriter/badge.svg?branch=master)](https://coveralls.io/github/ef-eng/graphql-query-rewriter?branch=master) | ||
@@ -532,2 +532,6 @@ [![npm](https://badgen.net/npm/v/graphql-query-rewriter)](https://www.npmjs.com/package/graphql-query-rewriter) | ||
## Sponsors | ||
[<img src="https://assets.hello.ef.com/icons/logo-04022021.png" height="50" alt="EF Hello" />](https://www.hello.ef.com/) | ||
## Contributing | ||
@@ -534,0 +538,0 @@ |
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
320836
3114
550