Skip to content

How can I use a generated client with @Autowired for Spring #908

Answered by dariuszkuc
xetra11 asked this question in Q&A
Discussion options

You must be logged in to vote

In order to use the generated clients as Spring beans you will need to manually register them with Spring context, e.g. given HelloWorldQuery you could create it as

@Configuration
class QueryConfiguration {
    @Bean
    fun graphQLWebClient(builder: WebClient.Builder) = 
        GraphQLWebClient(url = "http://localhost:8080/graphql", builder = builder)
    
    @Bean
    fun helloWorldQuery(graphQLWebClient: GraphQLWebClient) = HelloWorldQuery(graphQLWebClient)
}

You can then autowire helloWorldQuery: HelloWorldQuery bean to any of your services.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by dariuszkuc
Comment options

You must be logged in to vote
3 replies
@xetra11
Comment options

@smyrick
Comment options

@dariuszkuc
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #908 on October 17, 2020 04:10.