Skip to content

Commit e2c51ab

Browse files
committed
graphql-server
2017-06-01 ------------------------------------------------------ * Adds `graphql-server` example
1 parent 3a156e1 commit e2c51ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+10861
-0
lines changed

Diff for: .editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[*]
2+
indent_style = space
3+
end_of_line = lf
4+
indent_size = 2
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.md]
10+
max_line_length = 0
11+
trim_trailing_whitespace = false

Diff for: .gitignore

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Meta
2+
**/.DS_Store
3+
4+
# Logs
5+
**/logs
6+
**/*.log
7+
**/npm-debug.log*
8+
9+
# Runtime data
10+
**/pids
11+
**/*.pid
12+
**/*.seed
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
**/lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
**/coverage
19+
20+
# nyc test coverage
21+
**/.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
**/.grunt
25+
26+
# node-waf configuration
27+
**/.lock-wscript
28+
29+
# Compiled binary addons (http://nodejs.org/api/addons.html)
30+
**/build/Release
31+
32+
# Dependency directories
33+
**/node_modules
34+
**/jspm_packages
35+
36+
# Optional npm cache directory
37+
**/.npm
38+
39+
# Optional REPL history
40+
**/.node_repl_history
41+
42+
# Distribution
43+
**/dist

Diff for: CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2017-06-01
2+
------------------------------------------------------
3+
* Adds `graphql-server` example

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Lee Benson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ This flexibility makes the kit ideal for a variety of use cases -- from building
1212

1313
This repo features a growing list of runnable examples to demonstrate how ReactQL can be used.
1414

15+
## Projects
16+
17+
Current example projects:
18+
19+
### [GraphQL Server (graphql-server)](https://github.com/reactql/examples/blob/master/graphql-server)
20+
21+
Swaps out the [Graphcool](https://graph.cool) service for your own GraphQL server, running alongside the built-in Koa web server. Demonstrates a monolithic application, where the GraphQL endpoint 'lives' next to your front-end code.
22+
1523
## How to run
1624

1725
Each project appears in its own folder.

Diff for: graphql-server/.babelrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"node": true
6+
}
7+
}]
8+
]
9+
}

Diff for: graphql-server/.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[*]
2+
indent_style = space
3+
end_of_line = lf
4+
indent_size = 2
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.md]
10+
max_line_length = 0
11+
trim_trailing_whitespace = false

Diff for: graphql-server/.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

Diff for: graphql-server/.eslintrc.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const path = require('path');
2+
const baseRules = require('eslint-config-airbnb-base/rules/style');
3+
const [_, ...restricted] = baseRules.rules['no-restricted-syntax'];
4+
5+
const PATHS = require('./config/paths');
6+
7+
module.exports = {
8+
extends: 'airbnb',
9+
parser: 'babel-eslint',
10+
parserOptions: {
11+
ecmaVersion: 2017,
12+
sourceType: 'module',
13+
jsx: true,
14+
},
15+
env: {
16+
node: true,
17+
browser: true,
18+
},
19+
plugins: [
20+
'babel',
21+
'import',
22+
'jsx-a11y',
23+
'compat',
24+
],
25+
rules: {
26+
'arrow-parens': ['error', 'as-needed'],
27+
'react/forbid-prop-types': [1, { forbid: ['any']} ],
28+
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
29+
'react/prefer-stateless-function': [2, { ignorePureComponents: true }],
30+
'react/no-multi-comp': 0,
31+
'react/jsx-closing-bracket-location': [1, 'after-props'],
32+
'linebreak-style': 0,
33+
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
34+
'no-restricted-syntax': [2,
35+
...restricted.filter(
36+
r => !['ForOfStatement'].includes(r.selector)
37+
),
38+
],
39+
'global-require': 0,
40+
'import/no-unresolved': [2, { commonjs: true }],
41+
'compat/compat': 2
42+
},
43+
settings: {
44+
'import/resolver': {
45+
node: {
46+
paths: [
47+
PATHS.root,
48+
'node_modules',
49+
],
50+
},
51+
},
52+
},
53+
globals: {
54+
SERVER: false,
55+
},
56+
};

