-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
69 additions
and
31 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
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 |
---|---|---|
|
@@ -32,7 +32,6 @@ ehthumbs.db | |
**/.DS_Store | ||
|
||
# Build | ||
/dist | ||
/tmp | ||
oclif.manifest.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,14 @@ | ||
import { Command } from '@oclif/core'; | ||
export default class Mock extends Command { | ||
static args: { | ||
schema: import("@oclif/core/interfaces").Arg<string, { | ||
exists?: boolean; | ||
}>; | ||
}; | ||
static description: string; | ||
static examples: string[]; | ||
static flags: { | ||
port: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>; | ||
}; | ||
run(): Promise<void>; | ||
} |
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 { Args, Command, Flags } from '@oclif/core'; | ||
import { readFileSync } from 'node:fs'; | ||
import { startServer } from '../../common/server.js'; | ||
export default class Mock extends Command { | ||
static args = { | ||
schema: Args.file({ description: 'Schema file to mock', required: true }), | ||
}; | ||
static description = 'Start a mock GraphQL server from a file'; | ||
static examples = [ | ||
'<%= config.bin %> <%= command.id %> schema.graphql', | ||
'<%= config.bin %> <%= command.id %> schema.graphql --port 8080', | ||
]; | ||
static flags = { | ||
port: Flags.integer({ | ||
default: 4000, | ||
description: 'HTTP port for server', | ||
required: false | ||
}) | ||
}; | ||
async run() { | ||
const { args, flags } = await this.parse(Mock); | ||
this.log(`Reading schema file ${args.schema}...`); | ||
const sdl = readFileSync(args.schema, 'utf8'); | ||
const promise = await startServer(sdl, flags.port); | ||
this.log(`🚀 Mock Apollo Server ready at: ${promise.url}`); | ||
} | ||
} |
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 @@ | ||
export declare const startServer: (sdl: string, port: number) => Promise<{ | ||
url: 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,16 @@ | ||
import { ApolloServer } from '@apollo/server'; | ||
import { startStandaloneServer } from '@apollo/server/standalone'; | ||
import { addMocksToSchema } from '@graphql-tools/mock'; | ||
import { makeExecutableSchema } from '@graphql-tools/schema'; | ||
const getApolloServer = (sdl) => new ApolloServer({ | ||
introspection: true, | ||
schema: addMocksToSchema({ | ||
schema: makeExecutableSchema({ typeDefs: sdl }) | ||
}) | ||
}); | ||
export const startServer = async (sdl, port) => { | ||
const server = getApolloServer(sdl); | ||
return startStandaloneServer(server, { | ||
listen: { port }, | ||
}); | ||
}; |
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 @@ | ||
export { run } from '@oclif/core'; |
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 @@ | ||
export { run } from '@oclif/core'; |