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.5k stars 326 forks source link

Better documentation when it comes to webflux and spring boot #435

Open Toerktumlare opened 4 years ago

Toerktumlare commented 4 years ago

Is your feature request related to a problem? Please describe. I am an intermediate java developer that spent 3 hours reading about graphql, i am at the moment developing a webflux application and i though about implementing graphql in my webflux application. I try first to find a webflux implementation which is hard enough and when i find one here, sadly there is no documentation about it.

In my googling i found a feature request for a webflux implementation and that brought me to the kickstart project, it was implemented in november last year, and that issue links to a sample project: Webflux sample

I also found another webflux project under examples: example-webflux

No documentation found about these projects or on the kickstarter page whatsoever about webflux, only servlet and spring boot, but not explicitly about webflux in the spring boot section. Both semple/example projects implement 2 dependencies in their gradle files:

graphql-kickstart-spring-boot-starter-webflux
graphql-kickstart-spring-boot-starter-tools

The first dependency i understand, the second one, no documentation why it is needed. I do find that in order to use the graphQL DSL you need the "GraphQL Java Tools" could the second dependency be that? i have no idea, since there is no documentation. Digging into the pom.xml i do find that the second dependency is dragging in graphql-kickstart-spring-boot-autoconfigure-tools that in turn is dragging in the graphql-java-tools so yes.

When booting up the spring boot application won't start.

Description:

Parameter 0 of method graphQLSchemaProvider in graphql.kickstart.spring.webflux.boot.GraphQLSpringWebfluxAutoConfiguration required a bean of type 'graphql.schema.GraphQLSchema' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'graphQLSchema' in 'GraphQLJavaToolsAutoConfiguration' not loaded because @ConditionalOnBean (types: graphql.kickstart.tools.SchemaParser; SearchStrategy: all) did not find any beans of type graphql.kickstart.tools.SchemaParser

Action:

Consider revisiting the entries above or defining a bean of type 'graphql.schema.GraphQLSchema' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:60904', transport: 'socket'

Process finished with exit code 1

It needs some sort of bean, but there is no documentation about what bean, and the purpose of the bean, or how to declare it etc.

in the sample application, no bean is declared, only schema files, i spend some time digging but can't figure out how the sample project works because no bean is declared there.

in the example project there is a bean declared:

    @Bean
    GraphQLSchema schema() {
        return GraphQLSchema.newSchema()
            .query(GraphQLObjectType.newObject()
                .name("query")
                .field(field -> field
                    .name("test")
                    .type(Scalars.GraphQLString)
                    .dataFetcher(environment -> "response")
                )
                .build())
            .build();
    }

But there is no declaration as to what this bean is, it looks like it is declaring a schema. There is no documentation about this bean on the kickstarted spring boot webpage either, i actually can't find a single word about the GraphQLSchema object in the entire documentation.

Describe the solution you'd like I wish there to be more user friendly documentation as to how to get started from scratch. Since there is a lot of question marks in to how to get started, or i'm just stupid. And if that is so i apologize because that could be also be a fact.

I'd gladly write some more documentation and submit a PR to the documentation repo, as soon as i start getting things.

MykolaGolubyev commented 4 years ago

I have spent two hours chasing how to make a working spring boot example :( still no luck. Quite a quest with cross links and examples that don't actually use .graphqls files. Dozen of articles on the internet using outdated dependencies doesn't help either.

lnnery commented 3 years ago

I have a working application using the libraries you mentioned, Mykola, please let me know if you still need it. @oliemansm I'm facing issue when I try execute unit tests. I tried run the application as JUnit application in Eclipse, and also run tests using Maven. In both scenarios the tests are executed, but it seems the GraphQL itself is not running. I created a very simple test where I try to do a POST call to http://localhost:8080/graphql but I always receive "connection refused", the GraphQL is not running. The application starts, the tested are called, but the GraphQL doesn't respond. This only happens with tests, if I run the application normally it works fine. Any ideas? Thanks

SJ052020 commented 3 years ago

I too am trying to implement webflux based application using below dependency as showing in the sample : https://github.com/graphql-java-kickstart/samples/tree/master/spring-boot-webflux

The query "hello" is returning the toString() value of Mono and not the String that Mono is holding: image

If I try a Mono of an object, I get an error like below: graphql.kickstart.tools.ResolverError: Expected source object to be an instance of 'com.example.demo.pojo.card.Item' but instead got 'reactor.core.publisher.MonoJust'

My build.gradle file is as below:

plugins { id 'org.springframework.boot' version '2.5.2' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' }

dependencies { compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-webflux' implementation 'com.graphql-java-kickstart:graphql-spring-boot-starter:11.0.0' compileOnly 'com.graphql-java-kickstart:graphql-java-tools:11.0.1' runtimeOnly 'com.graphql-java-kickstart:graphiql-spring-boot-starter:11.0.0' runtimeOnly 'com.graphql-java-kickstart:voyager-spring-boot-starter:11.0.0' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'io.projectreactor:reactor-test' }

Would appreciate any sample/pointer on using webflux with GraphQL,.

Toerktumlare commented 3 years ago

@SJ052020 those type of questions are more suited for Stack Overflow than here. In this git repo we address bugs, feature requests, improvements etc.