Open gdelafosse opened 6 years ago
Sorry, I'm not familiar with CDI or jboss, so I can't provide any examples.
Ok, we manage to make it work by changing
@Inject
private Optional
by
@Inject
private Instance
in the generated TypeProviders.
Using javax.enterprise.inject.Instance is supported by the jboss CDI implementation. Hope we could provide a pull request.
Humm... it sounds like javax.enterprise.inject.Instance is a CDI specific thing. It might be worth commenting on this:
https://issues.jboss.org/browse/CDI-45?_sscc=t
...perhaps a good compromise is for graphql-apigen to generate CDI specific TypeProviders?
Note that if you want to avoid forking graphql-apigen, you can simply copy the modified graphql-apigen.stg into the directory containing your pom.xml:
https://github.com/Distelli/graphql-apigen/blob/master/apigen/src/main/resources/graphql-apigen.stg
Thanks, -Brian
Could you explain why those dependencies are optional?
The optional injection points are for resolve an object id into a full object. This isn't necessary for all objects. For example, you might not have foreign key references to an object type and thus it would never need to be resolved from id to full object.
That's the role of *.Resolver, but what about the _impl? In your example, AuthorTypeProvider needs an Author.Resolver implementation and also an Author implementation. In this case, the role of this Author imlementation. Is it an Author.Impl that will be injected? must I provide a bean that implement Author?
It's been awhile since I've thought about this, but you can see MethodDataFetcher will use the graphql.schema.DataFetchingEnvironment "source" if impl is null:
I believe this is useful if your implementation is a simple POJO that doesn't need to interact with your dependency injection system.
I debugged the Spring version. The AuthorTypeProvider has an Author _impl = null. The Optional injection works in Spring. In my CDI context, I still did not manage to inject an optional dependency. That's why I still have to implement an AuthorImpl that implements @Override public Author resolve(DataFetchingEnvironment env) { return env.getSource(); }
Could you confirm that a
Could you confirm that a Impl MUST be implemented ONLY for types that have function in the schema?
That is correct.
Hello I have difficulties to integrate graphql-apigen generated beans with CDI without guice. I use jboss as an application server. Could you provide an exemple?