Skip to content

Throw error if no possible concrete types found #1277

Closed
@mattkrick

Description

@mattkrick

While using relay modern v1.5.0, I got the following when running relay-compiler (I promise this is a graphql issue):

ERROR:
Cannot read property 'some' of undefined
error An unexpected error occurred: "Command failed.
Exit code: 100

Note that the error has no stack trace!

The some that it mentioned was:

	function hasConcreteTypeThatImplements(schema, type, interfaceName) {
	  return isAbstractType(type) && getConcreteTypes(schema, type).some(function (concreteType) {
	    return implementsInterface(concreteType, interfaceName);
	  });
	}

Ultimately, this was caused because when graphql built my schema, it crawled & found the GraphQLInterfaceType, but it didn't find the concrete types that implemented the interface.
This didn't throw an error in GraphQL; however, calling schema.getPossibleTypes returned undefined, which borked it in the compiler.

While it'd be nice for relay-compiler to catch errors & include a stack trace, I think the real issue is that GraphQL allows an abstract type to exist without any concrete types!

I propose closing this hole by calling schema.getPossibleTypes for each abstract type when building the schema. if the result is undefined then throw a friendly error telling the user to add that concrete type to their rootSchema.types.

Happy to PR if this sounds like a reasonable plan!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions