20
20
import java .util .Locale ;
21
21
import java .util .Map ;
22
22
import java .util .Objects ;
23
- import java .util .UUID ;
24
23
25
24
import org .springframework .beans .factory .BeanFactory ;
26
25
import org .springframework .expression .Expression ;
29
28
import org .springframework .graphql .GraphQlService ;
30
29
import org .springframework .graphql .RequestInput ;
31
30
import org .springframework .integration .expression .ExpressionUtils ;
31
+ import org .springframework .integration .expression .FunctionExpression ;
32
32
import org .springframework .integration .expression .SupplierExpression ;
33
33
import org .springframework .integration .handler .AbstractReplyProducingMessageHandler ;
34
34
import org .springframework .lang .Nullable ;
@@ -57,7 +57,7 @@ public class GraphQlMessageHandler extends AbstractReplyProducingMessageHandler
57
57
@ Nullable
58
58
private Locale locale ;
59
59
60
- private Expression idExpression = new SupplierExpression <>(() -> null );
60
+ private Expression executionIdExpression = new FunctionExpression < Message <?>>( message -> message . getHeaders (). getId () );
61
61
62
62
public GraphQlMessageHandler (final GraphQlService graphQlService ) {
63
63
Assert .notNull (graphQlService , "'graphQlService' must not be null" );
@@ -119,12 +119,12 @@ public void setLocale(@Nullable Locale locale) {
119
119
}
120
120
121
121
/**
122
- * Set a SpEL expression to evaluate Id for GraphQL Operation Request to execute.
123
- * @param idExpression the idExpression to use.
122
+ * Set a SpEL expression to evaluate Execution Id for GraphQL Operation Request to execute.
123
+ * @param executionIdExpression the executionIdExpression to use.
124
124
*/
125
- public void setIdExpression (Expression idExpression ) {
126
- Assert .notNull (idExpression , "'idExpression ' must not be null" );
127
- this .idExpression = idExpression ;
125
+ public void setIdExpression (Expression executionIdExpression ) {
126
+ Assert .notNull (executionIdExpression , "'executionIdExpression ' must not be null" );
127
+ this .executionIdExpression = executionIdExpression ;
128
128
}
129
129
130
130
@ Override
@@ -143,11 +143,11 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
143
143
}
144
144
else {
145
145
Assert .notNull (this .operationExpression , "'operationExpression' must not be null" );
146
- Assert .notNull (this .idExpression , "'idExpression ' must not be null" );
146
+ Assert .notNull (this .executionIdExpression , "'executionIdExpression ' must not be null" );
147
147
String query = evaluateOperationExpression (requestMessage );
148
148
String operationName = evaluateOperationNameExpression (requestMessage );
149
149
Map <String , Object > variables = evaluateVariablesExpression (requestMessage );
150
- String id = evaluateIdExpression (requestMessage );
150
+ String id = evaluateExecutionIdExpression (requestMessage );
151
151
requestInput = new RequestInput (query , operationName , variables , this .locale , id );
152
152
}
153
153
@@ -171,13 +171,8 @@ private Map<String, Object> evaluateVariablesExpression(Message<?> message) {
171
171
return this .variablesExpression .getValue (this .evaluationContext , message , Map .class );
172
172
}
173
173
174
- private String evaluateIdExpression (Message <?> message ) {
175
- String id = this .idExpression .getValue (this .evaluationContext , message , String .class );
176
- if (id == null ) {
177
- return Objects .requireNonNull (message .getHeaders ().get (MessageHeaders .ID )).toString ();
178
- }
179
-
180
- return id ;
174
+ private String evaluateExecutionIdExpression (Message <?> message ) {
175
+ return this .executionIdExpression .getValue (this .evaluationContext , message , String .class );
181
176
}
182
177
183
178
}
0 commit comments