Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up1764 allow interfaces to implement other interfaces #1884
Conversation
|
84a5b99
to
ea740ef
0a95b71
to
3dfdab1
|
thanks a lot @felipe-gdr. Please have a look at the Graphql JS PR as sanity check: graphql/graphql-js#2084 |
|
Yep, good idea. |
|
Looking at the graphq-js implementation was a good idea. I've simplified the validation code quite a bit. I didn't have to use recursion to find circular dependencies since the list of implemented interfaces is flattened at each interface type. |
311ef32
to
4015f0d
| assertErrorMessage(error, "The interface extension type 'BaseInterface' [@n:n] has tried to redefine field 'fieldB' arguments defined via interface 'InterfaceType' [@n:n] from 'arg3:Int' to 'arg3:String") | ||
| } | ||
|
|
||
| def assertErrorMessage(SchemaProblem error, expectedMessage) { |
bbakerman
May 18, 2020
Member
Nice one! We should do this in other tests.
Can you please rewrite all our tests to this pattern please! ;)
Nice one! We should do this in other tests.
Can you please rewrite all our tests to this pattern please! ;)
| # | ||
| extend type BaseType implements Interface1 { | ||
| extraField1 : String | ||
| } |
bbakerman
May 18, 2020
Member
Why does this need to be removed? Is it no longer valid or just not longer relevant and tested in the other places
Why does this need to be removed? Is it no longer valid or just not longer relevant and tested in the other places
felipe-gdr
May 18, 2020
Author
Member
This is actually invalid now.
I've added a new validation rule which prevents extensions from implementing an interface which has already been implemented from a base type, or other extensions for the same type.
This will make the graphql-java validation more aligned with graphql-js
This is actually invalid now.
I've added a new validation rule which prevents extensions from implementing an interface which has already been implemented from a base type, or other extensions for the same type.
This will make the graphql-java validation more aligned with graphql-js
| field21: String | ||
| } | ||
| extend type Type1 implements Interface2 { |
bbakerman
May 18, 2020
Member
My comment below is covered by this test
My comment below is covered by this test
|
Wow this is impressive code - neat and conscice but readable |
|
great work. Did a first review. See my comments. We also should have a "integration test" for the introspection result, what do you think? |
| @@ -185,6 +184,13 @@ InterfaceTypeDefinition createInterface(Map<String, Object> input) { | |||
|
|
|||
| InterfaceTypeDefinition.Builder interfaceTypeDefinition = InterfaceTypeDefinition.newInterfaceTypeDefinition().name((String) input.get("name")); | |||
| interfaceTypeDefinition.description(toDescription(input)); | |||
| if (input.containsKey("interfaces") && input.get("interfaces") != null) { | |||
| interfaceTypeDefinition.implementz( | |||
| ((List<Map<String, Object>>) input.get("interfaces")).stream() | |||
andimarek
May 18, 2020
Member
please use our map static function instead of streams directly
please use our map static function instead of streams directly
| * @param <T> | ||
| */ | ||
| @PublicApi | ||
| public interface ImplementingTypeDefinition<T extends ImplementingTypeDefinition> extends TypeDefinition<T> { |
andimarek
May 18, 2020
Member
why the recursive type definition here?
why the recursive type definition here?
felipe-gdr
May 19, 2020
Author
Member
Yep, not needed. <T extends TypeDefinition> should be enough.
Yep, not needed. <T extends TypeDefinition> should be enough.
| @PublicApi | ||
| public interface ImplementingTypeDefinition<T extends ImplementingTypeDefinition> extends TypeDefinition<T> { | ||
|
|
||
| List<Type> getImplements(); |
andimarek
May 18, 2020
Member
not great name, but not in scope to change it here.
not great name, but not in scope to change it here.
| private List<Type> getImplementz(GraphqlParser.ImplementsInterfacesContext implementsInterfacesContext) { | ||
| List<Type> implementz = new ArrayList<>(); | ||
| while (implementsInterfacesContext != null) { | ||
| List<TypeName> typeNames = implementsInterfacesContext.typeName().stream().map(this::createTypeName).collect(toList()); |
andimarek
May 18, 2020
Member
please use our map util function.
please use our map util function.
| @@ -90,7 +85,7 @@ | |||
|
|
|||
| private void checkForMissingTypes(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) { | |||
| // type extensions | |||
| List<ObjectTypeExtensionDefinition> typeExtensions = typeRegistry.objectTypeExtensions().values().stream().flatMap(Collection::stream).collect(Collectors.toList()); | |||
| List<ObjectTypeExtensionDefinition> typeExtensions = typeRegistry.objectTypeExtensions().values().stream().flatMap(Collection::stream).collect(toList()); | |||
andimarek
May 18, 2020
Member
please use the util function
please use the util function
felipe-gdr
May 19, 2020
Author
Member
FpKit#flatList applies to List<List<>> and we have a Collection<List<>> here.
Should we create a more generic flatten method in FpKit?
FpKit#flatList applies to List<List<>> and we have a Collection<List<>> here.
Should we create a more generic flatten method in FpKit?
| * | ||
| * @param targetInterface the target to search for | ||
| * @return the list of object types that implement the given interface type | ||
| */ | ||
| public List<ObjectTypeDefinition> getImplementationsOf(InterfaceTypeDefinition targetInterface) { | ||
| List<ObjectTypeDefinition> objectTypeDefinitions = getTypes(ObjectTypeDefinition.class); | ||
| public List<ImplementingTypeDefinition> getImplementationsOf(InterfaceTypeDefinition targetInterface) { |
andimarek
May 18, 2020
Member
this is a breaking change. Should we consider adding another one and keeping this one for use object implementations?
this is a breaking change. Should we consider adding another one and keeping this one for use object implementations?
felipe-gdr
May 19, 2020
Author
Member
Yep, just noticed that this is public API. I'll create a new method.
Yep, just noticed that this is public API. I'll create a new method.
- use FpKit - fix Generic definition in ImplementingTypeDefinition - don't break public API in TypeDefinitionRegistry
1339a86
to
04cfbe7
fix introspection interfaces field
and test SchemaPrinter
|
We need to add a verification for programmatically created GraphQLTypes that they declare all interfaces transitively. Also we need to look at AstPrinter if it prints correctly and add a test. |
Allows interfaces to implement other interfaces, as described in the draft spec.
fixes: #1764