Skip to content
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

Allow function as valid type for UrlSchemaOptions.customFetch #10150

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for using function as customFetch
  • Loading branch information
Armin Wiebigke authored and ArminWiebigke committed Nov 12, 2024
commit 2b279a6b4f39c33cdeff7365a5e07a6908b96c8a
25 changes: 25 additions & 0 deletions packages/graphql-codegen-cli/tests/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,31 @@ describe('Codegen Executor', () => {
expect((global as any).CUSTOM_FETCH_FN_CALLED).toBeTruthy();
});

it('should load schema with custom fetch function', async () => {
let fetchCalledFor = null;

async function myCustomFetch(url: string, options?: RequestInit): Promise<Response> {
fetchCalledFor = url;
return Promise.resolve(new Response());
}

try {
await executeCodegen({
schema: ['http://www.dummyschema.com/graphql'],
customFetch: myCustomFetch,
documents: ['./tests/test-documents/valid.graphql'],
generates: {
'out1.ts': {
plugins: ['typescript'],
},
},
});
} catch (error) {
expect(error.message).toContain('Failed to load schema from http://www.dummyschema.com/graphql');
}
expect(fetchCalledFor).toBe('http://www.dummyschema.com/graphql');
});

it('should evaluate glob expressions correctly', async () => {
try {
await executeCodegen({
Expand Down