1616
1717package org .springframework .graphql .server ;
1818
19+ import java .net .InetSocketAddress ;
1920import java .net .URI ;
2021import java .util .Collections ;
2122import java .util .Locale ;
@@ -58,8 +59,51 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements
5859
5960 private final MultiValueMap <String , HttpCookie > cookies ;
6061
62+ @ Nullable
63+ private final InetSocketAddress remoteAddress ;
64+
6165 private final Map <String , Object > attributes ;
6266
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+ }
63107
64108 /**
65109 * Create an instance.
@@ -71,12 +115,14 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements
71115 * @param id an identifier for the GraphQL request
72116 * @param locale the locale from the HTTP request, if any
73117 * @since 1.2.5
118+ * @deprecated since 1.3.0 in favor {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, InetSocketAddress, Map, Map, String, Locale)}
74119 */
120+ @ Deprecated (since = "1.3.0" , forRemoval = true )
75121 public WebGraphQlRequest (
76122 URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
77123 Map <String , Object > attributes , GraphQlRequest body , String id , @ Nullable Locale locale ) {
78124
79- this (uri , headers , cookies , attributes , body .getDocument (),
125+ this (uri , headers , cookies , null , attributes , body .getDocument (),
80126 body .getOperationName (), body .getVariables (), body .getExtensions (), id , locale );
81127 }
82128
@@ -91,12 +137,14 @@ public WebGraphQlRequest(
91137 * @param id an identifier for the GraphQL request
92138 * @param locale the locale from the HTTP request, if any
93139 * @since 1.1.3
140+ * @deprecated since 1.3.0 in favor {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, InetSocketAddress, Map, Map, String, Locale)}
94141 */
142+ @ Deprecated (since = "1.3.0" , forRemoval = true )
95143 public WebGraphQlRequest (
96144 URI uri , HttpHeaders headers , @ Nullable MultiValueMap <String , HttpCookie > cookies ,
97145 Map <String , Object > attributes , Map <String , Object > body , String id , @ Nullable Locale locale ) {
98146
99- this (uri , headers , cookies , attributes , getQuery (body ), getOperation (body ),
147+ this (uri , headers , cookies , null , attributes , getQuery (body ), getOperation (body ),
100148 getMap (VARIABLES_KEY , body ), getMap (EXTENSIONS_KEY , body ), id , locale );
101149 }
102150
@@ -127,24 +175,10 @@ private static Map<String, Object> getMap(String key, Map<String, Object> body)
127175 return (Map <String , Object >) value ;
128176 }
129177
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-
145178 private WebGraphQlRequest (
146179 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 ,
148182 @ Nullable Map <String , Object > variables , @ Nullable Map <String , Object > extensions ,
149183 String id , @ Nullable Locale locale ) {
150184
@@ -156,6 +190,7 @@ private WebGraphQlRequest(
156190 this .uri = UriComponentsBuilder .fromUri (uri ).build (true );
157191 this .headers = headers ;
158192 this .cookies = (cookies != null ) ? CollectionUtils .unmodifiableMultiValueMap (cookies ) : EMPTY_COOKIES ;
193+ this .remoteAddress = remoteAddress ;
159194 this .attributes = Collections .unmodifiableMap (attributes );
160195 }
161196
@@ -182,6 +217,15 @@ public MultiValueMap<String, HttpCookie> getCookies() {
182217 return this .cookies ;
183218 }
184219
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+
185229 /**
186230 * Return the request or WebSocket session attributes.
187231 * @since 1.1.3
0 commit comments