Skip to content

Commit 7c5c1f7

Browse files
authored
Merge pull request glennreyes#8 from glennreyes/missing-resolver-error-message
Missing resolver error message
2 parents e437876 + 58ce014 commit 7c5c1f7

File tree

6 files changed

+61
-42
lines changed

6 files changed

+61
-42
lines changed

bin/graphpack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const startDevServer = () => {
1515
webpackConfig.watchOptions,
1616
once((error, stats) => {
1717
if (error || stats.hasErrors()) {
18-
throw Error(error || stats.errors);
18+
throw Error(error || stats.toJson().errors);
1919
}
2020

2121
nodemon({ script: serverPaths[0], watch: serverPaths }).on(
@@ -29,7 +29,7 @@ const startDevServer = () => {
2929
const createProductionBuild = () => {
3030
compiler.run((error, stats) => {
3131
if (error || stats.hasErrors()) {
32-
throw Error(error || stats.errors);
32+
throw Error(error || stats.toJson().errors);
3333
}
3434
});
3535
};

config/webpack.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ module.exports = {
4747
},
4848
plugins: [
4949
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
50-
new webpack.EnvironmentPlugin({ NODE_ENV: 'development', DEBUG: false }),
50+
new webpack.EnvironmentPlugin({
51+
DEBUG: false,
52+
GRAPHPACK_SRC_DIR: path.resolve(process.cwd(), 'src'),
53+
NODE_ENV: 'development',
54+
}),
5155
new FriendlyErrorsWebpackPlugin(),
5256
],
53-
resolve: {
54-
alias: { __GRAPHPACK_USER_SRC__: path.resolve(process.cwd(), 'src') },
55-
extensions: ['.wasm', '.js', '.mjs', '.json', '.graphql'],
56-
},
5757
stats: 'minimal',
5858
target: 'node',
5959
};

lib/server.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ApolloServer } from 'apollo-server';
2+
import { config, context, resolvers, typeDefs } from './srcFiles';
3+
4+
if (!(resolvers && Object.keys(resolvers).length > 0)) {
5+
throw Error(
6+
`Couldn't find any resolvers. Please add resolvers to your src/resolvers.js`,
7+
);
8+
}
9+
10+
const server = new ApolloServer({
11+
...config,
12+
context,
13+
typeDefs,
14+
resolvers,
15+
});
16+
17+
server
18+
.listen({ port: 4000 })
19+
.then(({ url }) => console.log(`🚀 Server ready at ${url}`));
20+
21+
export default server;

lib/srcFiles.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const importFirst = req =>
2+
req.keys().map(mod => req(mod).default || req(mod))[0];
3+
4+
// Optionally import modules
5+
export const config = importFirst(
6+
require.context(
7+
process.env.GRAPHPACK_SRC_DIR,
8+
true,
9+
/^\.\/(config|config\/index)\.(js|ts)$/,
10+
),
11+
);
12+
export const context = importFirst(
13+
require.context(
14+
process.env.GRAPHPACK_SRC_DIR,
15+
true,
16+
/^\.\/(context|context\/index)\.(js|ts)$/,
17+
),
18+
);
19+
export const resolvers = importFirst(
20+
require.context(
21+
process.env.GRAPHPACK_SRC_DIR,
22+
true,
23+
/^\.\/(resolvers|resolvers\/index)\.(js|ts)$/,
24+
),
25+
);
26+
export const typeDefs = importFirst(
27+
require.context(
28+
process.env.GRAPHPACK_SRC_DIR,
29+
true,
30+
/^\.\/(schema|schema\/index)\.(graphql|js|ts)$/,
31+
),
32+
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bin": {
77
"graphpack": "./bin/graphpack.js"
88
},
9-
"main": "server",
9+
"main": "lib/server",
1010
"dependencies": {
1111
"@babel/core": "^7.1.2",
1212
"@babel/plugin-syntax-dynamic-import": "^7.0.0",

server.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)