Enigmatis / graphql-java-annotations

GraphQL Annotations for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@GraphQLNonNull is not inherited from interfaces

shevek opened this issue · comments

Quoth GraphQL:

    graphql.schema.validation.InvalidSchemaException: invalid schema:
    object type 'Pipeline' does not implement interface 'Entity' because field 'name' is defined as 'String' type and not as 'String!' type
        at graphql.schema.GraphQLSchema$Builder.build(GraphQLSchema.java:418)

Code is

public interface Entity { @GraphQLNonNull public String getName(); }
public class Pipeline implements Entity { @Override public String getName() ... }

I should not need to re-annotate GraphQLNonNull

commented

In the graphql schema way of implementing interface, you must specify the type of the inherited field, for example:

interface Entity {
   name: String!
}
type Pipeline implements Entity {
   name: String!
}

It's not valid if you create your Pipeline this way:

type Pipeline implements Entity {
    name: String
}

So I think the same should be applied here - you must specify the type is non-null in the implementation also

I understand your argument but that suggests that I must know GraphQL semantics in order to write the Java. I would rather have preferred that the Java semantics were transferred to the GraphQL, since there's fundamentally no conflict. This, I think, is a major success of e.g. the Jackson API, it Does What You Want, and this looks like an unambiguous opportunity to apply that philosophy. So I disagree with your conclusions.

commented

So how are you suggesting to declare a non null field? Because it must be declared on the sub type and not only the interface

I'm suggesting that part of the purpose of graphql-java-annotations is to inspect the interfaces in the Java domain with Java semantics, and transfer the nonnull annotations to the implementing classes/subclasses. Transfer the Java semantics to the GraphQL semantics.

Java allows me to say @Nonnull once, GraphQL requires me to say it in multiple places, graphql-java-annotations should do that work for me by copying it from the interface to the type.

Another way of saying this is that if I use an inherited annotation in Java, then I want it inherited. Jackson allows inherited annotations. GSON allows inherited annotations. findbugs, spotbugs, errorprone, etc all allow inherited annotations. So should GraphQL-Java.