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

alkem-io / client-web / #5957

13 Oct 2023 06:22AM UTC coverage: 6.276%. First build
#5957

Pull #4943

travis-ci

Pull Request #4943: GraphQL errors logged in Sentry & APM

173 of 8224 branches covered (0.0%)

Branch coverage included in aggregate %.

38 of 38 new or added lines in 7 files covered. (100.0%)

1294 of 15151 relevant lines covered (8.54%)

0.42 hits per line

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

0.0
/src/core/apollo/hooks/useGraphQLClient.ts
1
import { useMemo, useRef } from 'react';
2
import { from, InMemoryCache, NormalizedCacheObject, ApolloClient } from '@apollo/client';
3
import { once } from 'lodash';
4
import { env } from '@/main/env';
5
import {
6
  omitTypenameLink,
7
  consoleLink,
8
  guestHeaderLink,
9
  retryLink,
10
  redirectLink,
11
  httpLink,
12
  useErrorHandlerLink,
13
  useErrorLoggerLink,
14
} from '../graphqlLinks';
15
import { typePolicies } from '../config/typePolicies';
16

×
17
const enableQueryDebug = !!(env && env?.VITE_APP_DEBUG_QUERY === 'true');
×
18
const enableErrorLogging = !!(env && env?.VITE_APP_LOG_ERRORS === 'true');
19

×
20
export const useGraphQLClient = (
21
  graphQLEndpoint: string,
22
  enableWebSockets: boolean
23
): ApolloClient<NormalizedCacheObject> => {
24
  // useMemo() is a performance optimization and is not really guaranteed to be run ONLY when deps change.
25
  // It's guaranteed to be re-run WHEN the deps change, but it can re-run at random time as well.
26
  // See https://reactjs.org/docs/hooks-reference.html#usememo
27
  // If that happens, we don't want to lose the cache.
×
28
  const cache = useRef(
29
    once(
×
30
      () =>
×
31
        new InMemoryCache({
32
          typePolicies,
×
33
          possibleTypes: {
×
34
            Contributor: ['User', 'Organization', 'VirtualContributor'],
35
          },
36
        })
37
    )
38
  ).current();
39

40
  const errorHandlerLink = useErrorHandlerLink();
41
  const errorLoggerLink = useErrorLoggerLink(enableErrorLogging);
42

43
  return useMemo(() => {
44
    return new ApolloClient({
45
      link: from([
46
        omitTypenameLink,
47
        consoleLink(enableQueryDebug),
48
        guestHeaderLink,
49
        errorLoggerLink,
50
        errorHandlerLink,
51
        retryLink,
52
        redirectLink,
53
        httpLink(graphQLEndpoint, enableWebSockets),
54
      ]),
55
      cache,
56
    });
57
  }, [enableWebSockets, graphQLEndpoint, errorHandlerLink, cache]);
58
};
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

© 2026 Coveralls, Inc