Document GraalVM Native support
This commit documents the GraalVM Native image support in Spring for GraphQL and lists relevant pointers to the Spring Framework and Spring Boot documentations. This also explains how developers are expected to provide reachability hints for the cases where the AOT processing is not able to discover the relevant types. Closes gh-581
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2020-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.graphql.docs.graalvm.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Project(String slug, String name, List<Releases> releases) {
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2020-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.graphql.docs.graalvm.client;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
|
||||
import org.springframework.graphql.client.GraphQlClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RegisterReflectionForBinding(Project.class) // <2>
|
||||
public class ProjectService {
|
||||
|
||||
private final GraphQlClient graphQlClient;
|
||||
|
||||
public ProjectService(GraphQlClient graphQlClient) {
|
||||
this.graphQlClient = graphQlClient;
|
||||
}
|
||||
|
||||
public Mono<Project> project(String projectSlug) {
|
||||
String document = """
|
||||
query projectWithReleases($projectSlug: ID!) {
|
||||
project(slug: $projectSlug) {
|
||||
name
|
||||
releases {
|
||||
version
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
return this.graphQlClient.document(document)
|
||||
.variable("projectSlug", projectSlug)
|
||||
.retrieve("project")
|
||||
.toEntity(Project.class); // <1>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2020-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.graphql.docs.graalvm.client;
|
||||
|
||||
public record Releases(String version) {
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2020-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.graphql.docs.graalvm.server;
|
||||
|
||||
public class Book {
|
||||
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
|
||||
Long authorId;
|
||||
|
||||
public Book() {
|
||||
}
|
||||
|
||||
public Book(Long id, String name, Long authorId) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.authorId = authorId;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2020-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.graphql.docs.graalvm.server;
|
||||
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.graphql.data.GraphQlRepository;
|
||||
|
||||
@GraphQlRepository
|
||||
public interface BookRepository extends CrudRepository<Book, Long>, QuerydslPredicateExecutor<Book> {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2020-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.graphql.docs.graalvm.server;
|
||||
|
||||
import graphql.schema.DataFetcher;
|
||||
|
||||
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.graphql.data.query.QuerydslDataFetcher;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
|
||||
@Configuration
|
||||
@RegisterReflectionForBinding(Book.class) // <3>
|
||||
public class GraphQlConfiguration {
|
||||
|
||||
@Bean
|
||||
RuntimeWiringConfigurer customWiringConfigurer(BookRepository bookRepository) { // <1>
|
||||
DataFetcher dataFetcher = QuerydslDataFetcher.builder(bookRepository).single();
|
||||
return wiringBuilder -> wiringBuilder
|
||||
.type("Query", builder -> builder.dataFetcher("book", dataFetcher)); // <2>
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user