Skip to content

fix: allow modifying GraphQLInterfaceType in the willAddGraphQLTypeToSchema hook #293

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

Merged
merged 2 commits into from
Aug 5, 2019

Conversation

dariuszkuc
Copy link
Collaborator

InterfaceBuilder attempts to create all the implementing GraphQLObjectTypes after building an interface but before executing the willAddGraphQLTypeToSchema hook. This means that if we attempt to update the interface in that hook there could be some objects implementing that interface and referencing the old one. Since graphql-java schema objects don't implement hashcode we end up with type conflict of two interfaces being defined in the schema.

Fix is to use GraphQLTypeReference when referencing GraphQLInterfaceType from the GraphQLObjectType builder. Reference is just by name and they are resolved as the last step of building a schema. This allows us to modify the interface in the hook.

Resolves: #281

@codecov
Copy link

codecov bot commented Aug 5, 2019

Codecov Report

Merging #293 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #293      +/-   ##
============================================
- Coverage     64.57%   64.56%   -0.01%     
+ Complexity      195      194       -1     
============================================
  Files           103      103              
  Lines          1067     1064       -3     
  Branches        153      152       -1     
============================================
- Hits            689      687       -2     
+ Misses          364      363       -1     
  Partials         14       14
Impacted Files Coverage Δ Complexity Δ
...xpedia/graphql/generator/types/InterfaceBuilder.kt 100% <ø> (ø) 2 <0> (ø) ⬇️
...om/expedia/graphql/generator/types/QueryBuilder.kt 100% <ø> (ø) 5 <0> (ø) ⬇️
...om/expedia/graphql/generator/types/UnionBuilder.kt 88.23% <ø> (+8.23%) 2 <0> (ø) ⬇️
...m/expedia/graphql/generator/types/ObjectBuilder.kt 95.23% <100%> (ø) 3 <0> (ø) ⬇️
...otlin/com/expedia/graphql/generator/TypeBuilder.kt 96.66% <0%> (-3.34%) 19% <0%> (-1%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10da005...e0f50df. Read the comment docs.

…Schema hook

InterfaceBuilder attempts to create all the implementing `GraphQLObjectType`s after building an interface but before executing the `willAddGraphQLTypeToSchema` hook. This means that if we attempt to update the interface in that hook there could be some objects implementing that interface and referencing the old one. Since graphql-java schema objects don't implement hashcode we end up with type conflict of two interfaces being defined in the schema.

Fix is to use `GraphQLTypeReference` when referencing `GraphQLInterfaceType` from the `GraphQLObjectType` builder. Reference is just by name and they are resolved as the last step of building a schema. This allows us to modify the interface in the hook.

Resolves: ExpediaGroup#281
assertEquals("SomeData!", hooks.lastSeenGeneratedType?.deepName)
assertTrue(hooks.seenTypes.contains(RandomData::class.createType()))
assertTrue(hooks.seenTypes.contains(SomeData::class.createType()))
// TODO bug: didGenerateGraphQLType hook is not applied on the object types build from the interface
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO intended here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes -> it is a bug in how we apply the hooks... :(

@tapaderster tapaderster merged commit 4d62752 into ExpediaGroup:master Aug 5, 2019
@dariuszkuc dariuszkuc deleted the fix_interface_hook branch August 5, 2019 16:28
smyrick pushed a commit to smyrick/graphql-kotlin that referenced this pull request Sep 11, 2019
…Schema hook (ExpediaGroup#293)

* fix: allow modifying GraphQLInterfaceType in the willAddGraphQLTypeToSchema hook

InterfaceBuilder attempts to create all the implementing `GraphQLObjectType`s after building an interface but before executing the `willAddGraphQLTypeToSchema` hook. This means that if we attempt to update the interface in that hook there could be some objects implementing that interface and referencing the old one. Since graphql-java schema objects don't implement hashcode we end up with type conflict of two interfaces being defined in the schema.

Fix is to use `GraphQLTypeReference` when referencing `GraphQLInterfaceType` from the `GraphQLObjectType` builder. Reference is just by name and they are resolved as the last step of building a schema. This allows us to modify the interface in the hook.

Resolves: ExpediaGroup#281

* update test to verify hook updates interface description
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
…Schema hook (ExpediaGroup#293)

* fix: allow modifying GraphQLInterfaceType in the willAddGraphQLTypeToSchema hook

InterfaceBuilder attempts to create all the implementing `GraphQLObjectType`s after building an interface but before executing the `willAddGraphQLTypeToSchema` hook. This means that if we attempt to update the interface in that hook there could be some objects implementing that interface and referencing the old one. Since graphql-java schema objects don't implement hashcode we end up with type conflict of two interfaces being defined in the schema.

Fix is to use `GraphQLTypeReference` when referencing `GraphQLInterfaceType` from the `GraphQLObjectType` builder. Reference is just by name and they are resolved as the last step of building a schema. This allows us to modify the interface in the hook.

Resolves: ExpediaGroup#281

* update test to verify hook updates interface description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

GraphQLInterfaceType is not support in willAddGraphQLTypeToSchema
3 participants