Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use java.util.List for GQL lists #186

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.math.BigDecimal;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -61,7 +60,7 @@ public Product getProduct(String productId) throws UnableToRetrieveProductExcept
return productMapper.map(result.productById());
}

public List<Product> getProducts(Collection<String> productIds) throws UnableToRetrieveProductsException {
public List<Product> getProducts(List<String> productIds) throws UnableToRetrieveProductsException {
ProductsByIdsQueryRequest getProductRequest = new ProductsByIdsQueryRequest();
getProductRequest.setIds(productIds);
ProductResponseProjection responseProjection = new ProductResponseProjection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

import static java.util.stream.Collectors.toList;

Expand All @@ -23,7 +23,7 @@ public class QueriesResolver implements OrdersQueryResolver, OrderByIdQueryResol
private OrderMapper mapper;

@Override
public Collection<OrderTO> orders() {
public List<OrderTO> orders() {
return service.getOrders().stream().map(mapper::map).collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

import static java.util.stream.Collectors.toList;

Expand All @@ -22,7 +22,7 @@ public class QueriesResolver implements ProductsQueryResolver, ProductsByIdsQuer
private ProductMapper mapper;

@Override
public Collection<ProductTO> products() {
public List<ProductTO> products() {
return service.findAll().stream().map(mapper::map).collect(toList());
}

Expand All @@ -32,7 +32,7 @@ public ProductTO productById(String id) throws Exception {
}

@Override
public Collection<ProductTO> productsByIds(Collection<String> ids) {
public List<ProductTO> productsByIds(List<String> ids) {
return service.findByIds(ids).stream().map(mapper::map).collect(toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.math.BigDecimal;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -61,7 +60,7 @@ public Product getProduct(String productId) throws UnableToRetrieveProductExcept
return productMapper.map(result.productById());
}

public List<Product> getProducts(Collection<String> productIds) throws UnableToRetrieveProductsException {
public List<Product> getProducts(List<String> productIds) throws UnableToRetrieveProductsException {
ProductsByIdsQueryRequest getProductRequest = new ProductsByIdsQueryRequest();
getProductRequest.setIds(productIds);
ProductResponseProjection responseProjection = new ProductResponseProjection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

import static java.util.stream.Collectors.toList;

Expand All @@ -23,7 +23,7 @@ public class QueriesResolver implements OrdersQueryResolver, OrderByIdQueryResol
private OrderMapper mapper;

@Override
public Collection<OrderTO> orders() {
public List<OrderTO> orders() {
return service.getOrders().stream().map(mapper::map).collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

import static java.util.stream.Collectors.toList;

Expand All @@ -22,7 +22,7 @@ public class QueriesResolver implements ProductsQueryResolver, ProductsByIdsQuer
private ProductMapper mapper;

@Override
public Collection<ProductTO> products() {
public List<ProductTO> products() {
return service.findAll().stream().map(mapper::map).collect(toList());
}

Expand All @@ -32,7 +32,7 @@ public ProductTO productById(String id) throws Exception {
}

@Override
public Collection<ProductTO> productsByIds(Collection<String> ids) {
public List<ProductTO> productsByIds(List<String> ids) {
return service.findByIds(ids).stream().map(mapper::map).collect(toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ static NamedDefinition getJavaType(MappingContext mappingContext, Type graphqlTy
} else if (graphqlType instanceof ListType) {
NamedDefinition mappedCollectionType = getJavaType(mappingContext, ((ListType) graphqlType).getType(), name, parentTypeName);
if (mappedCollectionType.isInterface() && mappingContext.getInterfaceNames().contains(parentTypeName)) {
mappedCollectionType.setName(wrapSuperTypeIntoJavaCollection(mappedCollectionType.getName()));
mappedCollectionType.setName(wrapSuperTypeIntoJavaList(mappedCollectionType.getName()));
} else {
mappedCollectionType.setName(wrapIntoJavaCollection(mappedCollectionType.getName()));
mappedCollectionType.setName(wrapIntoJavaList(mappedCollectionType.getName()));
}
return mappedCollectionType;
} else if (graphqlType instanceof NonNullType) {
Expand Down Expand Up @@ -145,24 +145,24 @@ private static List<String> getAnnotations(MappingContext mappingContext, String
}

/**
* Wrap java type into collection. E.g.: "String" becomes "Collection<String"
* Wrap Java type into {@link java.util.List}. E.g.: {@code "String"} becomes {@code "List<String>"}
*
* @param type Anything that will be wrapped into Collection<>
* @return String wrapped into Collection<>
* @param type The name of a type that will be wrapped into List<>
* @return String The name of the given type, wrapped into List<>
*/
private static String wrapIntoJavaCollection(String type) {
return String.format("java.util.Collection<%s>", type);
private static String wrapIntoJavaList(String type) {
return String.format("java.util.List<%s>", type);
}

/**
* Return upper bounded wildcard for the given interface type:
* <code>Foo</code> becomes <code>Collection<? extends Foo></code>
* {@code "Foo"} becomes {@code "List<? extends Foo>"}.
*
* @param type Anything that will be wrapped into Collection<? extends @type>
* @return String wrapped into Collection<? extends @type>
* @param type The name of a type whose upper bound wildcard will be wrapped into a list.
* @return String The name of the the wrapped type.
*/
private static String wrapSuperTypeIntoJavaCollection(String type) {
return String.format("java.util.Collection<? extends %s>", type);
private static String wrapSuperTypeIntoJavaList(String type) {
return String.format("java.util.List<? extends %s>", type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void generate_CustomSubscriptionReturnType() throws Exception {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());

assertFileContainsElements(files, "EventsCreatedSubscriptionResolver.java",
"org.reactivestreams.Publisher<java.util.Collection<Event>> eventsCreated() throws Exception;");
"org.reactivestreams.Publisher<java.util.List<Event>> eventsCreated() throws Exception;");
}

@Test
Expand Down Expand Up @@ -345,7 +345,7 @@ void generate_AsyncQueryApis() throws Exception {
"java.util.concurrent.CompletableFuture<String> version()");

assertFileContainsElements(files, "EventsByCategoryAndStatusQueryResolver.java",
"java.util.concurrent.CompletableFuture<java.util.Collection<Event>> eventsByCategoryAndStatus(");
"java.util.concurrent.CompletableFuture<java.util.List<Event>> eventsByCategoryAndStatus(");

assertFileContainsElements(files, "EventByIdQueryResolver.java",
"java.util.concurrent.CompletableFuture<Event> eventById(");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface CommitResolver {
@javax.validation.constraints.NotNull
CommitCommentConnection comments(Commit commit, String after, String before, Integer first, Integer last, graphql.schema.DataFetchingEnvironment env) throws Exception;

DeploymentConnection deployments(Commit commit, String after, String before, java.util.Collection<String> environments, Integer first, Integer last, DeploymentOrder orderBy, graphql.schema.DataFetchingEnvironment env) throws Exception;
DeploymentConnection deployments(Commit commit, String after, String before, java.util.List<String> environments, Integer first, Integer last, DeploymentOrder orderBy, graphql.schema.DataFetchingEnvironment env) throws Exception;

@javax.validation.constraints.NotNull
CommitHistoryConnection history(Commit commit, String after, CommitAuthor author, String before, Integer first, Integer last, String path, String since, String until, graphql.schema.DataFetchingEnvironment env) throws Exception;
Expand Down
12 changes: 6 additions & 6 deletions src/test/resources/expected-classes/Event.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Event implements java.io.Serializable {

private String id;
private String categoryId;
private java.util.Collection<EventProperty> properties;
private java.util.List<EventProperty> properties;
private EventStatus status;
private String createdBy;
private String createdDateTime;
Expand All @@ -18,7 +18,7 @@ public class Event implements java.io.Serializable {
public Event() {
}

public Event(String id, String categoryId, java.util.Collection<EventProperty> properties, EventStatus status, String createdBy, String createdDateTime, Boolean active, Integer rating) {
public Event(String id, String categoryId, java.util.List<EventProperty> properties, EventStatus status, String createdBy, String createdDateTime, Boolean active, Integer rating) {
this.id = id;
this.categoryId = categoryId;
this.properties = properties;
Expand All @@ -43,10 +43,10 @@ public class Event implements java.io.Serializable {
this.categoryId = categoryId;
}

public java.util.Collection<EventProperty> getProperties() {
public java.util.List<EventProperty> getProperties() {
return properties;
}
public void setProperties(java.util.Collection<EventProperty> properties) {
public void setProperties(java.util.List<EventProperty> properties) {
this.properties = properties;
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public class Event implements java.io.Serializable {

private String id;
private String categoryId;
private java.util.Collection<EventProperty> properties;
private java.util.List<EventProperty> properties;
private EventStatus status;
private String createdBy;
private String createdDateTime;
Expand All @@ -115,7 +115,7 @@ public class Event implements java.io.Serializable {
return this;
}

public Builder setProperties(java.util.Collection<EventProperty> properties) {
public Builder setProperties(java.util.List<EventProperty> properties) {
this.properties = properties;
return this;
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/resources/expected-classes/EventProperty.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class EventProperty implements java.io.Serializable {
private Boolean booleanVal;
private Integer intVal;
private String stringVal;
private java.util.Collection<EventProperty> child;
private java.util.List<EventProperty> child;
private Event parent;

public EventProperty() {
}

public EventProperty(Double floatVal, Boolean booleanVal, Integer intVal, String stringVal, java.util.Collection<EventProperty> child, Event parent) {
public EventProperty(Double floatVal, Boolean booleanVal, Integer intVal, String stringVal, java.util.List<EventProperty> child, Event parent) {
this.floatVal = floatVal;
this.booleanVal = booleanVal;
this.intVal = intVal;
Expand Down Expand Up @@ -70,13 +70,13 @@ public class EventProperty implements java.io.Serializable {
/**
* Properties
*/
public java.util.Collection<EventProperty> getChild() {
public java.util.List<EventProperty> getChild() {
return child;
}
/**
* Properties
*/
public void setChild(java.util.Collection<EventProperty> child) {
public void setChild(java.util.List<EventProperty> child) {
this.child = child;
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public class EventProperty implements java.io.Serializable {
private Boolean booleanVal;
private Integer intVal;
private String stringVal;
private java.util.Collection<EventProperty> child;
private java.util.List<EventProperty> child;
private Event parent;

public Builder() {
Expand Down Expand Up @@ -141,7 +141,7 @@ public class EventProperty implements java.io.Serializable {
/**
* Properties
*/
public Builder setChild(java.util.Collection<EventProperty> child) {
public Builder setChild(java.util.List<EventProperty> child) {
this.child = child;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class EventPropertyTO implements java.io.Serializable {
private Boolean booleanVal;
private Integer intVal;
private String stringVal;
private java.util.Collection<EventPropertyTO> child;
private java.util.List<EventPropertyTO> child;
private EventTO parent;

public EventPropertyTO() {
}

public EventPropertyTO(Double floatVal, Boolean booleanVal, Integer intVal, String stringVal, java.util.Collection<EventPropertyTO> child, EventTO parent) {
public EventPropertyTO(Double floatVal, Boolean booleanVal, Integer intVal, String stringVal, java.util.List<EventPropertyTO> child, EventTO parent) {
this.floatVal = floatVal;
this.booleanVal = booleanVal;
this.intVal = intVal;
Expand Down Expand Up @@ -71,13 +71,13 @@ public class EventPropertyTO implements java.io.Serializable {
/**
* Properties
*/
public java.util.Collection<EventPropertyTO> getChild() {
public java.util.List<EventPropertyTO> getChild() {
return child;
}
/**
* Properties
*/
public void setChild(java.util.Collection<EventPropertyTO> child) {
public void setChild(java.util.List<EventPropertyTO> child) {
this.child = child;
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public class EventPropertyTO implements java.io.Serializable {
private Boolean booleanVal;
private Integer intVal;
private String stringVal;
private java.util.Collection<EventPropertyTO> child;
private java.util.List<EventPropertyTO> child;
private EventTO parent;

public Builder() {
Expand Down Expand Up @@ -165,7 +165,7 @@ public class EventPropertyTO implements java.io.Serializable {
/**
* Properties
*/
public Builder setChild(java.util.Collection<EventPropertyTO> child) {
public Builder setChild(java.util.List<EventPropertyTO> child) {
this.child = child;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class EventPropertyTO implements java.io.Serializable {
private Boolean booleanVal;
private Integer intVal;
private String stringVal;
private java.util.Collection<EventPropertyTO> child;
private java.util.List<EventPropertyTO> child;
private EventTO parent;

public EventPropertyTO() {
}

public EventPropertyTO(Double floatVal, Boolean booleanVal, Integer intVal, String stringVal, java.util.Collection<EventPropertyTO> child, EventTO parent) {
public EventPropertyTO(Double floatVal, Boolean booleanVal, Integer intVal, String stringVal, java.util.List<EventPropertyTO> child, EventTO parent) {
this.floatVal = floatVal;
this.booleanVal = booleanVal;
this.intVal = intVal;
Expand Down Expand Up @@ -71,13 +71,13 @@ public class EventPropertyTO implements java.io.Serializable {
/**
* Properties
*/
public java.util.Collection<EventPropertyTO> getChild() {
public java.util.List<EventPropertyTO> getChild() {
return child;
}
/**
* Properties
*/
public void setChild(java.util.Collection<EventPropertyTO> child) {
public void setChild(java.util.List<EventPropertyTO> child) {
this.child = child;
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public class EventPropertyTO implements java.io.Serializable {
private Boolean booleanVal;
private Integer intVal;
private String stringVal;
private java.util.Collection<EventPropertyTO> child;
private java.util.List<EventPropertyTO> child;
private EventTO parent;

public Builder() {
Expand Down Expand Up @@ -163,7 +163,7 @@ public class EventPropertyTO implements java.io.Serializable {
/**
* Properties
*/
public Builder setChild(java.util.Collection<EventPropertyTO> child) {
public Builder setChild(java.util.List<EventPropertyTO> child) {
this.child = child;
return this;
}
Expand Down
Loading