smallrye-graphql
smallrye-graphql copied to clipboard
Ignore Interface on GraphQL Model Classes for Schemabuilder
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.
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.
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)
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.
@michaelsonnleitner - can you create a reproducer ? That will fast track this.
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
Ok cool. I would think that the @Ignore must be on Adress2nd ?
yes and no ;)
ignore on AdressCode would ignore any other class implementing it igonre on Adress2nd would only ignore that class.
Ok, so if added to the interface, we also do not create the
interface AdressCode {
code: String
}
part in the schema ?
in my opinion not. but I am new in graphql
mmm, But that would not make sense, if you add @Ignore on the AddressCode interface, I would assume we need to ignore that interface ?
yes ignore and not add to schema (in my opinion)
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.
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?
I don't think we finalized on how this should work. Probably something that needs discussion on spec level
Would be nice to have this.