smallrye-graphql icon indicating copy to clipboard operation
smallrye-graphql copied to clipboard

Ignore Interface on GraphQL Model Classes for Schemabuilder

Open michaelsonnleitner opened this issue 5 years ago • 16 comments

I have following GraphQL Endpoint with following Java Model and Interface.

@GraphQLApi
public class ModelGraphQL {
    @Query
    public Model getModel(@Name("id") long id) {
        return new Model(id);
    }
}
public class Model implements AnyInterface {
   public void someMethod() {  }
}
public class Model2 implements AnyInterface {
   public void someMethod() {  }
}
public interface AnyInterface {
void someMethod();
}

Is it possible to be able to tell the schemabuilder not to add all Types implementing AnyInterface to the schema.

eg. Cloneable and Serializable is not added to schema.

michaelsonnleitner avatar Nov 04 '20 07:11 michaelsonnleitner

Hi @michaelsonnleitner . I don't think at the moment that there is a way, you can try and use events (see https://quarkus.io/blog/experimental_graphql/#events-and-custom-execution) to manually remove that as a workaround for now.

I'll keep this issue open and we can maybe look at supporting @Ignore on Type level.

phillip-kruger avatar Nov 04 '20 09:11 phillip-kruger

the real problem is that the schema parse can not deal with following model

public class MyList extends ArrayList<Model>

getting following error on startup:

Caused by: io.smallrye.graphql.schema.SchemaBuilderException: No class info found for parametrizedParentType name [java.util.ArrayList]
	at io.smallrye.graphql.schema.creator.ReferenceCreator.getReference(ReferenceCreator.java:286)
	at io.smallrye.graphql.schema.creator.ReferenceCreator.createReferenceForPojoField(ReferenceCreator.java:149)
	at io.smallrye.graphql.schema.creator.FieldCreator.createFieldForPojo(FieldCreator.java:114)
	at io.smallrye.graphql.schema.creator.type.TypeCreator.addFields(TypeCreator.java:104)
	at io.smallrye.graphql.schema.creator.type.TypeCreator.create(TypeCreator.java:72)
	at io.smallrye.graphql.schema.creator.type.TypeCreator.create(TypeCreator.java:41)
	at io.smallrye.graphql.schema.SchemaBuilder.createAndAddToSchema(SchemaBuilder.java:197)
	at io.smallrye.graphql.schema.SchemaBuilder.addTypesToSchema(SchemaBuilder.java:130)
	at io.smallrye.graphql.schema.SchemaBuilder.generateSchema(SchemaBuilder.java:111)
	at io.smallrye.graphql.schema.SchemaBuilder.build(SchemaBuilder.java:80)
	at io.smallrye.graphql.schema.SchemaBuilder.build(SchemaBuilder.java:67)
	at io.smallrye.graphql.servlet.StartupListener.contextInitialized(StartupListener.java:61)
	at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
	at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:217)
	at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:186)
	at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
	at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
	at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
	at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
	at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
	at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
	at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:252)

michaelsonnleitner avatar Nov 04 '20 10:11 michaelsonnleitner

Ok, that is a different story. Yes that is not supported at the moment, but again, let's keep this issue open and add support for this.

phillip-kruger avatar Nov 04 '20 10:11 phillip-kruger

@michaelsonnleitner - can you create a reproducer ? That will fast track this.

phillip-kruger avatar Nov 05 '20 11:11 phillip-kruger

I have added it to following example. https://github.com/michaelsonnleitner/sample-async-graphql/blob/master/src/main/java/at/raiffeisen/graphql/Adress2nd.java

Adress2nd is not referenced in my GraphQL Resource but indirectly referenced by https://github.com/michaelsonnleitner/sample-async-graphql/blob/master/src/main/java/at/raiffeisen/graphql/AdressCode.java

following schema is generated:

interface AdressCode {
  code: String
}

type Adress implements AdressCode {
  code: String
  detailAdresses: DetailAdress
  id: BigInteger!
  lines: [String]
}

type Adress2nd implements AdressCode {
  code: String
  id: BigInteger!
  lines: [String]
}
...

It would be nice to add @Ignore on AdressCode Interface

michaelsonnleitner avatar Nov 09 '20 13:11 michaelsonnleitner

Ok cool. I would think that the @Ignore must be on Adress2nd ?

phillip-kruger avatar Nov 09 '20 14:11 phillip-kruger

yes and no ;)

ignore on AdressCode would ignore any other class implementing it igonre on Adress2nd would only ignore that class.

michaelsonnleitner avatar Nov 09 '20 14:11 michaelsonnleitner

Ok, so if added to the interface, we also do not create the

interface AdressCode {
  code: String
}

part in the schema ?

phillip-kruger avatar Nov 09 '20 14:11 phillip-kruger

in my opinion not. but I am new in graphql

michaelsonnleitner avatar Nov 09 '20 14:11 michaelsonnleitner

mmm, But that would not make sense, if you add @Ignore on the AddressCode interface, I would assume we need to ignore that interface ?

phillip-kruger avatar Nov 09 '20 15:11 phillip-kruger

yes ignore and not add to schema (in my opinion)

michaelsonnleitner avatar Nov 09 '20 15:11 michaelsonnleitner

This requires a change in the spec to allow using the annotation on TYPE: I created https://github.com/eclipse/microprofile-graphql/issues/346 for that.

phillip-kruger avatar Nov 20 '20 11:11 phillip-kruger

Do I get this right: if the interface is @Ignored, the subclasses should still be in the schema, but not with the common interface, which is possible in GraphQL? But what would happen if Adress2nd would be @Ignored, but the code actually returns it?

t1 avatar May 12 '22 15:05 t1

I don't think we finalized on how this should work. Probably something that needs discussion on spec level

phillip-kruger avatar May 12 '22 23:05 phillip-kruger

Would be nice to have this.

robp94 avatar Jun 15 '22 12:06 robp94