-
Notifications
You must be signed in to change notification settings - Fork 345
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
dariuszkuc
commented
Jan 9, 2020
@@ -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 { |
There was a problem hiding this comment.
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
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
smyrick
reviewed
Jan 10, 2020
...tlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/hooks/SchemaGeneratorHooks.kt
Outdated
Show resolved
Hide resolved
smyrick
approved these changes
Jan 10, 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 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:
didGenerateQueryType
hook (and correspondingMutation
andSubscription
hooks) intodidGenerateQueryFieldType
(previous functionality) anddidGenerateQueryObjectType
hooks to allow more granular control when generating the schemaSchemaGeneratorHooks
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 typessee: graphql/graphql-spec#490 and graphql/graphql-spec#568
🔗 Related Issues
None