19
19
import java .util .Collections ;
20
20
import java .util .Locale ;
21
21
import java .util .Map ;
22
+ import java .util .Objects ;
23
+ import java .util .UUID ;
22
24
23
25
import org .springframework .beans .factory .BeanFactory ;
24
26
import org .springframework .expression .Expression ;
31
33
import org .springframework .integration .handler .AbstractReplyProducingMessageHandler ;
32
34
import org .springframework .lang .Nullable ;
33
35
import org .springframework .messaging .Message ;
36
+ import org .springframework .messaging .MessageHeaders ;
34
37
import org .springframework .util .Assert ;
35
38
36
39
/**
@@ -54,7 +57,7 @@ public class GraphQlMessageHandler extends AbstractReplyProducingMessageHandler
54
57
@ Nullable
55
58
private Locale locale ;
56
59
57
- private String executionId = null ;
60
+ private Expression idExpression = new SupplierExpression <>(() -> null ) ;
58
61
59
62
public GraphQlMessageHandler (final GraphQlService graphQlService ) {
60
63
Assert .notNull (graphQlService , "'graphQlService' must not be null" );
@@ -116,12 +119,12 @@ public void setLocale(@Nullable Locale locale) {
116
119
}
117
120
118
121
/**
119
- * Set a Execution Id for GraphQL Operation to execute.
120
- * @param executionId the executionId to use.
122
+ * Set a SpEL expression to evaluate Id for GraphQL Operation Request to execute.
123
+ * @param idExpression the idExpression to use.
121
124
*/
122
- public void setExecutionId ( String executionId ) {
123
- Assert .hasText ( executionId , "'executionId ' must not be empty " );
124
- this .executionId = executionId ;
125
+ public void setIdExpression ( Expression idExpression ) {
126
+ Assert .notNull ( idExpression , "'idExpression ' must not be null " );
127
+ this .idExpression = idExpression ;
125
128
}
126
129
127
130
@ Override
@@ -140,11 +143,12 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
140
143
}
141
144
else {
142
145
Assert .notNull (this .operationExpression , "'operationExpression' must not be null" );
143
- // Assert.hasText (this.executionId , "'executionId ' must not be empty ");
146
+ Assert .notNull (this .idExpression , "'idExpression ' must not be null " );
144
147
String query = evaluateOperationExpression (requestMessage );
145
148
String operationName = evaluateOperationNameExpression (requestMessage );
146
149
Map <String , Object > variables = evaluateVariablesExpression (requestMessage );
147
- requestInput = new RequestInput (query , operationName , variables , this .locale , this .executionId );
150
+ String id = evaluateIdExpression (requestMessage );
151
+ requestInput = new RequestInput (query , operationName , variables , this .locale , id );
148
152
}
149
153
150
154
return this .graphQlService
@@ -167,4 +171,13 @@ private Map<String, Object> evaluateVariablesExpression(Message<?> message) {
167
171
return this .variablesExpression .getValue (this .evaluationContext , message , Map .class );
168
172
}
169
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 ;
181
+ }
182
+
170
183
}
0 commit comments