-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Correct path to file containing custom fetch function when build…
…ing Mesh project (#5841)
- Loading branch information
1 parent
4180409
commit afa35c8
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-mesh/config': patch | ||
--- | ||
|
||
Fix path to file containing custom fetch function when building Mesh project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { MeshFetchRequestInit } from '@graphql-mesh/types'; | ||
import { fetch } from '@whatwg-node/fetch'; | ||
|
||
export default function (url: string, options?: MeshFetchRequestInit) { | ||
return fetch(url, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { path as pathModule } from '@graphql-mesh/cross-helpers'; | ||
import { writeFile } from '@graphql-mesh/utils'; | ||
import { processConfig } from '../src/process'; | ||
|
||
describe('processConfig', () => { | ||
const generatedMeshConfiguration = '.mesh'; | ||
|
||
it('should be possible to load custom fetch function', async () => { | ||
const config = await processConfig( | ||
{ | ||
customFetch: './mesh-config-sources/custom-fetch.ts', | ||
sources: [], | ||
}, | ||
{ | ||
dir: __dirname, | ||
generateCode: true, | ||
}, | ||
); | ||
|
||
// Verify that the code has been generated | ||
expect(config).toBeDefined(); | ||
expect(config.importCodes).toBeDefined(); | ||
|
||
let meshConfigContent = ''; | ||
|
||
// Find the custom fetch | ||
const importCodesIterator = config.importCodes.values(); | ||
let importCodesIteratorResult = importCodesIterator.next(); | ||
let includesCustomFetch; | ||
while (!importCodesIteratorResult.done) { | ||
if (importCodesIteratorResult.value.startsWith('import fetchFn from')) { | ||
meshConfigContent = meshConfigContent.concat(importCodesIteratorResult.value, '\n'); | ||
includesCustomFetch = true; | ||
break; | ||
} | ||
importCodesIteratorResult = importCodesIterator.next(); | ||
} | ||
expect(includesCustomFetch).toBeTruthy(); | ||
|
||
expect(meshConfigContent).toBeDefined(); | ||
|
||
// Adding export of fetch function so its resolution is actually attempted | ||
meshConfigContent = meshConfigContent.concat('export { fetchFn };', '\n'); | ||
|
||
// Create a .ts file with the codes and importCodes content | ||
const meshConfigPath = pathModule.join(__dirname, generatedMeshConfiguration, '/index.ts'); | ||
await writeFile(meshConfigPath, meshConfigContent); | ||
|
||
const { fetchFn } = await import(meshConfigPath); | ||
expect(fetchFn).toBeDefined(); | ||
}); | ||
}); |