Skip to content

Commit

Permalink
Test query with a large response to check if direct serialization of …
Browse files Browse the repository at this point in the history
…response to Servlet's output stream improves performance
  • Loading branch information
Shailender Bathula committed Nov 11, 2019
1 parent 5961b8d commit fd1bf6d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
54 changes: 50 additions & 4 deletions servlet-hello-world/src/main/java/hello/HelloServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}

}

0 comments on commit fd1bf6d

Please sign in to comment.