();
30 | reviews.add(new Review(1));
31 | reviews.add(new Review(5));
32 | reviews.add(new Review(4));
33 | reviews.add(new Review(3));
34 |
35 | return reviews;
36 | }
37 | }
--------------------------------------------------------------------------------
/reviews/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 |
4 | graphql:
5 | graphiql:
6 | mapping: /graphiql
7 | basePath: /
8 | enabled: true
9 | pageTitle: GraphiQL
10 | cdn:
11 | enabled: true
12 | version: latest
13 |
--------------------------------------------------------------------------------
/reviews/src/main/resources/schema/schema.graphqls:
--------------------------------------------------------------------------------
1 | type Query
2 |
3 | type Show @key(fields: "id") @extends {
4 | id: ID @external
5 | reviews: [Review]
6 | }
7 |
8 | type Review {
9 | starRating: Int
10 | }
--------------------------------------------------------------------------------
/shows/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 3.3.0
9 |
10 |
11 | shows
12 |
13 | shows
14 |
15 |
16 | 12.0.0
17 |
18 | 17.3
19 |
20 | 2.3.1
21 |
22 |
23 |
24 |
25 | com.apollographql.federation
26 | federation-graphql-java-support
27 | ${federation-graphql-java-support.version}
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-web
32 |
33 |
34 | com.graphql-java-kickstart
35 | graphql-spring-boot-starter
36 | ${graphql-java-kickstart.version}
37 |
38 |
39 | org.projectlombok
40 | lombok
41 |
42 |
43 |
44 |
45 | com.graphql-java-kickstart
46 | graphql-spring-boot-starter-test
47 | ${graphql-java-kickstart.version}
48 | test
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/shows/src/main/java/com/example/demo/ShowsApp.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ShowsApp {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ShowsApp.class, args);
11 | }
12 | }
--------------------------------------------------------------------------------
/shows/src/main/java/com/example/demo/federation/FederatedSchema.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.federation;
2 |
3 | import com.apollographql.federation.graphqljava.Federation;
4 | import com.apollographql.federation.graphqljava._Entity;
5 | import graphql.kickstart.tools.SchemaParser;
6 | import graphql.schema.GraphQLSchema;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.stream.Collectors;
10 | import org.springframework.context.annotation.Bean;
11 | import org.springframework.stereotype.Component;
12 |
13 |
14 | @Component
15 | public class FederatedSchema {
16 |
17 | /**
18 | * This transformation is not necessary when using Apollo Gateway with Managed Federation. When using Apollo Gateway
19 | * with an explicit `serviceList` (see apollo-gateway/index.js) it was complaining with the following"
20 | *
21 | * Error checking for changes to service definitions: Couldn't load service definitions for "shows" at
22 | * http://localhost:8080/graphql: Validation error of type FieldUndefined: Field '_service' in type 'Query' is
23 | * undefined @ '_service'
24 | */
25 |
26 | @Bean
27 | public GraphQLSchema customSchema(SchemaParser schemaParser) {
28 | GraphQLSchema federatedSchema = Federation.transform(schemaParser.makeExecutableSchema())
29 | .fetchEntities(env -> env.>>getArgument(_Entity.argumentName)
30 | .stream()
31 | .map(reference -> {
32 | return null;
33 | })
34 | .collect(Collectors.toList()))
35 | .resolveEntityType(env -> {
36 | return null;
37 | })
38 | .build();
39 |
40 | return federatedSchema;
41 | }
42 | }
43 |
44 |
45 |
--------------------------------------------------------------------------------
/shows/src/main/java/com/example/demo/model/Show.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | @Data
7 | @AllArgsConstructor
8 | public class Show {
9 |
10 | private String id;
11 | private String title;
12 | private int releaseYear;
13 | }
14 |
--------------------------------------------------------------------------------
/shows/src/main/java/com/example/demo/query/ShowsQueryResolver.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.query;
2 |
3 | import com.example.demo.model.Show;
4 | import com.example.demo.services.ShowsService;
5 | import graphql.kickstart.tools.GraphQLQueryResolver;
6 | import java.util.List;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Component;
9 |
10 |
11 | @Component
12 | public class ShowsQueryResolver implements GraphQLQueryResolver {
13 |
14 | @Autowired
15 | ShowsService showService;
16 |
17 | public List getShows() {
18 | return showService.getShows();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/shows/src/main/java/com/example/demo/services/ShowsService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Netflix, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.demo.services;
18 |
19 | import com.example.demo.model.Show;
20 | import java.util.Arrays;
21 | import java.util.List;
22 | import org.springframework.stereotype.Service;
23 |
24 | @Service
25 | public class ShowsService {
26 |
27 | public List getShows() {
28 | return Arrays.asList(new Show("1", "Stranger Things", 2016), new Show("2", "Ozark", 2017),
29 | new Show("3", "The Crown", 2016), new Show("4", "Dead to Me", 2019),
30 | new Show("5", "Orange is the New Black", 2013));
31 | }
32 | }
--------------------------------------------------------------------------------
/shows/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8080
3 |
4 | graphql:
5 | graphiql:
6 | mapping: /graphiql
7 | basePath: /
8 | enabled: true
9 | pageTitle: GraphiQL
10 | cdn:
11 | enabled: true
12 | version: latest
13 |
--------------------------------------------------------------------------------
/shows/src/main/resources/schema/schema.graphqls:
--------------------------------------------------------------------------------
1 | type Query {
2 | shows: [Show]
3 | }
4 |
5 | type Show @key(fields: "id") {
6 | id: ID
7 | title: String
8 | releaseYear: Int
9 | }
--------------------------------------------------------------------------------