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

BREAKING CHANGE: empty complex types should fail schema generation #541

Merged
merged 3 commits into from
Jan 10, 2020

Conversation

dariuszkuc
Copy link
Collaborator

📝 Description

GraphQL specification requires Query type to be present as it is required to run introspection query. Per specification it also shouldn't be possible to generate empty complex types (objects, input objects or interfaces) and they should expose at least a single field. Since root Query type is a special GraphQLObjectType it also has to expose at least a single field.

Breaking changes:

  • at least single Query is required when generating the schema
  • split didGenerateQueryType hook (and corresponding Mutation and Subscription hooks) into didGenerateQueryFieldType (previous functionality) and didGenerateQueryObjectType hooks to allow more granular control when generating the schema
  • default SchemaGeneratorHooks now performs validation of generated object types (including special query, mutation and subscription types), input object types and interfaces to ensure we don't generate empty complex object types

see: graphql/graphql-spec#490 and graphql/graphql-spec#568

🔗 Related Issues

None

GraphQL specification requires Query type to be present as it is required to run introspection query. Per specification it also shouldn't be possible to generate empty complex types (objects, input objects or interfaces) and they should expose at least a single field. Since root Query type is a special GraphQLObjectType it also has to expose at least a single field.

Breaking changes:
* at least single Query is required when generating the schema
* split `didGenerateQueryType` hook (and corresponding `Mutation` and `Subscription` hooks) into `didGenerateQueryFieldType` (previous functionality) and `didGenerateQueryObjectType` hooks to allow more granular control when generating the schema
* default `SchemaGeneratorHooks` now performs validation of generated object types (including special query, mutation and subscription types), input object types and interfaces to ensure we don't generate empty complex object types

see: graphql/graphql-spec#490 and graphql/graphql-spec#568
@@ -90,22 +100,58 @@ interface SchemaGeneratorHooks {
/**
* Called after wrapping the type based on nullity but before adding the generated type to the schema
*/
fun didGenerateGraphQLType(type: KType, generatedType: GraphQLType) = generatedType
@Suppress("Detekt.ThrowsCount")
fun didGenerateGraphQLType(type: KType, generatedType: GraphQLType): GraphQLType {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we are validating in didGenerateGraphQLType instead of willAddGraphQLTypeToSchema hook to allow custom modifications in the latter (including adding new fields).

@dariuszkuc dariuszkuc added changes: major Changes require a major version type: bug Something isn't working labels Jan 9, 2020
Federated schema at minimum will add _service query so there is no need for explicit queries
@dariuszkuc dariuszkuc merged commit 9d2be3f into ExpediaGroup:master Jan 10, 2020
@dariuszkuc dariuszkuc deleted the empty_objects branch January 10, 2020 18:53
@smyrick smyrick added this to the 2.0.0 milestone Feb 1, 2020
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
…xpediaGroup#541)

* BREAKING CHANGE: empty complex types should fail schema generation

GraphQL specification requires Query type to be present as it is required to run introspection query. Per specification it also shouldn't be possible to generate empty complex types (objects, input objects or interfaces) and they should expose at least a single field. Since root Query type is a special GraphQLObjectType it also has to expose at least a single field.

Breaking changes:
* at least single Query is required when generating the schema
* split `didGenerateQueryType` hook (and corresponding `Mutation` and `Subscription` hooks) into `didGenerateQueryFieldType` (previous functionality) and `didGenerateQueryObjectType` hooks to allow more granular control when generating the schema
* default `SchemaGeneratorHooks` now performs validation of generated object types (including special query, mutation and subscription types), input object types and interfaces to ensure we don't generate empty complex object types

see: graphql/graphql-spec#490 and graphql/graphql-spec#568
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: major Changes require a major version type: bug Something isn't working
Development

Successfully merging this pull request may close these issues.

2 participants