Skip to content

GraphQL Interface fields that are also an interface, are omitted from the generated interface #881

@Helmsdown

Description

@Helmsdown

This commit solved the problem of interface fields that are also interfaces by completely excluding them from the generated interface.

        mergedFieldDefinitions.filterSkipped().forEach {
            // Only generate getters/setters for fields that are not interfaces.
            //
            // interface Pet {
            // 	 parent: Pet
            // }
            // type Dog implements Pet {
            // 	 parent: Dog
            // }
            // type Bird implements Pet {
            // 	 parent: Bird
            // }
            // For the schema above, we currently generate Dog::setParent(Dog dog), but the interface
            // would have Pet::setParent(Pet pet) leading to missing overrides in the generated
            // implementation classes. This is not an issue if the overridden field has the same base type,
            // however.
            // Ref: https://github.com/graphql/graphql-js/issues/776
            if (!isFieldAnInterface(it) || config.generateInterfaceMethodsForInterfaceFields) {
                addInterfaceMethod(it, javaType)
            }
        }

I would like to propose that we generate the getter for the interface fields, but not the setter. This will allow clients to interact with the polymorphic interface type, get the data they want without having to downcast to the concrete type, and it won't break the concrete implementations of the top level interface.

public interface Pet {
    Pet getParent();

    //no setter as that would make `setParent` not compile in the concrete implemenetations
}

public class Dog implements Pet {

  @Override
   public Dog getParent() {}

   public void setParent(Dog dog) {}
}


public class Bird implements Pet {
   @Override
   public Bird getParent();

   public void setParent(Bird bird) {}
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions