Skip to content
This repository was archived by the owner on Sep 10, 2019. It is now read-only.

Commit 4466cea

Browse files
committed
fix: separate gateway function to lower complexity
1 parent 34d1614 commit 4466cea

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

bin/dev.js

+31-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ import { log, success, warn } from '../lib/logger';
1313

1414
const getDirPath = dir => path.resolve(process.cwd(), dir);
1515

16+
const startGateway = ({
17+
mock,
18+
gateway,
19+
dataSourcePaths,
20+
loadedDataSources,
21+
}) => {
22+
// If a custom gateway was specified, set the env vars and start it.
23+
if (gateway) {
24+
// Define GrAMPS env vars.
25+
process.env.GRAMPS_MODE = mock ? 'mock' : 'live';
26+
process.env.GRAMPS_DATA_SOURCES = dataSourcePaths.length
27+
? dataSourcePaths.join(',')
28+
: '';
29+
30+
// Start the user-specified gateway.
31+
spawn('node', [gateway], { stdio: 'inherit' });
32+
return;
33+
}
34+
35+
// If we get here, fire up the default gateway for development.
36+
startDefaultGateway({
37+
dataSources: loadedDataSources,
38+
enableMockData: mock,
39+
});
40+
};
41+
1642
export const command = 'dev';
1743
export const description = 'run a GraphQL gateway for local development';
1844

@@ -70,23 +96,11 @@ export const handler = async ({
7096
loadedDataSources = loadDataSources(dataSourcePaths);
7197
}
7298

73-
// If a custom gateway was specified, set the env vars and start it.
74-
if (gateway) {
75-
// Define GrAMPS env vars.
76-
process.env.GRAMPS_MODE = mock ? 'mock' : 'live';
77-
process.env.GRAMPS_DATA_SOURCES = dataSourcePaths.length
78-
? dataSourcePaths.join(',')
79-
: '';
80-
81-
// Start the user-specified gateway.
82-
spawn('node', [gateway], { stdio: 'inherit' });
83-
return;
84-
}
85-
86-
// If we get here, fire up the default gateway for development.
87-
startDefaultGateway({
88-
dataSources: loadedDataSources,
89-
enableMockData: mock,
99+
startGateway({
100+
mock,
101+
gateway,
102+
dataSourcePaths,
103+
loadedDataSources,
90104
});
91105
};
92106

0 commit comments

Comments
 (0)