★ wanayoo — archive 1999 https://github.com/graphql-java/graphql-java/pull/1884Nouvelle recherche | Portail wanayoo
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

1764 allow interfaces to implement other interfaces #1884

Conversation

@felipe-gdr
Copy link
Member

@felipe-gdr felipe-gdr commented Apr 27, 2020 •

Allows interfaces to implement other interfaces, as described in the draft spec.

fixes: #1764

@felipe-gdr
Copy link
Member Author

@felipe-gdr felipe-gdr commented Apr 28, 2020 •

  • use error list in asserts instead of regex for more fine tuned checks
@felipe-gdr felipe-gdr marked this pull request as draft Apr 28, 2020
@felipe-gdr felipe-gdr force-pushed the felipe-gdr:1764_allow-interfaces-to-implement-other-interfaces branch from 84a5b99 to ea740ef Apr 28, 2020
@felipe-gdr felipe-gdr force-pushed the felipe-gdr:1764_allow-interfaces-to-implement-other-interfaces branch from 0a95b71 to 3dfdab1 Apr 28, 2020
@andimarek
Copy link
Member

@andimarek andimarek commented Apr 29, 2020

thanks a lot @felipe-gdr. Please have a look at the Graphql JS PR as sanity check: graphql/graphql-js#2084

@felipe-gdr
Copy link
Member Author

@felipe-gdr felipe-gdr commented Apr 29, 2020 •

  • Interfaces declared in interface extensions are not being enforced by the transitive validation
@felipe-gdr
Copy link
Member Author

@felipe-gdr felipe-gdr commented Apr 29, 2020

thanks a lot @felipe-gdr. Please have a look at the Graphql JS PR as sanity check: graphql/graphql-js#2084

Yep, good idea.

@felipe-gdr
Copy link
Member Author

@felipe-gdr felipe-gdr commented Apr 29, 2020

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. 👍

@felipe-gdr felipe-gdr force-pushed the felipe-gdr:1764_allow-interfaces-to-implement-other-interfaces branch from 311ef32 to 4015f0d May 17, 2020
@felipe-gdr felipe-gdr marked this pull request as ready for review May 17, 2020
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) {

This comment has been minimized.

@bbakerman

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! ;)

#
extend type BaseType implements Interface1 {
extraField1 : String
}

This comment has been minimized.

@bbakerman

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

This comment has been minimized.

@felipe-gdr

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

field21: String
}
extend type Type1 implements Interface2 {

This comment has been minimized.

@bbakerman

bbakerman May 18, 2020
Member

My comment below is covered by this test

@bbakerman
Copy link
Member

@bbakerman bbakerman commented May 18, 2020

Wow this is impressive code - neat and conscice but readable

Copy link
Member

@andimarek andimarek left a comment

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()

This comment has been minimized.

@andimarek

andimarek May 18, 2020
Member

please use our map static function instead of streams directly

* @param <T>
*/
@PublicApi
public interface ImplementingTypeDefinition<T extends ImplementingTypeDefinition> extends TypeDefinition<T> {

This comment has been minimized.

@andimarek

andimarek May 18, 2020
Member

why the recursive type definition here?

This comment has been minimized.

@felipe-gdr

felipe-gdr May 19, 2020
Author Member

Yep, not needed. <T extends TypeDefinition> should be enough.

@PublicApi
public interface ImplementingTypeDefinition<T extends ImplementingTypeDefinition> extends TypeDefinition<T> {

List<Type> getImplements();

This comment has been minimized.

@andimarek

andimarek May 18, 2020
Member

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());

This comment has been minimized.

@andimarek

andimarek May 18, 2020
Member

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());

This comment has been minimized.

@andimarek

andimarek May 18, 2020
Member

please use the util function

This comment has been minimized.

@felipe-gdr

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?

*
* @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) {

This comment has been minimized.

@andimarek

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 comment has been minimized.

@felipe-gdr

felipe-gdr May 19, 2020
Author Member

Yep, just noticed that this is public API. I'll create a new method.

@andimarek andimarek added this to the 15.0 milestone May 19, 2020
- use FpKit
- fix Generic definition in ImplementingTypeDefinition
- don't break public API in TypeDefinitionRegistry
@felipe-gdr felipe-gdr force-pushed the felipe-gdr:1764_allow-interfaces-to-implement-other-interfaces branch from 1339a86 to 04cfbe7 May 20, 2020
@andimarek
Copy link
Member

@andimarek andimarek commented May 22, 2020

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.

@andimarek andimarek merged commit c508ac3 into graphql-java:master May 24, 2020
3 checks passed
3 checks passed
build
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.