Skip to content

Commit

Permalink
Rename directiveVisitors option to just directives.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Mar 14, 2018
1 parent 69e1ede commit 6776473
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface IExecutableSchemaDefinition<TContext = any> {
allowUndefinedInResolve?: boolean;
resolverValidationOptions?: IResolverValidationOptions;
directiveResolvers?: IDirectiveResolvers<any, TContext>;
directiveVisitors?: { [name: string]: typeof SchemaDirectiveVisitor };
directives?: { [name: string]: typeof SchemaDirectiveVisitor };
parseOptions?: GraphQLParseOptions;
}

Expand Down
12 changes: 6 additions & 6 deletions src/schemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function makeExecutableSchema<TContext = any>({
allowUndefinedInResolve = true,
resolverValidationOptions = {},
directiveResolvers = null,
directiveVisitors = null,
directives = null,
parseOptions = {},
}: IExecutableSchemaDefinition<TContext>) {
const jsSchema = _generateSchema(
Expand Down Expand Up @@ -142,10 +142,10 @@ function makeExecutableSchema<TContext = any>({
attachDirectiveResolvers(jsSchema, directiveResolvers);
}

if (directiveVisitors) {
if (directives) {
SchemaDirectiveVisitor.visitSchemaDirectives(
jsSchema,
directiveVisitors,
directives,
);
}

Expand Down Expand Up @@ -692,10 +692,10 @@ function attachDirectiveResolvers(
);
}

const directiveVisitors = Object.create(null);
const directives = Object.create(null);

Object.keys(directiveResolvers).forEach(directiveName => {
directiveVisitors[directiveName] = class extends SchemaDirectiveVisitor {
directives[directiveName] = class extends SchemaDirectiveVisitor {
public visitFieldDefinition(field: GraphQLField<any, any>) {
const resolver = directiveResolvers[directiveName];
const originalResolver = field.resolve || defaultFieldResolver;
Expand All @@ -716,7 +716,7 @@ function attachDirectiveResolvers(

SchemaDirectiveVisitor.visitSchemaDirectives(
schema,
directiveVisitors,
directives,
);
}

Expand Down
16 changes: 8 additions & 8 deletions src/test/testDirectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe('@directives', () => {
let argumentCount = 0;
let fieldCount = 0;

const directiveVisitors = {
const directives = {
directive: class extends SchemaDirectiveVisitor {
public visitEnumValue(value: GraphQLEnumValue) {
++enumValueCount;
Expand Down Expand Up @@ -444,7 +444,7 @@ describe('@directives', () => {

makeExecutableSchema({
typeDefs: schemaText,
directiveVisitors,
directives,
});

assert.strictEqual(enumValueCount, 2);
Expand Down Expand Up @@ -537,7 +537,7 @@ describe('@directives', () => {
type Query {
hello: String @upper
}`,
directiveVisitors: {
directives: {
upper: class extends SchemaDirectiveVisitor {
public visitFieldDefinition(field: GraphQLField<any, any>) {
const { resolve = defaultFieldResolver } = field;
Expand Down Expand Up @@ -582,7 +582,7 @@ describe('@directives', () => {
today: Date @date(format: "mmmm d, yyyy")
}`,

directiveVisitors: {
directives: {
date: class extends SchemaDirectiveVisitor {
public visitFieldDefinition(field: GraphQLField<any, any>) {
const { resolve = defaultFieldResolver } = field;
Expand Down Expand Up @@ -640,7 +640,7 @@ describe('@directives', () => {
greeting: String @intl
}`,

directiveVisitors: {
directives: {
intl: class extends SchemaDirectiveVisitor {
public visitFieldDefinition(field: GraphQLField<any, any>, details: {
objectType: GraphQLObjectType,
Expand Down Expand Up @@ -720,7 +720,7 @@ describe('@directives', () => {
users: [User]
}`,

directiveVisitors: {
directives: {
auth: class extends SchemaDirectiveVisitor {
public visitObject(type: GraphQLObjectType) {
this.ensureFieldsWrapped(type);
Expand Down Expand Up @@ -870,7 +870,7 @@ describe('@directives', () => {
title: String! @length(max: 10)
}`,

directiveVisitors: {
directives: {
length: class extends SchemaDirectiveVisitor {
public visitInputFieldDefinition(field: GraphQLInputField) {
this.wrapType(field);
Expand Down Expand Up @@ -956,7 +956,7 @@ describe('@directives', () => {
address: String
}`,

directiveVisitors: {
directives: {
uniqueID: class extends SchemaDirectiveVisitor {
public visitObject(type: GraphQLObjectType) {
const { name, from } = this.args;
Expand Down

0 comments on commit 6776473

Please sign in to comment.