Skip to content

Commit 4c807f6

Browse files
committed
Generics for Arguments and Context in SchemaDirectiveVisitor (#1325)
Closes #1298
1 parent 99cdbab commit 4c807f6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/utils/SchemaDirectiveVisitor.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ const hasOwn = Object.prototype.hasOwnProperty;
5858
// parameter types, and more details about the properties exposed by instances
5959
// of the SchemaDirectiveVisitor class.
6060

61-
export class SchemaDirectiveVisitor extends SchemaVisitor {
61+
export class SchemaDirectiveVisitor<
62+
TArgs = { [name: string]: any },
63+
TContext = { [key: string]: any }
64+
> extends SchemaVisitor {
6265
// The name of the directive this visitor is allowed to visit (that is, the
6366
// identifier that appears after the @ character in the schema). Note that
6467
// this property is per-instance rather than static because subclasses of
@@ -71,15 +74,15 @@ export class SchemaDirectiveVisitor extends SchemaVisitor {
7174
// A map from parameter names to argument values, as obtained from a
7275
// specific occurrence of a @directive(arg1: value1, arg2: value2, ...) in
7376
// the schema. Visitor methods may refer to this object via this.args.
74-
public args: { [name: string]: any };
77+
public args: TArgs;
7578

7679
// A reference to the type object that this visitor was created to visit.
7780
public visitedType: VisitableSchemaType;
7881

7982
// A shared object that will be available to all visitor instances via
8083
// this.context. Callers of visitSchemaDirectives can provide their own
8184
// object, or just use the default empty object.
82-
public context: { [key: string]: any };
85+
public context: TContext;
8386

8487
// Override this method to return a custom GraphQLDirective (or modify one
8588
// already present in the schema) to enforce argument types, provide default
@@ -275,10 +278,10 @@ export class SchemaDirectiveVisitor extends SchemaVisitor {
275278
// subclasses (not instances) to visitSchemaDirectives.
276279
protected constructor(config: {
277280
name: string;
278-
args: { [name: string]: any };
281+
args: TArgs;
279282
visitedType: VisitableSchemaType;
280283
schema: GraphQLSchema;
281-
context: { [key: string]: any };
284+
context: TContext;
282285
}) {
283286
super();
284287
this.name = config.name;

0 commit comments

Comments
 (0)