Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using graphql-apigen #28

Open
gdelafosse opened this issue Apr 10, 2018 · 9 comments
Open

Using graphql-apigen #28

gdelafosse opened this issue Apr 10, 2018 · 9 comments

Comments

@gdelafosse
Copy link

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?

@brimworks
Copy link
Contributor

Sorry, I'm not familiar with CDI or jboss, so I can't provide any examples.

@gdelafosse
Copy link
Author

Ok, we manage to make it work by changing
@Inject
private Optional _impl

by
@Inject
private Instance _impl

in the generated TypeProviders.

Using javax.enterprise.inject.Instance is supported by the jboss CDI implementation.
Hope we could provide a pull request.

@brimworks
Copy link
Contributor

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

@gdelafosse
Copy link
Author

Could you explain why those dependencies are optional?

@brimworks
Copy link
Contributor

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.

@gdelafosse
Copy link
Author

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?

@brimworks
Copy link
Contributor

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:

https://github.com/Distelli/graphql-apigen/blob/master/apigen-deps/src/main/java/com/distelli/graphql/MethodDataFetcher.java

I believe this is useful if your implementation is a simple POJO that doesn't need to interact with your dependency injection system.

@gdelafosse
Copy link
Author

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 Impl MUST be implemented ONLY for types that have function in the schema?

@brimworks
Copy link
Contributor

Could you confirm that a Impl MUST be implemented ONLY for types that have function in the schema?

That is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants