From f437b3251885de339db807b11534e240477b5add Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 1 Jun 2018 20:21:06 +0300 Subject: [PATCH] __allowedLegacyNames: Use empty array instead of undefined properties --- src/type/schema.js | 4 ++-- src/type/validate.js | 5 +---- src/utilities/extendSchema.js | 9 +++------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/type/schema.js b/src/type/schema.js index d7f1fa1c93..8817825e41 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -88,7 +88,7 @@ export class GraphQLSchema { // Used as a cache for validateSchema(). __validationErrors: ?$ReadOnlyArray; // Referenced by validateSchema(). - __allowedLegacyNames: ?$ReadOnlyArray; + __allowedLegacyNames: $ReadOnlyArray; constructor(config: GraphQLSchemaConfig): void { // If this schema was built from a source known to be valid, then it may be @@ -118,7 +118,7 @@ export class GraphQLSchema { ); } - this.__allowedLegacyNames = config.allowedLegacyNames; + this.__allowedLegacyNames = config.allowedLegacyNames || []; this._queryType = config.query; this._mutationType = config.mutation; this._subscriptionType = config.subscription; diff --git a/src/type/validate.js b/src/type/validate.js index de13bf1adb..a5cc5591f8 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -221,10 +221,7 @@ function validateName( ): void { // If a schema explicitly allows some legacy name which is no longer valid, // allow it to be assumed valid. - if ( - context.schema.__allowedLegacyNames && - context.schema.__allowedLegacyNames.indexOf(node.name) !== -1 - ) { + if (context.schema.__allowedLegacyNames.indexOf(node.name) !== -1) { return; } // Ensure names are valid, however introspection types opt out. diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index b8fc8b2e43..e72b6c0fd0 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -237,12 +237,9 @@ export function extendSchema( ]; // Support both original legacy names and extended legacy names. - const schemaAllowedLegacyNames = schema.__allowedLegacyNames; - const extendAllowedLegacyNames = options && options.allowedLegacyNames; - const allowedLegacyNames = - schemaAllowedLegacyNames && extendAllowedLegacyNames - ? schemaAllowedLegacyNames.concat(extendAllowedLegacyNames) - : schemaAllowedLegacyNames || extendAllowedLegacyNames; + const allowedLegacyNames = schema.__allowedLegacyNames.concat( + (options && options.allowedLegacyNames) || [], + ); // Then produce and return a Schema with these types. return new GraphQLSchema({