Select one level deep values for array type attributes from GQL query result
Some checks failed
Tests / sdk_tests (pull_request) Has been cancelled

This commit is contained in:
Prathamesh Musale 2024-01-11 15:31:50 +05:30
parent 17b21c4750
commit e92bf8e431
2 changed files with 21 additions and 3 deletions

View File

@ -16,7 +16,16 @@ const attributeField = `
... on StringValue { string: value } ... on StringValue { string: value }
... on BytesValue { bytes: value } ... on BytesValue { bytes: value }
... on LinkValue { link: 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 } } } ... on MapValue { map: value { key mapping: value { __typename } } }
} }
} }

View File

@ -86,10 +86,19 @@ export class Util {
} }
static fromGQLValue(obj: any) { static fromGQLValue(obj: any) {
// Get first non-null key
const present = Object.keys(obj).find(k => obj[k] !== null); const present = Object.keys(obj).find(k => obj[k] !== null);
if (present === undefined) { if (present === undefined) {
throw new Error('Object has no non-null values'); 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]; return obj[present];
} }