• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Mintbase / mintbase-js / 3932668827

pending completion
3932668827

push

github

Ruben Marcus
replace the package name

461 of 611 branches covered (75.45%)

Branch coverage included in aggregate %.

676 of 726 relevant lines covered (93.11%)

4.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.58
/packages/data/src/graphql/fetch.ts
1
import { DocumentNode } from 'graphql';
2
import { GraphQLClient } from 'graphql-request';
13✔
3
import { getErrorMessage } from '../errorHandling';
13✔
4
import { GRAPHQL_ENDPOINTS, mbjs, NEAR_NETWORKS, Network } from '@mintbase-js/sdk';
13✔
5

6
const isValidNetwork = (network: Network): boolean =>  network === NEAR_NETWORKS.MAINNET || network ===  NEAR_NETWORKS.TESTNET;
57✔
7

8

9
export type GqlFetchResult<T> = {
10
  data?: T;
11
  error?: string;
12
}
13

14
export const fetchGraphQl = async <T, V = Record<string, unknown>>({
13✔
15
  query,
16
  variables,
17
  network,
18
}: {
19
  query: DocumentNode | string;
20
  variables?: V;
21
  network?: Network | null | undefined;
22
}): Promise<GqlFetchResult<T>> => {
29✔
23

24
  let networkObj = network;
29✔
25

26
  if (!network) {
29✔
27
    networkObj = mbjs?.keys?.network as Network;
27!
28
  }
29

30
  if (networkObj && !isValidNetwork(networkObj)) {
29✔
31
    return { error: 'Please add a valid Network' };
1✔
32
  }
33

34
  if (!networkObj) {
28!
35
    return { error: 'Please set a network.' };
×
36
  }
37

38
  const endpointReady = isValidNetwork(networkObj) && networkObj;
28✔
39

40
  const graphqlEndpoint = GRAPHQL_ENDPOINTS[networkObj] ?? mbjs?.keys?.graphqlUrl;
28!
41

42
  if (endpointReady && graphqlEndpoint) {
28✔
43

44
    try {
28✔
45
      const client = new GraphQLClient(graphqlEndpoint);
28✔
46
      return {
28✔
47
        data: await client.request<T>(query, variables),
48
      };
49
    
50
    } catch (error:unknown) {
51
      return {
13✔
52
        error: getErrorMessage(error),
53
      };
54
    }
55
  }
56

57
  return { data: null, error: null };
×
58

59
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc