@@ -41,31 +41,33 @@ export default class QueryBuilder {
41
41
*
42
42
* There are three types of arguments:
43
43
*
44
- * 1) Signatures with attributes (signature = true)
44
+ * 1) Signatures with simple types (signature = true)
45
45
* mutation createUser($name: String!)
46
46
*
47
- * 2) Signatures with object (signature = true, args = { user: { __type: 'User' }})
48
- * mutation createUser($user: User !)
47
+ * 2) Signatures with object types (signature = true, args = { user: { __type: 'User' }})
48
+ * mutation createUser($user: UserInput !)
49
49
*
50
- * 3) Field with values (signature = false, valuesAsVariables = false)
51
- * user(id: 15)
50
+ * 3) Fields with values (signature = false, valuesAsVariables = false)
51
+ * query user(id: 15)
52
52
*
53
- * 4) Field with variables (signature = false, valuesAsVariables = true)
54
- * user(id: $id)
53
+ * 4) Fields with variables (signature = false, valuesAsVariables = true)
54
+ * query user(id: $id)
55
55
*
56
- * 5) Field with object value (signature = false, valuesAsVariables = false, args = { user: { __type: 'User' }})
57
- * createUser(user: {...})
56
+ * 5) Fields with object value (signature = false, valuesAsVariables = false, args = { user: { __type: 'User' }})
57
+ * mutation createUser(user: {...})
58
58
*
59
59
* @param {Arguments | undefined } args
60
60
* @param {boolean } signature When true, then this method generates a query signature instead of key/value pairs
61
61
* @param {boolean } valuesAsVariables When true and abstract = false, then this method generates filter arguments with
62
62
* variables instead of values
63
63
* @returns {String }
64
64
*/
65
- public buildArguments ( args : Arguments | undefined , signature : boolean = false ,
66
- valuesAsVariables : boolean = false ) : string {
65
+ public buildArguments ( args : Arguments | undefined ,
66
+ signature : boolean = false ,
67
+ valuesAsVariables : boolean = false ) : string {
67
68
let returnValue : string = '' ;
68
69
let any : boolean = false ;
70
+ let first : boolean = true ;
69
71
70
72
if ( args ) {
71
73
Object . keys ( args ) . forEach ( ( key : string ) => {
@@ -90,14 +92,15 @@ export default class QueryBuilder {
90
92
} else {
91
93
if ( typeof value === 'object' && value . __type ) {
92
94
// Case 3 ({name: 'Helga Hufflepuff"})
93
- typeOrValue = value ;
95
+ typeOrValue = JSON . stringify ( value ) ;
94
96
} else {
95
97
// Case 3 ("someValue")
96
98
typeOrValue = typeof value === 'number' ? value : `"${ value } "` ;
97
99
}
98
100
}
99
101
100
- returnValue = `${ returnValue } ${ ( signature ? '$' : '' ) + key } : ${ typeOrValue } ` ;
102
+ returnValue = `${ returnValue } ${ first ? '' : ', ' } ${ ( signature ? '$' : '' ) + key } : ${ typeOrValue } ` ;
103
+ first = false ;
101
104
}
102
105
} ) ;
103
106
@@ -108,17 +111,24 @@ export default class QueryBuilder {
108
111
}
109
112
110
113
111
-
112
-
113
-
114
+ /**
115
+ * Transforms outgoing data. Use for variables param.
116
+ *
117
+ * Omits relations and id fields.
118
+ *
119
+ * @param {Data } data
120
+ * @returns {Data }
121
+ */
114
122
public transformOutgoingData ( data : Data ) : Data {
123
+ const model : Model = this . getModel ( data . $self ( ) . entity ) ;
124
+ const relations : Map < string , Field > = model . getRelations ( ) ;
115
125
const returnValue : Data = { } ;
116
126
117
127
Object . keys ( data ) . forEach ( ( key ) => {
118
128
const value = data [ key ] ;
119
129
120
130
// Ignore IDs and connections
121
- if ( ! ( value instanceof Array || key === 'id' ) ) {
131
+ if ( ! relations . has ( key ) && key !== 'id' ) {
122
132
returnValue [ key ] = value ;
123
133
}
124
134
} ) ;
0 commit comments