-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78e4d9c
commit c7c4a60
Showing
17 changed files
with
273 additions
and
16 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,5 @@ | ||
--- | ||
'nx-plugin-graphql-mesh': major | ||
--- | ||
|
||
Add `start` executor |
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
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
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
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
27 changes: 27 additions & 0 deletions
27
libs/nx-plugin-graphql-mesh/src/executors/start/hasher.spec.ts
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,27 @@ | ||
import { Hasher, HasherContext } from '@nrwl/devkit'; | ||
|
||
import { startHasher } from './hasher'; | ||
|
||
describe('startHasher', () => { | ||
it('should generate hash', async () => { | ||
const mockHasher: Hasher = { | ||
hashTaskWithDepsAndContext: jest | ||
.fn() | ||
.mockReturnValue({ value: 'hashed-task' }), | ||
} as unknown as Hasher; | ||
const hash = await startHasher( | ||
{ | ||
id: 'my-task-id', | ||
target: { | ||
project: 'proj', | ||
target: 'target', | ||
}, | ||
overrides: {}, | ||
}, | ||
{ | ||
hasher: mockHasher, | ||
} as unknown as HasherContext | ||
); | ||
expect(hash).toEqual({ value: 'hashed-task' }); | ||
}); | ||
}); |
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 @@ | ||
import { CustomHasher } from '@nrwl/devkit'; | ||
|
||
/** | ||
* This is a boilerplate custom hasher that matches | ||
* the default Nx hasher. If you need to extend the behavior, | ||
* you can consume workspace details from the context. | ||
*/ | ||
export const startHasher: CustomHasher = async (task, context) => { | ||
return context.hasher.hashTaskWithDepsAndContext(task); | ||
}; | ||
|
||
export default startHasher; |
32 changes: 32 additions & 0 deletions
32
libs/nx-plugin-graphql-mesh/src/executors/start/schema.json
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,32 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"title": "Start executor", | ||
"description": "Serves a GraphQL server with GraphQL interface based on your generated artifacts", | ||
"type": "object", | ||
"properties": { | ||
"debug": { | ||
"type": "boolean", | ||
"description": "Display debugging info.", | ||
"default": false | ||
}, | ||
"dir": { | ||
"description": "The directory containing built GraphQL Mesh assets (.mesh).", | ||
"type": "string" | ||
}, | ||
"port": { | ||
"type": "integer", | ||
"description": "The port number to run on.", | ||
"default": 4000 | ||
}, | ||
"require": { | ||
"type": "array", | ||
"description": "Loads specific require.extensions before running the codegen and reading the configuration.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"default": [] | ||
} | ||
}, | ||
"required": ["dir"] | ||
} |
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 type { Options } from '../../utils'; | ||
|
||
type MeshStartSchema = Options<'start'>; | ||
|
||
export type StartExecutorSchema = MeshStartSchema['args'] & | ||
MeshStartSchema['env']; |
66 changes: 66 additions & 0 deletions
66
libs/nx-plugin-graphql-mesh/src/executors/start/start.impl.ts
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,66 @@ | ||
import type { ExecutorContext } from '@nrwl/devkit'; | ||
|
||
import { logger } from '@nrwl/devkit'; | ||
import { resolve } from 'path'; | ||
|
||
import { childProcess, runMeshCli } from '../../utils/mesh-cli'; | ||
|
||
import { StartExecutorSchema } from './schema'; | ||
|
||
const readyWhenMsg = 'Serving GraphQL Mesh:'; | ||
|
||
export default async function* startExecutor( | ||
options: StartExecutorSchema, | ||
context: ExecutorContext | ||
) { | ||
if (options.dir === undefined) { | ||
throw new Error("Please define the 'dir' value"); | ||
} | ||
|
||
const baseUrl = `http://0.0.0.0:${options.port}`; | ||
|
||
logger.info('Starting GraphQL Mesh start server...'); | ||
|
||
runMeshCli( | ||
'start', | ||
{ | ||
args: { | ||
dir: resolve(context.root, options.dir), | ||
port: options.port, | ||
require: options.require, | ||
}, | ||
env: { | ||
debug: options.debug, | ||
}, | ||
}, | ||
context, | ||
{ | ||
stdio: 'pipe', | ||
} | ||
); | ||
|
||
childProcess?.stdout?.on('data', (chunk) => { | ||
process.stdout.write(chunk); | ||
}); | ||
|
||
childProcess?.stderr?.on('data', (chunk) => { | ||
process.stderr.write(chunk); | ||
}); | ||
|
||
await new Promise<void>((resolve) => { | ||
childProcess?.stdout?.on('data', (chunk) => { | ||
if (chunk.toString().indexOf(readyWhenMsg) > -1) { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
|
||
yield { | ||
baseUrl, | ||
success: true, | ||
}; | ||
|
||
await new Promise<{ success: boolean }>(() => { | ||
// This Promise intentionally never resolves, leaving the process running. | ||
}); | ||
} |
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