File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1
1
import axios from 'axios' ;
2
+ import { isObject , forEach } from 'lodash' ;
3
+
4
+ const paramsSerializer = ( params ) => {
5
+ const parts = [ ] ;
6
+
7
+ forEach ( params , ( value , key ) => {
8
+ if ( value === null || typeof value === 'undefined' ) {
9
+ return ;
10
+ }
11
+
12
+ let k = key ;
13
+ let v = value ;
14
+ if ( Array . isArray ( v ) ) {
15
+ k += '[]' ;
16
+ } else {
17
+ v = [ v ] ;
18
+ }
19
+
20
+ forEach ( v , ( val ) => {
21
+ let finalValue = val ;
22
+ if ( isObject ( finalValue ) ) {
23
+ finalValue = JSON . stringify ( finalValue ) ;
24
+ }
25
+ parts . push ( `${ k } =${ finalValue } ` ) ;
26
+ } ) ;
27
+ } ) ;
28
+
29
+ return parts . join ( '&' ) ;
30
+ } ;
2
31
3
32
export default class HttpDataLoader {
4
33
constructor ( config ) {
@@ -13,6 +42,7 @@ export default class HttpDataLoader {
13
42
url : req . resourcePath ,
14
43
headers : req . params . headers ,
15
44
params : req . params . query ,
45
+ paramsSerializer,
16
46
method : req . method . toLowerCase ( ) ,
17
47
data : req . params . body ,
18
48
} ) ;
You can’t perform that action at this time.
0 commit comments