Diff for: graphql-server/.gitignore

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Meta
2+
**/.DS_Store
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# node-waf configuration
27+
.lock-wscript
28+
29+
# Compiled binary addons (http://nodejs.org/api/addons.html)
30+
build/Release
31+
32+
# Dependency directories
33+
node_modules
34+
jspm_packages
35+
36+
# Optional npm cache directory
37+
.npm
38+
39+
# Optional REPL history
40+
.node_repl_history
41+
42+
# Distribution
43+
dist

Diff for: graphql-server/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<img src="https://reactql.org/docs/images/reactql-logo.svg" alt="ReactQL" width="278" height="77" />
2+
3+
# ReactQL: GraphQL server example
4+
5+
In this example, we swap out the [Graphcool](https://www.graph.cool/) GraphQL server, and instead run our own - directly within your bundled ReactQL web server.
6+
7+
This use case might be useful if:
8+
9+
* You want to build a monolithic application (i.e. keep everything under one code base)
10+
* You want to own the GraphQL infrastructure, end-to-end
11+
* You want to call internal server-side functions, as a means to replace REST
12+
13+
## Kit version
14+
15+
Built using ReactQL [Javascript kit](https://github.com/reactql/kit), [v1.5.1](https://github.com/reactql/kit/releases/tag/1.5.1)
16+
17+
## Running locally
18+
19+
First, install NPM packages with `npm i` or `yarn`.
20+
21+
Then, run:
22+
23+
`npm start`
24+
25+
You can then navigate to [http://localhost:8080](http://localhost:8080) to see a hot-reloading browser version, [http://localhost:8081](http://localhost:8081) for a development web server with full [server-side rendering](https://reactql.org/docs/ssr), and [http://localhost:8081/graphql](http://localhost:8081/graphql) for the GraphiQL utility to test GraphQL queries.
26+
27+
For more build options, see the [root examples README](https://github.com/reactql/examples)

Diff for: graphql-server/browerslist

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# By default, target only modern browsers
2+
3+
last 3 versions

Diff for: graphql-server/config/paths.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ----------------------
2+
// IMPORTS
3+
4+
const path = require('path');
5+
6+
// ----------------------
7+
8+
// Parent folder = project root
9+
const root = path.join(__dirname, '..');
10+
11+
module.exports = {
12+
// Root project folder. This is the current dir.
13+
root,
14+
15+
// Kit. ReactQL starter kit code. You can edit these files, but be
16+
// aware that upgrading your starter kit could overwrite them
17+
kit: path.join(root, 'kit'),
18+
19+
// Entry points. This is where webpack will look for our browser.js,
20+
// server.js and vendor.js files to start building
21+
entry: path.join(root, 'kit', 'entry'),
22+
23+
// Webpack configuration files
24+
webpack: path.join(root, 'kit', 'webpack'),
25+
26+
// Views for internal use
27+
views: path.join(root, 'kit', 'views'),
28+
29+
// Source path; where we'll put our application files
30+
src: path.join(root, 'src'),
31+
32+
// Static files. HTML, images, etc that can be processed by Webpack
33+
// before being moved into the final `dist` folder
34+
static: path.join(root, 'static'),
35+
36+
// Dist path; where bundled assets will wind up
37+
dist: path.join(root, 'dist'),
38+
39+
// Dist path for development; where dev assets will wind up
40+
distDev: path.resolve(root, 'dist', 'dev'),
41+
42+
// Public. This is where our web server will start looking to serve
43+
// static files from
44+
public: path.join(root, 'dist', 'public'),
45+
};

Diff for: graphql-server/config/project.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable import/prefer-default-export */
2+
3+
// ----------------------
4+
// IMPORTS
5+
6+
/* Local */
7+
import {
8+
getServerHost,
9+
getServerPort,
10+
} from 'kit/lib/env';
11+
12+
// ----------------------
13+
14+
export const APOLLO = {
15+
uri: `http://${getServerHost()}:${getServerPort()}/graphql`,
16+
};
17+
18+
export const BUNDLE_ANALYZER = {
19+
openAnalyzer: false,
20+
};

0 commit comments

Comments
 (0)