graphql-java-kickstart / graphql-spring-boot

GraphQL and GraphiQL Spring Framework Boot Starters - Forked from oembedler/graphql-spring-boot due to inactivity.
https://www.graphql-java-kickstart.com/spring-boot/
MIT License
1.51k stars 324 forks source link

Document how to invoke internal graphql queries using the same schema the application is serving #464

Closed asfernandes closed 3 years ago

asfernandes commented 3 years ago

I cannot figure out how to do it, searching the issues here, google and stack overflow.

oliemansm commented 3 years ago

The reason we have those issue templates is to guide you to write proper and clear issues.

Do you want to send a GraphQL request over http to yourself? What is it that you're actually trying to do here?

There are libraries here for exposing a GraphQL API and there's one library for consuming GraphQL from java (webclient). If you want to consume from java then take a look at that library.

asfernandes commented 3 years ago

As I said, I want to internally route a graphql query to the same schema the application is serving. Not with HTTP.

For example, I would inject a GraphQL.

Didn't this library have any integration with the base graphql library for that?

asfernandes commented 3 years ago

I have seen something as https://stackoverflow.com/questions/58188938/how-to-execute-java-calls-to-graphql-in-a-spring-boot-graphql-java-tools-cont but does not work for me.

oliemansm commented 3 years ago

Should indeed be possible with the approach described there. If you want help/advise here or on stackoverflow you should add more detail and concrete information what's going wrong and why that's not working for you. And since that issue on stack overflow already addresses it you'd be best of adding a comment there.

asfernandes commented 3 years ago

I have tried in my project and had org.springframework.beans.factory.BeanCurrentlyInCreationException when injecting GraphQLInvocationInputFactory.

I'm also trying to build this graphql-spring-boot project in Eclipse, but after imported the project as gradle project, almost all the projects has errors (circular dependencies, etc).

asfernandes commented 3 years ago

The problem is to inject a GraphQLInvocationInputFactory inside a graphl resolver:

The dependencies of some of the beans in the application context form a cycle:

   graphQLServletRegistrationBean defined in class path resource [graphql/kickstart/spring/web/boot/GraphQLWebAutoConfiguration.class]
      ↓
   graphQLHttpServlet defined in class path resource [graphql/kickstart/spring/web/boot/GraphQLWebAutoConfiguration.class]
      ↓
   graphQLServletConfiguration defined in class path resource [graphql/kickstart/spring/web/boot/GraphQLWebAutoConfiguration.class]
┌─────┐
|  invocationInputFactory defined in class path resource [graphql/kickstart/spring/web/boot/GraphQLWebAutoConfiguration.class]
↑     ↓
|  graphQLSchemaProvider defined in class path resource [graphql/kickstart/spring/web/boot/GraphQLWebAutoConfiguration.class]
↑     ↓
|  graphQLSchema defined in class path resource [graphql/kickstart/tools/boot/GraphQLJavaToolsAutoConfiguration.class]
↑     ↓
|  schemaParser defined in class path resource [graphql/kickstart/tools/boot/GraphQLJavaToolsAutoConfiguration.class]
↑     ↓
|  bookResolver
└─────┘

But this is what I want.

Look:

But, looks like I cannot consume graphql services inside the same app if I want!

asfernandes commented 3 years ago

It seems it works using @Lazy.