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

fix #1277 ensure interface has at least 1 concrete type #1280

Merged
merged 7 commits into from
Apr 4, 2018

Conversation

mattkrick
Copy link
Contributor

@mattkrick mattkrick commented Mar 8, 2018

Changes:

if (possibleTypes.length === 0) {
context.reportError(
`No concrete types found for Interface type ${iface.name}. ` +
`If only referenced via abstraction, add concrete types to schema.types array`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema can be create using SDL syntax so add concrete types to schema.types array part would be confusing in such case.
concrete types - better to avoid inventing new terminology.

Something like this would be great:
Interface ${iface.name} should be implemented by at least one object type.
Disclaimer: I'm grammatically challenged 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, fixed!

mattkrick added a commit to mattkrick/graphql that referenced this pull request Mar 9, 2018
@mattkrick
Copy link
Contributor Author

@IvanGoncharov ready for another review!

@@ -204,7 +207,7 @@ export class GraphQLSchema {
if (!possibleTypeMap[abstractType.name]) {
const possibleTypes = this.getPossibleTypes(abstractType);
invariant(
Array.isArray(possibleTypes),
Array.isArray(possibleTypes) && possibleTypes.length > 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a late checking invariant, not part of the scheme validation. This change shouldn't be necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leebyron this was only necessary for getting the schema tests working

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema tests will likely need to change instead of changing this invariant. In fact, this entire invariant check shouldn't even be necessary if this step is done as part of schema validation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully agree. The invariant can go away because getPossibleTypes is now guaranteed to return an array.
The test can go away because there's no way isPossibleType can produce an error.

@@ -76,19 +76,6 @@ const Schema = new GraphQLSchema({
});

describe('Type System: Schema', () => {
describe('Getting possible types', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPossibleType can no longer throw, so this test is no longer needed

@@ -159,6 +160,8 @@ export class GraphQLSchema {
this._implementations[iface.name] = [type];
}
});
} else if (isAbstractType(type) && !this._implementations[type.name]) {
this._implementations[type.name] = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guarantees that getPossibleTypes returns an array, as it should per its flow type.

@mattkrick
Copy link
Contributor Author

@leebyron that should fix it up


if (possibleTypes.length === 0) {
context.reportError(
`Interface ${iface.name} must be implemented` +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please expand the tests further to include a test which asserts this error occurs?

@mattkrick
Copy link
Contributor Author

validation test added, ready for another go

@leebyron leebyron merged commit 43ff3e3 into graphql:master Apr 4, 2018
@leebyron
Copy link
Contributor

leebyron commented Apr 4, 2018

Great work!

leebyron pushed a commit to graphql/graphql-spec that referenced this pull request Apr 4, 2018
* Require Interface to implement at least 1 Object

Matching PR for graphql-js: graphql/graphql-js#1280

* add period
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants