Support for annotated DataFetcher's

Closes gh-61, gh-90
This commit is contained in:
Rossen Stoyanchev
2021-08-04 16:35:57 +01:00
parent c2a996e564
commit 0d0b84dc8a
41 changed files with 2783 additions and 217 deletions

View File

@@ -0,0 +1,54 @@
/*
* 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 reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.graphql.data.method.annotation.GraphQlController;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
@GraphQlController
public class SampleController {
private final DataRepository repository;
public SampleController(DataRepository dataRepository) {
this.repository = dataRepository;
}
@QueryMapping
public String greeting() {
return this.repository.getBasic();
}
@QueryMapping
public Mono<String> greetingMono() {
return this.repository.getGreeting();
}
@QueryMapping
public Flux<String> greetingsFlux() {
return this.repository.getGreetings();
}
@SubscriptionMapping
public Flux<String> greetings() {
return this.repository.getGreetingsStream();
}
}

View File

@@ -1,41 +0,0 @@
/*
* 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.schema.idl.RuntimeWiring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.boot.RuntimeWiringBuilderCustomizer;
import org.springframework.stereotype.Component;
@Component
public class SampleWiring implements RuntimeWiringBuilderCustomizer {
private final DataRepository repository;
public SampleWiring(@Autowired DataRepository dataRepository) {
this.repository = dataRepository;
}
@Override
public void customize(RuntimeWiring.Builder wiringBuilder) {
wiringBuilder.type("Query", builder -> builder.dataFetcher("greeting", env -> this.repository.getBasic()));
wiringBuilder.type("Query", builder -> builder.dataFetcher("greetingMono", env -> this.repository.getGreeting()));
wiringBuilder.type("Query", builder -> builder.dataFetcher("greetingsFlux", env -> this.repository.getGreetings()));
wiringBuilder.type("Subscription", builder -> builder.dataFetcher("greetings", env -> this.repository.getGreetingsStream()));
}
}