diff --git a/gradle.properties b/gradle.properties index 12989a6..5965f2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -LIB_GRAPHQL_SERVLET_VER = 7.5.0 -LIB_GRAPHQL_SPRING_BOOT_VER = 5.9.1-SNAPSHOT +LIB_GRAPHQL_SERVLET_VER = 8.0.1-SNAPSHOT +LIB_GRAPHQL_SPRING_BOOT_VER = 5.10.1-SNAPSHOT LIB_SPRING_BOOT_VER = 2.1.5.RELEASE sourceCompatibility=11 diff --git a/servlet-hello-world/src/main/java/hello/HelloServlet.java b/servlet-hello-world/src/main/java/hello/HelloServlet.java index 6b3b681..e1cab63 100644 --- a/servlet-hello-world/src/main/java/hello/HelloServlet.java +++ b/servlet-hello-world/src/main/java/hello/HelloServlet.java @@ -2,13 +2,15 @@ import static graphql.schema.idl.RuntimeWiring.newRuntimeWiring; +import java.util.Collections; + import graphql.schema.GraphQLSchema; import graphql.schema.StaticDataFetcher; import graphql.schema.idl.RuntimeWiring; import graphql.schema.idl.SchemaGenerator; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; -import graphql.servlet.GraphQLConfiguration; +import graphql.servlet.config.GraphQLConfiguration; import graphql.servlet.GraphQLHttpServlet; import javax.servlet.annotation.WebServlet; @@ -21,17 +23,61 @@ protected GraphQLConfiguration getConfiguration() { } private GraphQLSchema createSchema() { - String schema = "type Query{hello: String}"; + String schema = + "type Query{" + + "hello: String " + + "customers: [Customer!]! " + + "}" + + "type Customer {id: ID!, firstName: String!, lastName: String!, yearOfBirth: Int!, email: String!}"; SchemaParser schemaParser = new SchemaParser(); TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema); RuntimeWiring runtimeWiring = newRuntimeWiring() - .type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world"))) - .build(); + .type("Query", + builder -> builder + .dataFetcher("hello", new StaticDataFetcher("world")) + .dataFetcher("customers", new StaticDataFetcher(Collections.nCopies(5000, + new Customer("id", "firstName", "lastName", 1990, + "first.lastname@email.com"))))) + .build(); SchemaGenerator schemaGenerator = new SchemaGenerator(); return schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring); } + public static class Customer { + + private final String id; + private final String firstName; + private final String lastName; + private final int yearOfBirth; + private final String email; + + public Customer(String id, String firstName, String lastName, int yearOfBirth, + String email) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.yearOfBirth = yearOfBirth; + this.email = email; + } + + public String getId() { + return id; + } + public String getFirstName() { + return firstName; + } + public String getLastName() { + return lastName; + } + public int getYearOfBirth() { + return yearOfBirth; + } + public String getEmail() { + return email; + } + } + }