diff --git a/src/type/definition.js b/src/type/definition.js index 428304f71d8..b7795b5a4ba 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -563,7 +563,7 @@ export class GraphQLObjectType { name: string; description: ?string; astNode: ?ObjectTypeDefinitionNode; - extensionASTNodes: ?$ReadOnlyArray; + extensionASTNodes: $ReadOnlyArray; isTypeOf: ?GraphQLIsTypeOfFn<*, *>; _typeConfig: GraphQLObjectTypeConfig<*, *>; @@ -574,7 +574,7 @@ export class GraphQLObjectType { this.name = config.name; this.description = config.description; this.astNode = config.astNode; - this.extensionASTNodes = config.extensionASTNodes; + this.extensionASTNodes = config.extensionASTNodes || []; this.isTypeOf = config.isTypeOf; this._typeConfig = config; invariant(typeof config.name === 'string', 'Must provide name.'); @@ -820,7 +820,7 @@ export class GraphQLInterfaceType { name: string; description: ?string; astNode: ?InterfaceTypeDefinitionNode; - extensionASTNodes: ?$ReadOnlyArray; + extensionASTNodes: $ReadOnlyArray; resolveType: ?GraphQLTypeResolver<*, *>; _typeConfig: GraphQLInterfaceTypeConfig<*, *>; @@ -830,7 +830,7 @@ export class GraphQLInterfaceType { this.name = config.name; this.description = config.description; this.astNode = config.astNode; - this.extensionASTNodes = config.extensionASTNodes; + this.extensionASTNodes = config.extensionASTNodes || []; this.resolveType = config.resolveType; this._typeConfig = config; invariant(typeof config.name === 'string', 'Must provide name.'); diff --git a/src/type/schema.js b/src/type/schema.js index 1b2ea738d14..58d71acf070 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -83,7 +83,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 @@ -113,7 +113,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 d65b0dc87c6..99f13a7918f 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -218,10 +218,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. @@ -564,10 +561,8 @@ function getAllObjectNodes( type: GraphQLObjectType, ): $ReadOnlyArray { return type.astNode - ? type.extensionASTNodes - ? [type.astNode].concat(type.extensionASTNodes) - : [type.astNode] - : type.extensionASTNodes || []; + ? [type.astNode].concat(type.extensionASTNodes) + : type.extensionASTNodes; } function getAllObjectOrInterfaceNodes( @@ -579,10 +574,8 @@ function getAllObjectOrInterfaceNodes( | InterfaceTypeExtensionNode, > { return type.astNode - ? type.extensionASTNodes - ? [type.astNode].concat(type.extensionASTNodes) - : [type.astNode] - : type.extensionASTNodes || []; + ? [type.astNode].concat(type.extensionASTNodes) + : type.extensionASTNodes; } function getImplementsInterfaceNode( diff --git a/src/utilities/__tests__/extendSchema-test.js b/src/utilities/__tests__/extendSchema-test.js index 8731c65cfd7..71f9a10e891 100644 --- a/src/utilities/__tests__/extendSchema-test.js +++ b/src/utilities/__tests__/extendSchema-test.js @@ -245,7 +245,7 @@ describe('extendSchema', () => { const testDirective = extendedTwiceSchema.getDirective('test'); expect(query.extensionASTNodes).to.have.lengthOf(2); - expect(testType.extensionASTNodes).to.equal(undefined); + expect(testType.extensionASTNodes).to.have.lengthOf(0); const restoredExtensionAST = { kind: Kind.DOCUMENT, diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 237473b35b1..ce7a073b2ec 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -241,10 +241,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 = extendAllowedLegacyNames + ? schemaAllowedLegacyNames.concat(extendAllowedLegacyNames) + : schemaAllowedLegacyNames; // Then produce and return a Schema with these types. return new GraphQLSchema({ @@ -309,9 +308,7 @@ export function extendSchema( function extendObjectType(type: GraphQLObjectType): GraphQLObjectType { const name = type.name; const extensionASTNodes = typeExtensionsMap[name] - ? type.extensionASTNodes - ? type.extensionASTNodes.concat(typeExtensionsMap[name]) - : typeExtensionsMap[name] + ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : type.extensionASTNodes; return new GraphQLObjectType({ name, @@ -329,9 +326,7 @@ export function extendSchema( ): GraphQLInterfaceType { const name = type.name; const extensionASTNodes = typeExtensionsMap[name] - ? type.extensionASTNodes - ? type.extensionASTNodes.concat(typeExtensionsMap[name]) - : typeExtensionsMap[name] + ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : type.extensionASTNodes; return new GraphQLInterfaceType({ name: type.name,