Select one level deep values for array type attributes from GQL query result
Some checks failed
Tests / sdk_tests (pull_request) Has been cancelled
Some checks failed
Tests / sdk_tests (pull_request) Has been cancelled
This commit is contained in:
parent
17b21c4750
commit
e92bf8e431
@ -16,7 +16,16 @@ const attributeField = `
|
||||
... on StringValue { string: value }
|
||||
... on BytesValue { bytes: value }
|
||||
... on LinkValue { link: value }
|
||||
... on ArrayValue { array: value { __typename } }
|
||||
... on ArrayValue {
|
||||
array: value {
|
||||
... on BooleanValue { bool: value }
|
||||
... on IntValue { int: value }
|
||||
... on FloatValue { float: value }
|
||||
... on StringValue { string: value }
|
||||
... on BytesValue { bytes: value }
|
||||
... on LinkValue { link: value }
|
||||
}
|
||||
}
|
||||
... on MapValue { map: value { key mapping: value { __typename } } }
|
||||
}
|
||||
}
|
||||
|
13
src/util.ts
13
src/util.ts
@ -36,7 +36,7 @@ export class Util {
|
||||
const vars: any[] = [];
|
||||
Object.keys(obj).forEach(key => {
|
||||
const value = this.toGQLValue(obj[key]);
|
||||
|
||||
|
||||
if (value !== undefined) {
|
||||
vars.push({ key, value });
|
||||
}
|
||||
@ -86,13 +86,22 @@ export class Util {
|
||||
}
|
||||
|
||||
static fromGQLValue(obj: any) {
|
||||
// Get first non-null key
|
||||
const present = Object.keys(obj).find(k => obj[k] !== null);
|
||||
if (present === undefined) {
|
||||
throw new Error('Object has no non-null values');
|
||||
}
|
||||
|
||||
// Create an array if array type attribute
|
||||
if (present === 'array') {
|
||||
return obj[present].map((e: any) => {
|
||||
return this.fromGQLValue(e);
|
||||
});
|
||||
}
|
||||
|
||||
return obj[present];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get record content ID.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user