Reactor DataFetcher support

Closes gh-47
This commit is contained in:
Rossen Stoyanchev
2021-04-23 20:57:22 +01:00
parent a57b78e521
commit 1e619263d2
20 changed files with 565 additions and 24 deletions

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.sample.graphql;
import graphql.GraphQL;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.graphql.WebGraphQLService;
import org.springframework.graphql.test.query.GraphQLTester;
/**
* GraphQL query tests directly via {@link GraphQL}.
*/
@SpringBootTest
public class QueryTests {
private GraphQLTester graphQLTester;
@BeforeEach
public void setUp(@Autowired WebGraphQLService service) {
this.graphQLTester = GraphQLTester.create(webInput ->
service.execute(webInput).contextWrite(context -> context.put("name", "James")));
}
@Test
void greetingMono() {
this.graphQLTester.query("{greetingMono}")
.execute()
.path("greetingMono")
.entity(String.class)
.isEqualTo("Hello James");
}
@Test
void greetingsFlux() {
this.graphQLTester.query("{greetingsFlux}")
.execute()
.path("greetingsFlux")
.entityList(String.class)
.containsExactly("Hi James", "Bonjour James", "Hola James", "Ciao James", "Zdravo James");
}
}

View File

@@ -30,14 +30,15 @@ import org.springframework.graphql.test.query.GraphQLTester;
* GraphQL subscription tests directly via {@link GraphQL}.
*/
@SpringBootTest
public class SubscriptionGraphQLTests {
public class SubscriptionTests {
private GraphQLTester graphQLTester;
@BeforeEach
public void setUp(@Autowired WebGraphQLService service) {
this.graphQLTester = GraphQLTester.create(service);
this.graphQLTester = GraphQLTester.create(webInput ->
service.execute(webInput).contextWrite(context -> context.put("name", "James")));
}
@@ -50,7 +51,11 @@ public class SubscriptionGraphQLTests {
.toFlux("greetings", String.class);
StepVerifier.create(result)
.expectNext("Hi", "Bonjour", "Hola", "Ciao", "Zdravo")
.expectNext("Hi James")
.expectNext("Bonjour James")
.expectNext("Hola James")
.expectNext("Ciao James")
.expectNext("Zdravo James")
.verifyComplete();
}
@@ -64,8 +69,8 @@ public class SubscriptionGraphQLTests {
StepVerifier.create(result)
.consumeNextWith(spec -> spec.path("greetings").valueExists())
.consumeNextWith(spec -> spec.path("greetings").matchesJson("\"Bonjour\""))
.consumeNextWith(spec -> spec.path("greetings").matchesJson("\"Hola\""))
.consumeNextWith(spec -> spec.path("greetings").matchesJson("\"Bonjour James\""))
.consumeNextWith(spec -> spec.path("greetings").matchesJson("\"Hola James\""))
.expectNextCount(2)
.verifyComplete();
}