Skip to content

Commit d9d67c7

Browse files
committed
Pagination support for Querydsl and QBE
See gh-597
1 parent 2d071a4 commit d9d67c7

File tree

8 files changed

+626
-66
lines changed

8 files changed

+626
-66
lines changed

platform/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies {
1212
api(platform("io.projectreactor:reactor-bom:2022.0.5"))
1313
api(platform("io.micrometer:micrometer-bom:1.11.0-M2"))
1414
api(platform("io.micrometer:micrometer-tracing-bom:1.1.0-M2"))
15-
api(platform("org.springframework.data:spring-data-bom:2023.0.0-M3"))
15+
api(platform("org.springframework.data:spring-data-bom:2023.0.0-SNAPSHOT"))
1616
api(platform("org.springframework.security:spring-security-bom:6.1.0-M2"))
1717
api(platform("com.querydsl:querydsl-bom:5.0.0"))
1818
api(platform("io.rsocket:rsocket-bom:1.1.3"))

spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationRuntimeWiringConfigurer.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import graphql.schema.GraphQLList;
2525
import graphql.schema.GraphQLNamedOutputType;
2626
import graphql.schema.GraphQLNonNull;
27+
import graphql.schema.GraphQLObjectType;
2728
import graphql.schema.GraphQLType;
2829
import graphql.schema.idl.FieldWiringEnvironment;
2930
import graphql.schema.idl.RuntimeWiring;
@@ -76,15 +77,20 @@ public void configure(RuntimeWiring.Builder builder, List<WiringFactory> contain
7677
interface DataFetcherFactory {
7778

7879
/**
79-
* Create a singe item {@code DataFetcher}.
80+
* Create {@code DataFetcher} for a singe item.
8081
*/
8182
DataFetcher<?> single();
8283

8384
/**
84-
* Create {@code DataFetcher} for multiple items.
85+
* Create {@code DataFetcher} for many items.
8586
*/
8687
DataFetcher<?> many();
8788

89+
/**
90+
* Create {@code DataFetcher} for scrolling.
91+
*/
92+
DataFetcher<?> scrollable();
93+
8894
}
8995

9096

@@ -127,6 +133,11 @@ public boolean providesDataFetcher(FieldWiringEnvironment environment) {
127133
private String getOutputTypeName(FieldWiringEnvironment environment) {
128134
GraphQLType outputType = removeNonNullWrapper(environment.getFieldType());
129135

136+
if (isConnectionType(outputType)) {
137+
String name = ((GraphQLObjectType) outputType).getName();
138+
return name.substring(0, name.length() - 10);
139+
}
140+
130141
if (outputType instanceof GraphQLList) {
131142
outputType = removeNonNullWrapper(((GraphQLList) outputType).getWrappedType());
132143
}
@@ -142,6 +153,12 @@ private GraphQLType removeNonNullWrapper(GraphQLType outputType) {
142153
return (outputType instanceof GraphQLNonNull wrapper ? wrapper.getWrappedType() : outputType);
143154
}
144155

156+
private boolean isConnectionType(GraphQLType type) {
157+
return (type instanceof GraphQLObjectType objectType &&
158+
objectType.getName().endsWith("Connection") &&
159+
objectType.getField("edges") != null && objectType.getField("pageInfo") != null);
160+
}
161+
145162
private boolean hasDataFetcherFor(FieldDefinition fieldDefinition) {
146163
if (this.existingQueryDataFetcherPredicate == null) {
147164
Map<String, ?> map = this.builder.build().getDataFetcherForType("Query");
@@ -168,13 +185,9 @@ public DataFetcher<?> getDataFetcher(FieldWiringEnvironment environment) {
168185
DataFetcherFactory factory = dataFetcherFactories.get(outputTypeName);
169186
Assert.notNull(factory, "Expected DataFetcher factory for typeName '" + outputTypeName + "'");
170187

171-
GraphQLType outputType = removeNonNullWrapper(environment.getFieldType());
172-
if (outputType instanceof GraphQLList) {
173-
return factory.many();
174-
}
175-
else {
176-
return factory.single();
177-
}
188+
GraphQLType type = removeNonNullWrapper(environment.getFieldType());
189+
return (isConnectionType(type) ? factory.scrollable() :
190+
(type instanceof GraphQLList ? factory.many() : factory.single()));
178191
}
179192

180193
}

0 commit comments

Comments
 (0)