87f7efd960
* fix: candle type paths * chore: migrate deal-ticket * chore: migrate deposits * fix: format * chore: migrate environment * fix: format * chore: migrate fills * fix: format * chore: fix build errors * fix: format * fix: lint * fix: env tests * fix: add missing query variable * fix: format * fix: change vega_url because n11 is down * fix: deal ticket query name * chore: extend event type * fix: incorrect e2e test
26 lines
591 B
TypeScript
26 lines
591 B
TypeScript
import type { Schema } from '@vegaprotocol/types';
|
|
|
|
export type Node<T> = {
|
|
__typename?: string;
|
|
node: T;
|
|
};
|
|
|
|
export type Connection<A> = {
|
|
__typename?: string;
|
|
edges?: Schema.Maybe<Array<Schema.Maybe<A>>>;
|
|
};
|
|
|
|
export function getNodes<
|
|
T,
|
|
A extends Node<T> = Node<T>,
|
|
B extends Connection<A> = Connection<A>
|
|
>(data?: B | null, filterBy?: (item?: T | null) => boolean) {
|
|
const edges = data?.edges || [];
|
|
return edges.reduce<T[]>((acc, edge) => {
|
|
if (edge?.node && (filterBy ? filterBy(edge?.node) : true)) {
|
|
acc.push(edge.node);
|
|
}
|
|
return acc;
|
|
}, []);
|
|
}
|