-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance(transport-rest): use the default fetch if no fetch exists in the transport context #8351
Conversation
…the transport context
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
packages/transports/rest/src/directives/httpOperation.tsOops! Something went wrong! :( ESLint: 9.19.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by 📝 WalkthroughWalkthroughThe pull request introduces a patch for the Changes
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
⏰ Context from checks skipped due to timeout of 90000ms (14)
🔇 Additional comments (3)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai generate unit testing code for this file. |
Tip For best results, initiate chat on the files or code changes. @ardatan Here are the unit tests for the REST transport implementation: import { describe, it, expect, vi } from 'vitest';
import RESTTransport from '../src/index';
import { processDirectives } from '../src/directives/process';
import { createDefaultExecutor } from '@graphql-mesh/transport-common';
// Mock dependencies
vi.mock('@graphql-mesh/transport-common', () => ({
createDefaultExecutor: vi.fn(),
}));
vi.mock('../src/directives/process', () => ({
processDirectives: vi.fn(),
}));
describe('REST Transport', () => {
const mockFetch = vi.fn();
const mockPubsub = { publish: vi.fn(), subscribe: vi.fn() };
const mockLogger = { info: vi.fn(), error: vi.fn() };
const mockSubgraph = { schema: {} };
beforeEach(() => {
vi.clearAllMocks();
});
it('should initialize executor with correct parameters', () => {
const transportEntry = {
options: {
timeout: 5000,
queryParams: { version: '1.0' },
},
};
RESTTransport.getSubgraphExecutor({
transportEntry,
subgraph: mockSubgraph,
fetch: mockFetch,
pubsub: mockPubsub,
logger: mockLogger,
});
// Verify processDirectives was called with correct args
expect(processDirectives).toHaveBeenCalledWith(mockSubgraph, {
globalFetch: mockFetch,
pubsub: mockPubsub,
logger: mockLogger,
timeout: 5000,
queryParams: { version: '1.0' },
});
});
it('should create and return default executor with processed schema', () => {
const mockProcessedSchema = { processed: true };
(processDirectives as jest.Mock).mockReturnValue(mockProcessedSchema);
const mockExecutor = vi.fn();
(createDefaultExecutor as jest.Mock).mockReturnValue(mockExecutor);
const result = RESTTransport.getSubgraphExecutor({
transportEntry: { options: {} },
subgraph: mockSubgraph,
fetch: mockFetch,
pubsub: mockPubsub,
logger: mockLogger,
});
expect(createDefaultExecutor).toHaveBeenCalledWith(mockProcessedSchema);
expect(result).toBe(mockExecutor);
});
it('should work without optional transport options', () => {
RESTTransport.getSubgraphExecutor({
transportEntry: { options: {} },
subgraph: mockSubgraph,
fetch: mockFetch,
pubsub: mockPubsub,
logger: mockLogger,
});
expect(processDirectives).toHaveBeenCalledWith(mockSubgraph, {
globalFetch: mockFetch,
pubsub: mockPubsub,
logger: mockLogger,
});
});
it('should pass fetch function to process directives', () => {
const customFetch = vi.fn();
RESTTransport.getSubgraphExecutor({
transportEntry: { options: {} },
subgraph: mockSubgraph,
fetch: customFetch,
pubsub: mockPubsub,
logger: mockLogger,
});
expect(processDirectives).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
globalFetch: customFetch,
}),
);
});
}); This test suite covers:
The tests use Vitest as the testing framework and include mocks for all external dependencies. You'll need to place this file in the Make sure to add the following dev dependencies to your package: {
"devDependencies": {
"vitest": "latest",
"@types/jest": "latest"
}
} 🔗 Analysis chain🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 30 Script:
Length of output: 31 Script:
Length of output: 129 Script:
Length of output: 971 |
Apollo Federation Subgraph Compatibility Results
Learn more: |
🚀 Snapshot Release (
|
Package | Version | Info |
---|---|---|
@graphql-mesh/json-schema |
0.108.15-alpha-20250131092314-9768df0daaefb5600beeda0845e991d3513b3af8 |
npm ↗︎ unpkg ↗︎ |
@graphql-mesh/openapi |
0.108.16-alpha-20250131092314-9768df0daaefb5600beeda0845e991d3513b3af8 |
npm ↗︎ unpkg ↗︎ |
@graphql-mesh/raml |
0.108.14-alpha-20250131092314-9768df0daaefb5600beeda0845e991d3513b3af8 |
npm ↗︎ unpkg ↗︎ |
@omnigraph/json-schema |
0.108.14-alpha-20250131092314-9768df0daaefb5600beeda0845e991d3513b3af8 |
npm ↗︎ unpkg ↗︎ |
@omnigraph/openapi |
0.108.16-alpha-20250131092314-9768df0daaefb5600beeda0845e991d3513b3af8 |
npm ↗︎ unpkg ↗︎ |
@omnigraph/raml |
0.108.14-alpha-20250131092314-9768df0daaefb5600beeda0845e991d3513b3af8 |
npm ↗︎ unpkg ↗︎ |
@graphql-mesh/transport-rest |
0.8.14-alpha-20250131092314-9768df0daaefb5600beeda0845e991d3513b3af8 |
npm ↗︎ unpkg ↗︎ |
💻 Website PreviewThe latest changes are available as preview in: https://a0bff8b3.graphql-mesh.pages.dev |
Fixes graphql-hive/gateway#1
Summary by CodeRabbit