-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Corerct TS artifact generation when Mesh config is in TS/JS form…
…at (#5966)
- Loading branch information
1 parent
3e246cf
commit 8f2349c
Showing
7 changed files
with
105 additions
and
0 deletions.
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,6 @@ | ||
--- | ||
'@graphql-mesh/cli': patch | ||
--- | ||
|
||
Fix TS artifact generation when running Mesh build command so no reference to Mesh config script | ||
files (TS/JS) are included in the built sources. |
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
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 |
---|---|---|
@@ -1,3 +1,54 @@ | ||
import { fs, path as pathModule } from '@graphql-mesh/cross-helpers'; | ||
import { DEFAULT_CLI_PARAMS, graphqlMesh } from '../src/index'; | ||
|
||
describe('runtime', () => { | ||
it('dummy', async () => {}); | ||
|
||
describe('build', () => { | ||
const generatedMeshConfiguration = '.mesh'; | ||
|
||
it('Should replace the `.ts` extension of a config file in the built Mesh index file for the `.js` extension', async () => { | ||
const tsConfigFolder = 'ts-config'; | ||
await graphqlMesh(DEFAULT_CLI_PARAMS, [ | ||
'build', | ||
`--dir=${pathModule.resolve(__dirname, tsConfigFolder)}`, | ||
]); | ||
|
||
const meshConfigPath = pathModule.resolve( | ||
__dirname, | ||
tsConfigFolder, | ||
generatedMeshConfiguration, | ||
'index.ts', | ||
); | ||
const builtMesh = (await fs.promises.readFile(meshConfigPath)).toString(); | ||
|
||
// Check that the import of the main Mesh module has replaced the extension | ||
expect(builtMesh).toMatch(/import \* as importedModule(.*) from ".*\/\.meshrc.js";/); | ||
|
||
// Check that the reference to the relative module in the "importFn" function has replaced the extension | ||
expect(builtMesh).toMatch(/case "\.meshrc.js":/); | ||
}); | ||
|
||
it('Should keep the `.js` extension of a config file in the built Mesh index file', async () => { | ||
const jsConfigFolder = 'js-config'; | ||
await graphqlMesh(DEFAULT_CLI_PARAMS, [ | ||
'build', | ||
`--dir=${pathModule.resolve(__dirname, jsConfigFolder)}`, | ||
]); | ||
|
||
const meshConfigPath = pathModule.resolve( | ||
__dirname, | ||
jsConfigFolder, | ||
generatedMeshConfiguration, | ||
'index.ts', | ||
); | ||
const builtMesh = (await fs.promises.readFile(meshConfigPath)).toString(); | ||
|
||
// Check that the import of the main Mesh module has kept the file's extension | ||
expect(builtMesh).toMatch(/import \* as importedModule(.*) from ".*\/\.meshrc.js";/); | ||
|
||
// Check that the reference to the relative module in the "importFn" function has kept the file's extension | ||
expect(builtMesh).toMatch(/case "\.meshrc.js":/); | ||
}); | ||
}); | ||
}); |
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,3 @@ | ||
type Query { | ||
greet: String | ||
} |
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,12 @@ | ||
module.exports = { | ||
sources: [ | ||
{ | ||
name: 'Dummy', | ||
handler: { | ||
graphql: { | ||
source: '../fixtures/dummy-schema.graphql', | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |
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,12 @@ | ||
export default { | ||
sources: [ | ||
{ | ||
name: 'Dummy', | ||
handler: { | ||
graphql: { | ||
source: '../fixtures/dummy-schema.graphql', | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |