16
16
17
17
package org .springframework .graphql .server ;
18
18
19
+ import java .net .InetSocketAddress ;
19
20
import java .net .URI ;
20
21
import java .util .Collections ;
21
22
import java .util .Locale ;
@@ -58,8 +59,51 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements
58
59
59
60
private final MultiValueMap <String , HttpCookie > cookies ;
60
61
62
+ @ Nullable
63
+ private final InetSocketAddress remoteAddress ;
64
+
61
65
private final Map <String , Object > attributes ;
62
66
67
+ /**
68
+ * Create an instance.
69
+ * @param uri the URL for the HTTP request or WebSocket handshake
70
+ * @param headers the HTTP request headers
71
+ * @param cookies the HTTP request cookies
72
+ * @param remoteAddress the HTTP client remote address
73
+ * @param attributes request attributes
74
+ * @param body the deserialized content of the GraphQL request
75
+ * @param id an identifier for the GraphQL request
76
+ * @param locale the locale from the HTTP request, if any
77
+ * @since 1.3.0
78
+ */
79
+ public WebGraphQlRequest (URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
80
+ @ Nullable InetSocketAddress remoteAddress , Map <String , Object > attributes ,
81
+ GraphQlRequest body , String id , @ Nullable Locale locale ) {
82
+ this (uri , headers , cookies , remoteAddress , attributes , body .getDocument (),
83
+ body .getOperationName (), body .getVariables (), body .getExtensions (), id , locale );
84
+ }
85
+
86
+ /**
87
+ * Variant of {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, Map, GraphQlRequest, String, Locale)}
88
+ * with a Map for the request body.
89
+ * @param uri the URL for the HTTP request or WebSocket handshake
90
+ * @param headers the HTTP request headers
91
+ * @param cookies the HTTP request cookies
92
+ * @param remoteAddress the HTTP client remote address
93
+ * @param attributes request attributes
94
+ * @param body the deserialized content of the GraphQL request
95
+ * @param id an identifier for the GraphQL request
96
+ * @param locale the locale from the HTTP request, if any
97
+ * @since 1.3.0
98
+ */
99
+ public WebGraphQlRequest (
100
+ URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
101
+ @ Nullable InetSocketAddress remoteAddress , Map <String , Object > attributes ,
102
+ Map <String , Object > body , String id , @ Nullable Locale locale ) {
103
+
104
+ this (uri , headers , cookies , remoteAddress , attributes , getQuery (body ), getOperation (body ),
105
+ getMap (VARIABLES_KEY , body ), getMap (EXTENSIONS_KEY , body ), id , locale );
106
+ }
63
107
64
108
/**
65
109
* Create an instance.
@@ -71,12 +115,14 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements
71
115
* @param id an identifier for the GraphQL request
72
116
* @param locale the locale from the HTTP request, if any
73
117
* @since 1.2.5
118
+ * @deprecated since 1.3.0 in favor {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, InetSocketAddress, Map, Map, String, Locale)}
74
119
*/
120
+ @ Deprecated (since = "1.3.0" , forRemoval = true )
75
121
public WebGraphQlRequest (
76
122
URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
77
123
Map <String , Object > attributes , GraphQlRequest body , String id , @ Nullable Locale locale ) {
78
124
79
- this (uri , headers , cookies , attributes , body .getDocument (),
125
+ this (uri , headers , cookies , null , attributes , body .getDocument (),
80
126
body .getOperationName (), body .getVariables (), body .getExtensions (), id , locale );
81
127
}
82
128
@@ -91,12 +137,14 @@ public WebGraphQlRequest(
91
137
* @param id an identifier for the GraphQL request
92
138
* @param locale the locale from the HTTP request, if any
93
139
* @since 1.1.3
140
+ * @deprecated since 1.3.0 in favor {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, InetSocketAddress, Map, Map, String, Locale)}
94
141
*/
142
+ @ Deprecated (since = "1.3.0" , forRemoval = true )
95
143
public WebGraphQlRequest (
96
144
URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
97
145
Map <String , Object > attributes , Map <String , Object > body , String id , @ Nullable Locale locale ) {
98
146
99
- this (uri , headers , cookies , attributes , getQuery (body ), getOperation (body ),
147
+ this (uri , headers , cookies , null , attributes , getQuery (body ), getOperation (body ),
100
148
getMap (VARIABLES_KEY , body ), getMap (EXTENSIONS_KEY , body ), id , locale );
101
149
}
102
150
@@ -127,24 +175,10 @@ private static Map<String, Object> getMap(String key, Map<String, Object> body)
127
175
return (Map <String , Object >) value ;
128
176
}
129
177
130
- /**
131
- * Create an instance.
132
- * @param uri the URL for the HTTP request or WebSocket handshake
133
- * @param headers the HTTP request headers
134
- * @param body the deserialized content of the GraphQL request
135
- * @param id an identifier for the GraphQL request
136
- * @param locale the locale from the HTTP request, if any
137
- * @deprecated as of 1.1.3 in favor of
138
- * {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, Map, GraphQlRequest, String, Locale)}
139
- */
140
- @ Deprecated (since = "1.1.3" , forRemoval = true )
141
- public WebGraphQlRequest (URI uri , HttpHeaders headers , Map <String , Object > body , String id , @ Nullable Locale locale ) {
142
- this (uri , headers , null , Collections .emptyMap (), body , id , locale );
143
- }
144
-
145
178
private WebGraphQlRequest (
146
179
URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
147
- Map <String , Object > attributes , String document , @ Nullable String operationName ,
180
+ @ Nullable InetSocketAddress remoteAddress , Map <String , Object > attributes ,
181
+ String document , @ Nullable String operationName ,
148
182
@ Nullable Map <String , Object > variables , @ Nullable Map <String , Object > extensions ,
149
183
String id , @ Nullable Locale locale ) {
150
184
@@ -156,6 +190,7 @@ private WebGraphQlRequest(
156
190
this .uri = UriComponentsBuilder .fromUri (uri ).build (true );
157
191
this .headers = headers ;
158
192
this .cookies = (cookies != null ) ? CollectionUtils .unmodifiableMultiValueMap (cookies ) : EMPTY_COOKIES ;
193
+ this .remoteAddress = remoteAddress ;
159
194
this .attributes = Collections .unmodifiableMap (attributes );
160
195
}
161
196
@@ -182,6 +217,15 @@ public MultiValueMap<String, HttpCookie> getCookies() {
182
217
return this .cookies ;
183
218
}
184
219
220
+ /**
221
+ * Return the remote address of the client, if available.
222
+ * @since 1.3.0
223
+ */
224
+ @ Nullable
225
+ public InetSocketAddress getRemoteAddress () {
226
+ return this .remoteAddress ;
227
+ }
228
+
185
229
/**
186
230
* Return the request or WebSocket session attributes.
187
231
* @since 1.1.3
0 commit comments