MCPcopy Create free account
hub / github.com/subquery/subql / processGetJson

Function processGetJson

packages/node-core/src/utils/graphql.ts:153–177  ·  view source on GitHub ↗

* Process nested json get, output is same as input value type * @param field * @param value

(field: GraphQLEntityField | GraphQLJsonFieldType, value: any)

Source from the content-addressed store, hash-verified

151 * @param value
152 */
153function 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
179function processSetJson(data: any): any {
180 return JSON.parse(

Callers 1

getColumnOptionFunction · 0.85

Calls 1

processBigIntFieldsFunction · 0.85

Tested by

no test coverage detected