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: *generateGraphQLType hooks are now called on interfaces #303

Merged
merged 3 commits into from
Aug 16, 2019

Conversation

smyrick
Copy link
Contributor

@smyrick smyrick commented Aug 14, 2019

Fixes #294

Interfaces now go through the internal TypeBuilder method 'graphQLTypeOf' instead of 'objectFromReflection'. This means we can make 'objectFromReflection' private. But the type may be (if not always) wrapped in a GraphQLNonNull which means we have to cast it back to the interface type before adding it to the ObjectBuilder.

@smyrick smyrick added type: bug Something isn't working changes: patch Changes require a patch version labels Aug 14, 2019
val cacheKey = getCacheKeyString(key)

if (cacheKey != null) {
typeUnderConstruction.remove(kGraphQLType.kClass)
return cache.put(cacheKey, kGraphQLType)
cache[cacheKey] = kGraphQLType
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to remove from typeUnderConstruction since the only place we add is in the buildIfNotUnderConstruction method and we also remove it there.

@smyrick smyrick added the status: do not merge Do not merge until this is removed label Aug 14, 2019
@smyrick
Copy link
Contributor Author

smyrick commented Aug 14, 2019

@dkuc84 So I found the actual issue with this #294

This code change doesn’t fix the test you commented in previously. If I simplify the unit test and have a query class that only returns field which the return type is the interface then the schema never directly contains all the implementations of the interface, they are all in the additional types. That means to fix the issue we just need to add the hooks where we call the additional types.

Fixes ExpediaGroup#294

Interfaces now go through the internal TypeBuilder method 'graphQLTypeOf' instead of 'objectFromReflection'. This means we can make 'objectFromReflection' private. But the type may be (if not always) wrapped in a GraphQLNonNull which means we have to cast it back to the interface type before adding it to the ObjectBuilder.
@ExpediaGroup ExpediaGroup deleted a comment from codecov bot Aug 15, 2019
@@ -76,8 +75,8 @@ open class SchemaGenerator(val config: SchemaGeneratorConfig) {
open fun listType(type: KType, inputType: Boolean) =
listTypeBuilder.listType(type, inputType)

open fun objectType(kClass: KClass<*>, interfaceType: GraphQLInterfaceType? = null) =
objectTypeBuilder.objectType(kClass, interfaceType)
open fun objectType(kClass: KClass<*>) =
Copy link
Contributor Author

@smyrick smyrick Aug 15, 2019

Choose a reason for hiding this comment

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

Since we no longer directly call objectType, we never call the method passing in an interface so we can clean this up

@codecov
Copy link

codecov bot commented Aug 15, 2019

Codecov Report

Merging #303 into master will increase coverage by 0.11%.
The diff coverage is 93.93%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #303      +/-   ##
============================================
+ Coverage     94.31%   94.42%   +0.11%     
+ Complexity      260      256       -4     
============================================
  Files            73       74       +1     
  Lines           914      915       +1     
  Branches        169      169              
============================================
+ Hits            862      864       +2     
  Misses           31       31              
+ Partials         21       20       -1
Impacted Files Coverage Δ Complexity Δ
...expedia/graphql/generator/types/FunctionBuilder.kt 100% <100%> (ø) 10 <0> (-3) ⬇️
...raphql/generator/extensions/kFunctionExtensions.kt 100% <100%> (ø) 0 <0> (?)
...xpedia/graphql/generator/types/InterfaceBuilder.kt 100% <100%> (ø) 2 <0> (ø) ⬇️
...lin/com/expedia/graphql/generator/SubTypeMapper.kt 100% <100%> (ø) 3 <2> (ø) ⬇️
...n/com/expedia/graphql/generator/SchemaGenerator.kt 97.43% <100%> (-0.07%) 20 <1> (-1)
...otlin/com/expedia/graphql/generator/TypeBuilder.kt 96.96% <100%> (+0.3%) 20 <0> (+1) ⬆️
.../com/expedia/graphql/generator/state/TypesCache.kt 100% <100%> (ø) 20 <0> (ø) ⬇️
...m/expedia/graphql/generator/types/ObjectBuilder.kt 94.73% <83.33%> (-0.51%) 2 <0> (-1)
...om/expedia/graphql/generator/types/UnionBuilder.kt 93.75% <83.33%> (+5.51%) 2 <0> (ø) ⬇️

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 4c2652f...e0582a7. Read the comment docs.

@smyrick smyrick removed the status: do not merge Do not merge until this is removed label Aug 15, 2019
@smyrick
Copy link
Contributor Author

smyrick commented Aug 15, 2019

Ready for review

@dariuszkuc dariuszkuc merged commit 5812fa0 into ExpediaGroup:master Aug 16, 2019
@smyrick smyrick deleted the fix-interface-hooks branch August 16, 2019 03:21
smyrick added a commit to smyrick/graphql-kotlin that referenced this pull request Sep 11, 2019
…Group#303)

* fix: *generateGraphQLType hooks are now called on interfaces

Fixes ExpediaGroup#294

Interfaces now go through the internal TypeBuilder method 'graphQLTypeOf' instead of 'objectFromReflection'. This means we can make 'objectFromReflection' private. But the type may be (if not always) wrapped in a GraphQLNonNull which means we have to cast it back to the interface type before adding it to the ObjectBuilder.
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
…Group#303)

* fix: *generateGraphQLType hooks are now called on interfaces

Fixes ExpediaGroup#294

Interfaces now go through the internal TypeBuilder method 'graphQLTypeOf' instead of 'objectFromReflection'. This means we can make 'objectFromReflection' private. But the type may be (if not always) wrapped in a GraphQLNonNull which means we have to cast it back to the interface type before adding it to the ObjectBuilder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: patch Changes require a patch version type: bug Something isn't working
Development

Successfully merging this pull request may close these issues.

Hooks are not applied on objects build from InterfaceBuilder and UnionBuilder
2 participants