Skip to content

Commit 0159315

Browse files
Use java.util.List for GQL lists (#186)
1 parent 1a21c02 commit 0159315

File tree

46 files changed

+153
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+153
-155
lines changed

plugins/gradle/example-client/src/main/java/io/github/kobylynskyi/order/external/ProductServiceGraphQLClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import java.math.BigDecimal;
2727
import java.net.URI;
28-
import java.util.Collection;
2928
import java.util.Collections;
3029
import java.util.List;
3130
import java.util.stream.Collectors;
@@ -61,7 +60,7 @@ public Product getProduct(String productId) throws UnableToRetrieveProductExcept
6160
return productMapper.map(result.productById());
6261
}
6362

64-
public List<Product> getProducts(Collection<String> productIds) throws UnableToRetrieveProductsException {
63+
public List<Product> getProducts(List<String> productIds) throws UnableToRetrieveProductsException {
6564
ProductsByIdsQueryRequest getProductRequest = new ProductsByIdsQueryRequest();
6665
getProductRequest.setIds(productIds);
6766
ProductResponseProjection responseProjection = new ProductResponseProjection()

plugins/gradle/example-client/src/main/java/io/github/kobylynskyi/order/graphql/resolvers/QueriesResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.stereotype.Component;
1212

13-
import java.util.Collection;
13+
import java.util.List;
1414

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

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

2525
@Override
26-
public Collection<OrderTO> orders() {
26+
public List<OrderTO> orders() {
2727
return service.getOrders().stream().map(mapper::map).collect(toList());
2828
}
2929

plugins/gradle/example-server/src/main/java/io/github/kobylynskyi/product/graphql/resolvers/QueriesResolver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.stereotype.Component;
1111

12-
import java.util.Collection;
12+
import java.util.List;
1313

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

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

2424
@Override
25-
public Collection<ProductTO> products() {
25+
public List<ProductTO> products() {
2626
return service.findAll().stream().map(mapper::map).collect(toList());
2727
}
2828

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

3434
@Override
35-
public Collection<ProductTO> productsByIds(Collection<String> ids) {
35+
public List<ProductTO> productsByIds(List<String> ids) {
3636
return service.findByIds(ids).stream().map(mapper::map).collect(toList());
3737
}
3838
}

plugins/maven/example-client/src/main/java/io/github/kobylynskyi/order/external/ProductServiceGraphQLClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import java.math.BigDecimal;
2727
import java.net.URI;
28-
import java.util.Collection;
2928
import java.util.Collections;
3029
import java.util.List;
3130
import java.util.stream.Collectors;
@@ -61,7 +60,7 @@ public Product getProduct(String productId) throws UnableToRetrieveProductExcept
6160
return productMapper.map(result.productById());
6261
}
6362

64-
public List<Product> getProducts(Collection<String> productIds) throws UnableToRetrieveProductsException {
63+
public List<Product> getProducts(List<String> productIds) throws UnableToRetrieveProductsException {
6564
ProductsByIdsQueryRequest getProductRequest = new ProductsByIdsQueryRequest();
6665
getProductRequest.setIds(productIds);
6766
ProductResponseProjection responseProjection = new ProductResponseProjection()

plugins/maven/example-client/src/main/java/io/github/kobylynskyi/order/graphql/resolvers/QueriesResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.stereotype.Component;
1212

13-
import java.util.Collection;
13+
import java.util.List;
1414

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

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

2525
@Override
26-
public Collection<OrderTO> orders() {
26+
public List<OrderTO> orders() {
2727
return service.getOrders().stream().map(mapper::map).collect(toList());
2828
}
2929

plugins/maven/example-server/src/main/java/io/github/kobylynskyi/product/graphql/resolvers/QueriesResolver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.stereotype.Component;
1111

12-
import java.util.Collection;
12+
import java.util.List;
1313

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

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

2424
@Override
25-
public Collection<ProductTO> products() {
25+
public List<ProductTO> products() {
2626
return service.findAll().stream().map(mapper::map).collect(toList());
2727
}
2828

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

3434
@Override
35-
public Collection<ProductTO> productsByIds(Collection<String> ids) {
35+
public List<ProductTO> productsByIds(List<String> ids) {
3636
return service.findByIds(ids).stream().map(mapper::map).collect(toList());
3737
}
3838
}

src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ static NamedDefinition getJavaType(MappingContext mappingContext, Type graphqlTy
5151
} else if (graphqlType instanceof ListType) {
5252
NamedDefinition mappedCollectionType = getJavaType(mappingContext, ((ListType) graphqlType).getType(), name, parentTypeName);
5353
if (mappedCollectionType.isInterface() && mappingContext.getInterfaceNames().contains(parentTypeName)) {
54-
mappedCollectionType.setName(wrapSuperTypeIntoJavaCollection(mappedCollectionType.getName()));
54+
mappedCollectionType.setName(wrapSuperTypeIntoJavaList(mappedCollectionType.getName()));
5555
} else {
56-
mappedCollectionType.setName(wrapIntoJavaCollection(mappedCollectionType.getName()));
56+
mappedCollectionType.setName(wrapIntoJavaList(mappedCollectionType.getName()));
5757
}
5858
return mappedCollectionType;
5959
} else if (graphqlType instanceof NonNullType) {
@@ -145,24 +145,24 @@ private static List<String> getAnnotations(MappingContext mappingContext, String
145145
}
146146

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

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

168168
/**

src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void generate_CustomSubscriptionReturnType() throws Exception {
179179
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
180180

181181
assertFileContainsElements(files, "EventsCreatedSubscriptionResolver.java",
182-
"org.reactivestreams.Publisher<java.util.Collection<Event>> eventsCreated() throws Exception;");
182+
"org.reactivestreams.Publisher<java.util.List<Event>> eventsCreated() throws Exception;");
183183
}
184184

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

347347
assertFileContainsElements(files, "EventsByCategoryAndStatusQueryResolver.java",
348-
"java.util.concurrent.CompletableFuture<java.util.Collection<Event>> eventsByCategoryAndStatus(");
348+
"java.util.concurrent.CompletableFuture<java.util.List<Event>> eventsByCategoryAndStatus(");
349349

350350
assertFileContainsElements(files, "EventByIdQueryResolver.java",
351351
"java.util.concurrent.CompletableFuture<Event> eventById(");

src/test/resources/expected-classes/CommitResolver.java.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface CommitResolver {
1515
@javax.validation.constraints.NotNull
1616
CommitCommentConnection comments(Commit commit, String after, String before, Integer first, Integer last, graphql.schema.DataFetchingEnvironment env) throws Exception;
1717

18-
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;
18+
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;
1919

2020
@javax.validation.constraints.NotNull
2121
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;

src/test/resources/expected-classes/Event.java.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Event implements java.io.Serializable {
88

99
private String id;
1010
private String categoryId;
11-
private java.util.Collection<EventProperty> properties;
11+
private java.util.List<EventProperty> properties;
1212
private EventStatus status;
1313
private String createdBy;
1414
private String createdDateTime;
@@ -18,7 +18,7 @@ public class Event implements java.io.Serializable {
1818
public Event() {
1919
}
2020

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

46-
public java.util.Collection<EventProperty> getProperties() {
46+
public java.util.List<EventProperty> getProperties() {
4747
return properties;
4848
}
49-
public void setProperties(java.util.Collection<EventProperty> properties) {
49+
public void setProperties(java.util.List<EventProperty> properties) {
5050
this.properties = properties;
5151
}
5252

@@ -95,7 +95,7 @@ public class Event implements java.io.Serializable {
9595

9696
private String id;
9797
private String categoryId;
98-
private java.util.Collection<EventProperty> properties;
98+
private java.util.List<EventProperty> properties;
9999
private EventStatus status;
100100
private String createdBy;
101101
private String createdDateTime;
@@ -115,7 +115,7 @@ public class Event implements java.io.Serializable {
115115
return this;
116116
}
117117

118-
public Builder setProperties(java.util.Collection<EventProperty> properties) {
118+
public Builder setProperties(java.util.List<EventProperty> properties) {
119119
this.properties = properties;
120120
return this;
121121
}

0 commit comments

Comments
 (0)