Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Contributing to graphql-js
==========================
# Contributing to graphql-js

We want to make contributing to this project as easy and transparent as
possible. Hopefully this document makes the process for contributing clear and
Expand Down Expand Up @@ -80,12 +79,12 @@ This will watch the file system run any relevant lint, tests, and type checks au

## Release on NPM

*Only core contributors may release to NPM.*
_Only core contributors may release to NPM._

To release a new version on NPM, first ensure all tests pass with `npm test`,
then use `npm version patch|minor|major` in order to increment the version in
package.json and tag and commit a release. Then `git push && git push --tags`
this change so Travis CI can deploy to NPM. *Do not run `npm publish` directly.*
this change so Travis CI can deploy to NPM. _Do not run `npm publish` directly._
Once published, add [release notes](https://github.com/graphql/graphql-js/tags).
Use [semver](http://semver.org/) to determine which version part to increment.

Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ For discussion, join [#graphql on Discord](http://join.reactiflux.com/).

## Technical Preview Contents

This technical preview contains a [draft specification for GraphQL]
(https://github.com/facebook/graphql) and a reference implementation in
This technical preview contains a [draft specification for GraphQL](https://github.com/facebook/graphql) and a reference implementation in
JavaScript that implements that draft, GraphQL.js.

The reference implementation provides base libraries in JavaScript that would
Expand Down Expand Up @@ -71,16 +70,16 @@ import {
GraphQLSchema,
GraphQLObjectType,
GraphQLString
} from 'graphql';
} from "graphql";

var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
name: "RootQueryType",
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'world';
return "world";
}
}
}
Expand All @@ -96,16 +95,14 @@ level [tests](src/__tests__) directory.
Then, serve the result of a query against that type schema.

```js
var query = '{ hello }';
var query = "{ hello }";

graphql(schema, query).then(result => {

// Prints
// {
// data: { hello: "world" }
// }
console.log(result);

});
```

Expand All @@ -114,10 +111,9 @@ first ensure the query is syntactically and semantically valid before executing
it, reporting errors otherwise.

```js
var query = '{ boyhowdy }';
var query = "{ boyhowdy }";

graphql(schema, query).then(result => {

// Prints
// {
// errors: [
Expand All @@ -126,7 +122,6 @@ graphql(schema, query).then(result => {
// ]
// }
console.log(result);

});
```

Expand Down
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
"url": "http://github.com/graphql/graphql-js.git"
},
"options": {
"mocha": "--require ./resources/mocha-bootload --check-leaks --full-trace src/**/__tests__/**/*-test.js"
"mocha":
"--require ./resources/mocha-bootload --check-leaks --full-trace src/**/__tests__/**/*-test.js"
},
"babel": {
"presets": [
"es2015"
],
"presets": ["es2015"],
"plugins": [
"syntax-async-functions",
"transform-class-properties",
Expand All @@ -35,15 +34,21 @@
},
"scripts": {
"test": "npm run lint && npm run check && npm run testonly",
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
"t": "babel-node ./node_modules/.bin/_mocha --require ./resources/mocha-bootload",
"testonly":
"babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
"t":
"babel-node ./node_modules/.bin/_mocha --require ./resources/mocha-bootload",
"lint": "eslint src",
"check": "flow check",
"check-cover": "for file in {src/*.js,src/**/*.js}; do echo $file; flow coverage $file; done",
"build": "babel src --ignore __tests__ --out-dir dist/ && cp package.json dist/",
"check-cover":
"for file in {src/*.js,src/**/*.js}; do echo $file; flow coverage $file; done",
"build":
"babel src --ignore __tests__ --out-dir dist/ && cp package.json dist/",
"watch": "babel-node ./resources/watch.js",
"cover": "babel-node ./node_modules/.bin/isparta cover --root src --report html _mocha -- $npm_package_options_mocha",
"cover:lcov": "babel-node ./node_modules/.bin/isparta cover --root src --report lcovonly _mocha -- $npm_package_options_mocha",
"cover":
"babel-node ./node_modules/.bin/isparta cover --root src --report html _mocha -- $npm_package_options_mocha",
"cover:lcov":
"babel-node ./node_modules/.bin/isparta cover --root src --report lcovonly _mocha -- $npm_package_options_mocha",
"preversion": ". ./resources/checkgit.sh && npm test",
"prepublish": ". ./resources/prepublish.sh"
},
Expand Down
10 changes: 5 additions & 5 deletions resources/mocha-bootload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

var chai = require('chai');
var chai = require("chai");

var chaiSubset = require('chai-subset');
var chaiSubset = require("chai-subset");
chai.use(chaiSubset);

process.on('unhandledRejection', function (error) {
console.error('Unhandled Promise Rejection:');
console.error(error && error.stack || error);
process.on("unhandledRejection", function(error) {
console.error("Unhandled Promise Rejection:");
console.error((error && error.stack) || error);
});
154 changes: 85 additions & 69 deletions resources/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,46 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

import sane from 'sane';
import { resolve as resolvePath } from 'path';
import { spawn } from 'child_process';
import flowBinPath from 'flow-bin';
import sane from "sane";
import { resolve as resolvePath } from "path";
import { spawn } from "child_process";
import flowBinPath from "flow-bin";


process.env.PATH += ':./node_modules/.bin';
process.env.PATH += ":./node_modules/.bin";

var cmd = resolvePath(__dirname);
var srcDir = resolvePath(cmd, '../src');
var srcDir = resolvePath(cmd, "../src");

function exec(command, options) {
return new Promise((resolve, reject) => {
var child = spawn(command, options, {
cmd: cmd,
env: process.env,
stdio: 'inherit'
stdio: "inherit"
});
child.on('exit', code => {
child.on("exit", code => {
if (code === 0) {
resolve(true);
} else {
reject(new Error('Error code: ' + code));
reject(new Error("Error code: " + code));
}
});
});
}

var flowServer = spawn(flowBinPath, ['server'], {
var flowServer = spawn(flowBinPath, ["server"], {
cmd: cmd,
env: process.env
});

var watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] })
.on('ready', startWatch)
.on('add', changeFile)
.on('delete', deleteFile)
.on('change', changeFile);
var watcher = sane(srcDir, { glob: ["**/*.js", "**/*.graphql"] })
.on("ready", startWatch)
.on("add", changeFile)
.on("delete", deleteFile)
.on("change", changeFile);

process.on('SIGINT', () => {
console.log(CLEARLINE + yellow(invert('stopped watching')));
process.on("SIGINT", () => {
console.log(CLEARLINE + yellow(invert("stopped watching")));
watcher.close();
flowServer.kill();
process.exit();
Expand All @@ -59,7 +58,7 @@ var toCheck = {};
var timeout;

function startWatch() {
process.stdout.write(CLEARSCREEN + green(invert('watching...')));
process.stdout.write(CLEARSCREEN + green(invert("watching...")));
}

function changeFile(filepath, root, stat) {
Expand Down Expand Up @@ -95,73 +94,90 @@ function guardedCheck() {
}

function checkFiles(filepaths) {
console.log('\u001b[2J');
console.log("\u001b[2J");

return parseFiles(filepaths)
.then(() => runTests(filepaths))
.then(testSuccess => lintFiles(filepaths)
.then(lintSuccess => typecheckStatus()
.then(typecheckSuccess =>
testSuccess && lintSuccess && typecheckSuccess)))
.then(testSuccess =>
lintFiles(filepaths).then(lintSuccess =>
typecheckStatus().then(
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess
)
)
)
.catch(() => false)
.then(success => {
process.stdout.write(
'\n' + (success ? '' : '\x07') + green(invert('watching...'))
"\n" + (success ? "" : "\x07") + green(invert("watching..."))
);
});
}

// Checking steps

function parseFiles(filepaths) {
console.log('Checking Syntax');

return Promise.all(filepaths.map(filepath => {
if (isJS(filepath) && !isTest(filepath)) {
return exec('babel', [
'--optional', 'runtime',
'--out-file', '/dev/null',
srcPath(filepath)
]);
}
}));
console.log("Checking Syntax");

return Promise.all(
filepaths.map(filepath => {
if (isJS(filepath) && !isTest(filepath)) {
return exec("babel", [
"--optional",
"runtime",
"--out-file",
"/dev/null",
srcPath(filepath)
]);
}
})
);
}

function runTests(filepaths) {
console.log('\nRunning Tests');

return exec('babel-node', [
'./node_modules/.bin/_mocha',
'--reporter', 'progress',
'--require', './resources/mocha-bootload',
].concat(
allTests(filepaths) ?
filepaths.map(srcPath) :
['src/**/__tests__/**/*-test.js']
)).catch(() => false);
console.log("\nRunning Tests");

return exec(
"babel-node",
[
"./node_modules/.bin/_mocha",
"--reporter",
"progress",
"--require",
"./resources/mocha-bootload"
].concat(
allTests(filepaths)
? filepaths.map(srcPath)
: ["src/**/__tests__/**/*-test.js"]
)
).catch(() => false);
}

function lintFiles(filepaths) {
console.log('Linting Code\n');

return filepaths.reduce((prev, filepath) => prev.then(prevSuccess => {
if (isJS(filepath)) {
process.stdout.write(' ' + filepath + ' ...');
return exec('eslint', [srcPath(filepath)])
.catch(() => false)
.then(success => {
console.log(CLEARLINE + ' ' + (success ? CHECK : X)
+ ' ' + filepath);
return prevSuccess && success;
});
}
return prevSuccess;
}), Promise.resolve(true));
console.log("Linting Code\n");

return filepaths.reduce(
(prev, filepath) =>
prev.then(prevSuccess => {
if (isJS(filepath)) {
process.stdout.write(" " + filepath + " ...");
return exec("eslint", [srcPath(filepath)])
.catch(() => false)
.then(success => {
console.log(
CLEARLINE + " " + (success ? CHECK : X) + " " + filepath
);
return prevSuccess && success;
});
}
return prevSuccess;
}),
Promise.resolve(true)
);
}

function typecheckStatus() {
console.log('\nType Checking\n');
return exec(flowBinPath, ['status']).catch(() => false);
console.log("\nType Checking\n");
return exec(flowBinPath, ["status"]).catch(() => false);
}

// Filepath
Expand All @@ -173,7 +189,7 @@ function srcPath(filepath) {
// Predicates

function isJS(filepath) {
return filepath.indexOf('.js') === filepath.length - 3;
return filepath.indexOf(".js") === filepath.length - 3;
}

function allTests(filepaths) {
Expand All @@ -188,10 +204,10 @@ function isTest(filepath) {

// Print helpers

var CLEARSCREEN = '\u001b[2J';
var CLEARLINE = '\r\x1B[K';
var CHECK = green('\u2713');
var X = red('\u2718');
var CLEARSCREEN = "\u001b[2J";
var CLEARLINE = "\r\x1B[K";
var CHECK = green("\u2713");
var X = red("\u2718");

function invert(str) {
return `\u001b[7m ${str} \u001b[27m`;
Expand Down
3 changes: 1 addition & 2 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
GraphQL JS
----------
## GraphQL JS

The primary `graphql` module includes everything you need to define a GraphQL
schema and fulfill GraphQL requests.
Expand Down
Loading