Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generics for Arguments and Context in SchemaDirectiveVisitor #1325

Merged
merged 1 commit into from Apr 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/utils/SchemaDirectiveVisitor.ts
Expand Up @@ -58,7 +58,10 @@ const hasOwn = Object.prototype.hasOwnProperty;
// parameter types, and more details about the properties exposed by instances
// of the SchemaDirectiveVisitor class.

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

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

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

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