Reinstate Spring for GraphQL auto-configuration
This commit adds the Spring for GraphQL auto-configuration back into Spring Boot 3.0, now that a 1.1.0 release is scheduled with the required baseline. This release also needs GraphQL Java 19.0 as a baseline. Closes gh-31809
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 org.springframework.boot.docs.features.testing.springbootapplications.springgraphqltests;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
|
||||
@AutoConfigureHttpGraphQlTester
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||
class GraphQlIntegrationTests {
|
||||
|
||||
@Test
|
||||
void shouldGreetWithSpecificName(@Autowired HttpGraphQlTester graphQlTester) {
|
||||
HttpGraphQlTester authenticatedTester = graphQlTester.mutate()
|
||||
.webTestClient(
|
||||
(client) -> client.defaultHeaders((headers) -> headers.setBasicAuth("admin", "ilovespring")))
|
||||
.build();
|
||||
authenticatedTester.document("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String.class)
|
||||
.isEqualTo("Hello, Alice!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 org.springframework.boot.docs.features.testing.springbootapplications.springgraphqltests;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.docs.web.graphql.runtimewiring.GreetingController;
|
||||
import org.springframework.boot.test.autoconfigure.graphql.GraphQlTest;
|
||||
import org.springframework.graphql.test.tester.GraphQlTester;
|
||||
|
||||
@GraphQlTest(GreetingController.class)
|
||||
class GreetingControllerTests {
|
||||
|
||||
@Autowired
|
||||
private GraphQlTester graphQlTester;
|
||||
|
||||
@Test
|
||||
void shouldGreetWithSpecificName() {
|
||||
this.graphQlTester.document("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String.class)
|
||||
.isEqualTo("Hello, Alice!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldGreetWithDefaultName() {
|
||||
this.graphQlTester.document("{ greeting } ").execute().path("greeting").entity(String.class)
|
||||
.isEqualTo("Hello, Spring!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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 org.springframework.boot.docs.web.graphql.runtimewiring;
|
||||
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class GreetingController {
|
||||
|
||||
@QueryMapping
|
||||
public String greeting(@Argument String name) {
|
||||
return "Hello, " + name + "!";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 org.springframework.boot.docs.web.graphql.transports.rsocket;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.client.RSocketGraphQlClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
// tag::builder[]
|
||||
@Component
|
||||
public class RSocketGraphQlClientExample {
|
||||
|
||||
private final RSocketGraphQlClient graphQlClient;
|
||||
|
||||
public RSocketGraphQlClientExample(RSocketGraphQlClient.Builder<?> builder) {
|
||||
this.graphQlClient = builder.tcp("example.spring.io", 8181).route("graphql").build();
|
||||
}
|
||||
// end::builder[]
|
||||
|
||||
public void rsocketOverTcp() {
|
||||
// tag::request[]
|
||||
Mono<Book> book = this.graphQlClient.document("{ bookById(id: \"book-1\"){ id name pageCount author } }")
|
||||
.retrieve("bookById").toEntity(Book.class);
|
||||
// end::request[]
|
||||
book.block(Duration.ofSeconds(5));
|
||||
}
|
||||
|
||||
static class Book {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 org.springframework.boot.docs.features.testing.springbootapplications.springgraphqltests
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
|
||||
@AutoConfigureHttpGraphQlTester
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||
class GraphQlIntegrationTests {
|
||||
|
||||
@Test
|
||||
fun shouldGreetWithSpecificName(@Autowired graphQlTester: HttpGraphQlTester) {
|
||||
val authenticatedTester = graphQlTester.mutate()
|
||||
.webTestClient { client: WebTestClient.Builder ->
|
||||
client.defaultHeaders { headers: HttpHeaders ->
|
||||
headers.setBasicAuth("admin", "ilovespring")
|
||||
}
|
||||
}.build()
|
||||
authenticatedTester.document("{ greeting(name: \"Alice\") } ").execute()
|
||||
.path("greeting").entity(String::class.java).isEqualTo("Hello, Alice!")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 org.springframework.boot.docs.features.testing.springbootapplications.springgraphqltests
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.docs.web.graphql.runtimewiring.GreetingController
|
||||
import org.springframework.boot.test.autoconfigure.graphql.GraphQlTest
|
||||
import org.springframework.graphql.test.tester.GraphQlTester
|
||||
|
||||
@GraphQlTest(GreetingController::class)
|
||||
internal class GreetingControllerTests {
|
||||
|
||||
@Autowired
|
||||
lateinit var graphQlTester: GraphQlTester
|
||||
|
||||
@Test
|
||||
fun shouldGreetWithSpecificName() {
|
||||
graphQlTester.document("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String::class.java)
|
||||
.isEqualTo("Hello, Alice!")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldGreetWithDefaultName() {
|
||||
graphQlTester.document("{ greeting } ").execute().path("greeting").entity(String::class.java)
|
||||
.isEqualTo("Hello, Spring!")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 org.springframework.boot.docs.web.graphql.runtimewiring;
|
||||
|
||||
import org.springframework.graphql.data.method.annotation.Argument
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping
|
||||
import org.springframework.stereotype.Controller
|
||||
|
||||
@Controller
|
||||
class GreetingController {
|
||||
|
||||
@QueryMapping
|
||||
fun greeting(@Argument name: String): String {
|
||||
return "Hello, $name!"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 org.springframework.boot.docs.web.graphql.transports.rsocket
|
||||
|
||||
import org.springframework.graphql.client.RSocketGraphQlClient
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.Duration
|
||||
|
||||
// tag::builder[]
|
||||
@Component
|
||||
class RSocketGraphQlClientExample(private val builder: RSocketGraphQlClient.Builder<*>) {
|
||||
// end::builder[]
|
||||
|
||||
val graphQlClient = builder.tcp("example.spring.io", 8181)
|
||||
.route("graphql")
|
||||
.build()
|
||||
|
||||
fun rsocketOverTcp() {
|
||||
// tag::request[]
|
||||
val book = graphQlClient.document(
|
||||
"""
|
||||
{
|
||||
bookById(id: "book-1"){
|
||||
id
|
||||
name
|
||||
pageCount
|
||||
author
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
.retrieve("bookById").toEntity(Book::class.java)
|
||||
// end::request[]
|
||||
book.block(Duration.ofSeconds(5))
|
||||
}
|
||||
|
||||
internal class Book
|
||||
}
|
||||
Reference in New Issue
Block a user