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

Function listProjects

packages/cli/src/controller/network/list-projects.ts:27–58  ·  view source on GitHub ↗
(
  network: SQNetworks,
  address: string,
  ipfsEndpoint = IPFS_NODE_ENDPOINT
)

Source from the content-addressed store, hash-verified

25export type Project = z.infer<typeof projectSchema>;
26
27export async function listProjects(
28 network: SQNetworks,
29 address: string,
30 ipfsEndpoint = IPFS_NODE_ENDPOINT
31): Promise<Project[]> {
32 const res = await getQueryClient(network).query<GetProjectsQuery, GetProjectsQueryVariables>({
33 query: GetProjects,
34 variables: {address: utils.getAddress(address)},
35 });
36
37 if (res.errors) {
38 throw new Error(`Failed to fetch projects for address ${address}`);
39 }
40
41 const ipfs = new IPFSHTTPClientLite({url: ipfsEndpoint});
42
43 const raw = res.data?.projects?.nodes ?? [];
44 const projects = await Promise.all(
45 raw.map(async (p) => {
46 if (!p) return null;
47 const {__typename, type, ...rest} = p;
48
49 return <Project>{
50 ...rest,
51 type: ProjectType[gqlProjectTypeToProjectType(type)],
52 meta: await resultToJson(ipfs.cat(p.metadata), true),
53 };
54 })
55 );
56
57 return projects.filter((p): p is Project => p !== null);
58}

Callers 1

listProjectsAdapterFunction · 0.90

Calls 6

catMethod · 0.95
getQueryClientFunction · 0.90
resultToJsonFunction · 0.90
getAddressMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected