* Process nested json get, output is same as input value type * @param field * @param value
(field: GraphQLEntityField | GraphQLJsonFieldType, value: any)
| 151 | * @param value |
| 152 | */ |
| 153 | function processGetJson(field: GraphQLEntityField | GraphQLJsonFieldType, value: any): any { |
| 154 | // bigIntFields and nestJsonFields from this level in the entity/json |
| 155 | const bigIntFields = field.jsonInterface?.fields.filter((f) => f.type === 'BigInt'); |
| 156 | const nestJsonFields = field.jsonInterface?.fields.filter((f) => f.jsonInterface); |
| 157 | const processBigIntFields = (value: any) => { |
| 158 | if (bigIntFields) { |
| 159 | for (const bigIntField of bigIntFields) { |
| 160 | // If null is passed, we should not convert it to BigInt |
| 161 | if (value[bigIntField.name] !== undefined && value[bigIntField.name] !== null) { |
| 162 | value[bigIntField.name] = BigInt(value[bigIntField.name].slice(0, -1)); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | return value; |
| 167 | }; |
| 168 | if (nestJsonFields) { |
| 169 | for (const nestJsonField of nestJsonFields) { |
| 170 | // have a nest field, and nest field is json type, also value is defined |
| 171 | if (nestJsonField.jsonInterface && value[nestJsonField.name]) { |
| 172 | value[nestJsonField.name] = processGetJson(nestJsonField, value[nestJsonField.name]); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | return processBigIntFields(value); |
| 177 | } |
| 178 | |
| 179 | function processSetJson(data: any): any { |
| 180 | return JSON.parse( |
no test coverage detected