Skip to content

Commit a02314a

Browse files
authored
GraphQL integration (#5299)
* GraphQL integration * Changelog entry
1 parent 28188f3 commit a02314a

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
## Unreleased
1010

11+
### Features
12+
13+
- Adds GraphQL integration ([#5299](https://github.com/getsentry/sentry-react-native/pull/5299))
14+
1115
### Dependencies
1216

1317
- Bump Bundler Plugins from v4.4.0 to v4.5.0 ([#5283](https://github.com/getsentry/sentry-react-native/pull/5283))

packages/core/src/js/integrations/exports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export { timeToDisplayIntegration } from '../tracing/integrations/timeToDisplayI
2525
export { breadcrumbsIntegration } from './breadcrumbs';
2626
export { primitiveTagIntegration } from './primitiveTagIntegration';
2727
export { logEnricherIntegration } from './logEnricherIntegration';
28+
export { graphqlIntegration } from './graphql';
2829

2930
export {
3031
browserApiErrorsIntegration,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { graphqlClientIntegration as browserGraphqlClientIntegration } from '@sentry/browser';
2+
import type { Integration } from '@sentry/core';
3+
4+
interface GraphQLReactNativeIntegrationOptions {
5+
endpoints: Array<string | RegExp>;
6+
}
7+
8+
/**
9+
* This integration ensures that GraphQL requests made in the React Native apps
10+
* have their GraphQL-specific data captured and attached to spans and breadcrumbs.
11+
*/
12+
export function graphqlIntegration(options: GraphQLReactNativeIntegrationOptions): Integration {
13+
return browserGraphqlClientIntegration({ endpoints: options.endpoints });
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { graphqlClientIntegration as browserGraphqlClientIntegration } from '@sentry/browser';
2+
import { graphqlIntegration } from '../../src/js';
3+
4+
jest.mock('@sentry/browser', () => ({
5+
graphqlClientIntegration: jest.fn(() => ({ name: 'GraphQL' })),
6+
}));
7+
8+
describe('GraphQL Integration', () => {
9+
afterEach(() => {
10+
jest.resetAllMocks();
11+
});
12+
13+
it('passes React Native options to browserGraphqlClientIntegration', () => {
14+
const result = graphqlIntegration({ endpoints: ['test'] });
15+
16+
expect(browserGraphqlClientIntegration).toHaveBeenCalledWith({
17+
endpoints: ['test'],
18+
});
19+
expect(result).toBeDefined();
20+
});
21+
22+
it('handles RegExp patterns', () => {
23+
const pattern = /graphql/;
24+
graphqlIntegration({ endpoints: [pattern] });
25+
26+
expect(browserGraphqlClientIntegration).toHaveBeenCalledWith({
27+
endpoints: [pattern],
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)