Skip to content

Commit 4b07386

Browse files
committed
Initial commit
0 parents  commit 4b07386

File tree

12 files changed

+5527
-0
lines changed

12 files changed

+5527
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
node_modules
3+
yarn-error.log

.huskyrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
hooks: {
3+
'pre-commit': 'lint-staged',
4+
},
5+
};

.lintstagedrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'*.{js,json,md}': ['prettier --write', 'git add'],
3+
};

.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
singleQuote: true,
3+
trailingComma: 'all',
4+
};

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# graphpack
2+
3+
A minimalistic zero-config GraphQL server
4+
5+
## What is included
6+
7+
tbd
8+
9+
## Install
10+
11+
With yarn:
12+
13+
```
14+
yarn add graphpack
15+
```
16+
17+
With npm:
18+
19+
```
20+
npm install graphpack
21+
```
22+
23+
## Usage
24+
25+
Add following run script to your `package.json`:
26+
27+
```json
28+
"scripts": {
29+
"start": "graphpack"
30+
},
31+
```
32+
33+
Add your type definitions under `src/schema.graphql` and add some example types in [SDL](https://graphql.org/learn/schema/#type-language):
34+
35+
```graphql
36+
type Query {
37+
hello: String
38+
}
39+
```
40+
41+
Add your resolvers under `src/resolvers.js`:
42+
43+
```js
44+
const resolvers = {
45+
Query: {
46+
hello: () => 'world!',
47+
},
48+
};
49+
50+
export default resolvers;
51+
```
52+
53+
> If you prefer to write the type definitions in JS and parse the queries with [graphql-tag](https://github.com/apollographql/graphql-tag), just save your schema as a JS file under `src/schema.js`. It's also possible to create separate folders `src/schema/index.js` and `src/resolvers/index.js`.

babel.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = () => ({
2+
plugins: ['@babel/plugin-syntax-dynamic-import'],
3+
presets: [
4+
['@babel/preset-env', { targets: { node: 'current' }, modules: false }],
5+
],
6+
});

bin/graphpack

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
const nodemon = require('nodemon');
4+
const path = require('path');
5+
const { once } = require('ramda');
6+
const webpack = require('webpack');
7+
const paths = require('../config/paths');
8+
const webpackConfig = require('../config/webpack.config');
9+
10+
const compiler = webpack(webpackConfig);
11+
const serverPaths = Object.keys(compiler.options.entry).map(entry =>
12+
path.join(compiler.options.output.path, `${entry}.js`),
13+
);
14+
15+
compiler.watch(
16+
webpackConfig.watchOptions,
17+
once(error => {
18+
if (error) return;
19+
20+
nodemon({ script: serverPaths[0], watch: serverPaths }).on(
21+
'quit',
22+
process.exit,
23+
);
24+
}),
25+
);

config/paths.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const path = require('path');
2+
const rootPath = path.resolve(process.cwd());
3+
const buildPath = path.join(rootPath, 'build');
4+
const publicBuildPath = path.join(buildPath, 'public');
5+
6+
module.exports = {
7+
rootPath,
8+
buildPath,
9+
publicBuildPath,
10+
publicSrcPath: path.join(rootPath, 'public'),
11+
serverSrcPath: path.join(rootPath, 'src'),
12+
serverBuildPath: buildPath,
13+
userNodeModulesPath: path.join(rootPath, 'node_modules'),
14+
publicPath: '/',
15+
serverUrl: 'http://localhost:3000',
16+
};

config/webpack.config.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
2+
const path = require('path');
3+
const nodeExternals = require('webpack-node-externals');
4+
5+
console.log(require.resolve('babel-loader'));
6+
7+
module.exports = {
8+
entry: {
9+
// We take care of setting up the server under ./server.js
10+
index: ['graphpack'],
11+
},
12+
// When bundling with Webpack for the backend you usually don't want to bundle
13+
// its node_modules dependencies. This creates an externals function that
14+
// ignores node_modules when bundling in Webpack.
15+
externals: [nodeExternals({ whitelist: [/^graphpack$/] })],
16+
mode: 'development',
17+
module: {
18+
rules: [
19+
{
20+
test: /\.graphql/,
21+
use: 'graphql-tag/loader',
22+
},
23+
{
24+
test: /\.js$/,
25+
use: [
26+
{
27+
loader: require.resolve('babel-loader'),
28+
options: {
29+
babelrc: true,
30+
cacheDirectory: true,
31+
presets: [require.resolve('../babel')],
32+
},
33+
},
34+
],
35+
},
36+
{
37+
test: /\.mjs$/,
38+
type: 'javascript/auto',
39+
},
40+
],
41+
},
42+
optimization: { noEmitOnErrors: true },
43+
output: {
44+
filename: '[name].js',
45+
libraryTarget: 'commonjs2',
46+
path: path.join(process.cwd(), './build'),
47+
sourceMapFilename: '[name].map',
48+
},
49+
plugins: [new FriendlyErrorsWebpackPlugin({ clearConsole: false })],
50+
resolve: {
51+
alias: { __GRAPHPACK_SRC__: path.resolve(process.cwd(), 'src') },
52+
extensions: ['.wasm', '.js', '.mjs', '.json', '.graphql'],
53+
},
54+
stats: 'minimal',
55+
target: 'node',
56+
};

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "graphpack",
3+
"version": "0.0.1-4",
4+
"description": "☄️ A minimalistic zero-config GraphQL server",
5+
"license": "MIT",
6+
"bin": {
7+
"graphpack": "./bin/graphpack"
8+
},
9+
"main": "server",
10+
"dependencies": {
11+
"@babel/core": "^7.1.2",
12+
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
13+
"@babel/preset-env": "^7.1.0",
14+
"apollo-server": "2.0.0",
15+
"babel-loader": "^8.0.4",
16+
"friendly-errors-webpack-plugin": "^1.7.0",
17+
"graphql": "^0.13.2",
18+
"graphql-tag": "^2.9.2",
19+
"nodemon": "^1.18.4",
20+
"ramda": "^0.25.0",
21+
"webpack": "^4.20.2",
22+
"webpack-node-externals": "^1.7.2"
23+
},
24+
"devDependencies": {
25+
"husky": "^1.0.1",
26+
"lint-staged": "^7.3.0",
27+
"prettier": "^1.14.3"
28+
}
29+
}

0 commit comments

Comments
 (0)