Skip to content

Commit 64474ee

Browse files
authored
Merge pull request #7 from graphql/master
Add 'isRequredArgument' & 'isRequredInputField' predicates (graphql#1465)
2 parents 67f232f + 76e37d5 commit 64474ee

24 files changed

+612
-620
lines changed

.babelrc.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
module.exports = {
22
"presets": [["@babel/preset-env", {
33
"modules": process.env.BABEL_MODULES ? false : 'commonjs',
4-
"targets": {
5-
"node": 6,
6-
"browsers": [
7-
"ie 9",
8-
"ios 9",
9-
"last 2 chrome versions",
10-
"last 2 edge versions",
11-
"last 2 firefox versions",
12-
]
13-
}
4+
"targets": [
5+
"node 6",
6+
"ie 9",
7+
"ios 9",
8+
"last 2 chrome versions",
9+
"last 2 edge versions",
10+
"last 2 firefox versions",
11+
],
1412
}]],
1513
"plugins": [
1614
"./resources/inline-invariant",

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)?)\\)
1313
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)?)\\)?:? #[0-9]+
1414

1515
[version]
16-
^0.78.0
16+
^0.79.0

package.json

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"type": "git",
1515
"url": "http://github.com/graphql/graphql-js.git"
1616
},
17-
"options": {
18-
"mocha": "--check-leaks --full-trace --timeout 15000 src/**/__tests__/**/*-test.js"
19-
},
2017
"engines": {
2118
"node": "6.x || 8.x || >= 10.x"
2219
},
@@ -48,30 +45,30 @@
4845
"iterall": "^1.2.2"
4946
},
5047
"devDependencies": {
51-
"@babel/cli": "7.0.0-beta.56",
52-
"@babel/core": "7.0.0-beta.56",
53-
"@babel/plugin-proposal-class-properties": "7.0.0-beta.56",
54-
"@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.56",
55-
"@babel/plugin-syntax-async-generators": "7.0.0-beta.56",
56-
"@babel/plugin-transform-classes": "7.0.0-beta.56",
57-
"@babel/plugin-transform-destructuring": "7.0.0-beta.56",
58-
"@babel/plugin-transform-flow-strip-types": "7.0.0-beta.56",
59-
"@babel/plugin-transform-spread": "7.0.0-beta.56",
60-
"@babel/polyfill": "7.0.0-beta.56",
61-
"@babel/preset-env": "7.0.0-beta.56",
62-
"@babel/register": "7.0.0-beta.56",
48+
"@babel/cli": "7.0.0-rc.3",
49+
"@babel/core": "7.0.0-rc.3",
50+
"@babel/plugin-proposal-class-properties": "7.0.0-rc.3",
51+
"@babel/plugin-proposal-object-rest-spread": "7.0.0-rc.3",
52+
"@babel/plugin-syntax-async-generators": "7.0.0-rc.3",
53+
"@babel/plugin-transform-classes": "7.0.0-rc.3",
54+
"@babel/plugin-transform-destructuring": "7.0.0-rc.3",
55+
"@babel/plugin-transform-flow-strip-types": "7.0.0-rc.3",
56+
"@babel/plugin-transform-spread": "7.0.0-rc.3",
57+
"@babel/polyfill": "7.0.0-rc.3",
58+
"@babel/preset-env": "7.0.0-rc.3",
59+
"@babel/register": "7.0.0-rc.3",
6360
"babel-eslint": "8.2.6",
6461
"beautify-benchmark": "0.2.4",
6562
"benchmark": "2.1.4",
6663
"chai": "4.1.2",
6764
"coveralls": "3.0.2",
68-
"eslint": "5.3.0",
65+
"eslint": "5.4.0",
6966
"eslint-plugin-flowtype": "2.50.0",
7067
"eslint-plugin-prettier": "2.6.2",
71-
"flow-bin": "0.78.0",
68+
"flow-bin": "0.79.1",
7269
"mocha": "5.2.0",
7370
"nyc": "12.0.2",
74-
"prettier": "1.14.0",
71+
"prettier": "1.14.2",
7572
"sane": "3.0.0"
7673
}
7774
}

resources/benchmark.js

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ const { Suite } = require('benchmark');
99
const beautifyBenchmark = require('beautify-benchmark');
1010
const { execSync } = require('child_process');
1111
const os = require('os');
12+
const fs = require('fs');
1213
const path = require('path');
1314

1415
// Like build:cjs, but includes __tests__ and copies other files.
1516
const BUILD_CMD = 'babel src --optional runtime --copy-files --out-dir dist/';
1617
const LOCAL = 'local';
17-
const LOCAL_DIR = path.join(__dirname, '../');
18-
const TEMP_DIR = os.tmpdir();
18+
function LOCAL_DIR(...paths) {
19+
return path.join(__dirname, '..', ...paths);
20+
}
21+
function TEMP_DIR(...paths) {
22+
return path.join(os.tmpdir(), 'graphql-js-benchmark', ...paths);
23+
}
1924

2025
// Returns the complete git hash for a given git revision reference.
2126
function hashForRevision(revision) {
22-
if (revision === LOCAL) {
23-
return revision;
24-
}
2527
const out = execSync(`git rev-parse "${revision}"`, { encoding: 'utf8' });
2628
const match = /[0-9a-f]{8,40}/.exec(out);
2729
if (!match) {
@@ -30,54 +32,48 @@ function hashForRevision(revision) {
3032
return match[0];
3133
}
3234

33-
// Returns the temporary directory which hosts the files for this git hash.
34-
function dirForHash(hash) {
35-
if (hash === LOCAL) {
36-
return path.join(__dirname, '../');
37-
}
38-
return path.join(TEMP_DIR, 'graphql-js-benchmark', hash);
39-
}
40-
41-
// Build a benchmarkable environment for the given revision.
35+
// Build a benchmarkable environment for the given revision
36+
// and returns path to its 'dist' directory.
4237
function prepareRevision(revision) {
4338
console.log(`🍳 Preparing ${revision}...`);
44-
const hash = hashForRevision(revision);
45-
const dir = dirForHash(hash);
46-
if (hash === LOCAL) {
47-
execSync(`(cd "${dir}" && yarn run ${BUILD_CMD})`);
39+
40+
if (revision === LOCAL) {
41+
execSync(`yarn run ${BUILD_CMD}`);
42+
return LOCAL_DIR('dist');
4843
} else {
49-
execSync(`
50-
if [ ! -d "${dir}" ]; then
51-
mkdir -p "${dir}" &&
52-
git archive "${hash}" | tar -xC "${dir}" &&
53-
(cd "${dir}" && yarn install);
54-
fi &&
55-
# Copy in local tests so the same logic applies to each revision.
56-
for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*');
57-
do cp "${LOCAL_DIR}src/$file" "${dir}/src/$file";
58-
done &&
59-
(cd "${dir}" && yarn run ${BUILD_CMD})
60-
`);
44+
if (!fs.existsSync(TEMP_DIR())) {
45+
fs.mkdirSync(TEMP_DIR());
46+
}
47+
48+
const hash = hashForRevision(revision);
49+
const dir = TEMP_DIR(hash);
50+
51+
if (!fs.existsSync(dir)) {
52+
fs.mkdirSync(dir);
53+
execSync(`git archive "${hash}" | tar -xC "${dir}"`);
54+
execSync('yarn install', { cwd: dir });
55+
}
56+
for (const file of findFiles(LOCAL_DIR('src'), '*/__tests__/*')) {
57+
const from = LOCAL_DIR('src', file);
58+
const to = path.join(dir, 'src', file);
59+
fs.copyFileSync(from, to);
60+
}
61+
execSync(`cp -R "${LOCAL_DIR()}/src/__fixtures__/" "${dir}/src/__fixtures__/"`);
62+
execSync(`yarn run ${BUILD_CMD}`, { cwd: dir });
63+
64+
return path.join(dir, 'dist');
6165
}
6266
}
6367

64-
// Find all benchmark tests to be run.
65-
function findBenchmarks() {
66-
const out = execSync(
67-
`(cd ${LOCAL_DIR}src; find . -path '*/__tests__/*-benchmark.js')`,
68-
{ encoding: 'utf8' },
69-
);
68+
function findFiles(cwd, pattern) {
69+
const out = execSync(`find . -path '${pattern}'`, { cwd, encoding: 'utf8' });
7070
return out.split('\n').filter(Boolean);
7171
}
7272

7373
// Run a given benchmark test with the provided revisions.
74-
function runBenchmark(benchmark, revisions) {
75-
const modules = revisions.map(revision =>
76-
require(path.join(
77-
dirForHash(hashForRevision(revision)),
78-
'dist',
79-
benchmark,
80-
)),
74+
function runBenchmark(benchmark, enviroments) {
75+
const modules = enviroments.map(({distPath}) =>
76+
require(path.join(distPath, benchmark)),
8177
);
8278
const suite = new Suite(modules[0].name, {
8379
onStart(event) {
@@ -94,28 +90,36 @@ function runBenchmark(benchmark, revisions) {
9490
beautifyBenchmark.log();
9591
},
9692
});
97-
for (let i = 0; i < revisions.length; i++) {
98-
suite.add(revisions[i], modules[i].measure);
93+
for (let i = 0; i < enviroments.length; i++) {
94+
suite.add(enviroments[i].revision, modules[i].measure);
9995
}
10096
suite.run({ async: false });
10197
}
10298

10399
// Prepare all revisions and run benchmarks matching a pattern against them.
104100
function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
105-
const benchmarks = findBenchmarks().filter(
106-
benchmark =>
107-
benchmarkPatterns.length === 0 ||
108-
benchmarkPatterns.some(pattern => benchmark.indexOf(pattern) !== -1),
109-
);
101+
// Find all benchmark tests to be run.
102+
let benchmarks = findFiles(LOCAL_DIR('src'), '*/__tests__/*-benchmark.js');
103+
if (benchmarkPatterns.length !== 0) {
104+
benchmarks = benchmarks.filter(
105+
benchmark => benchmarkPatterns.some(
106+
pattern => path.join('src', benchmark).includes(pattern)
107+
),
108+
);
109+
}
110+
110111
if (benchmarks.length === 0) {
111112
console.warn(
112113
'No benchmarks matching: ' +
113114
`\u001b[1m${benchmarkPatterns.join('\u001b[0m or \u001b[1m')}\u001b[0m`,
114115
);
115116
return;
116117
}
117-
revisions.forEach(revision => prepareRevision(revision));
118-
benchmarks.forEach(benchmark => runBenchmark(benchmark, revisions));
118+
119+
const enviroments = revisions.map(
120+
revision => ({ revision, distPath: prepareRevision(revision)})
121+
);
122+
benchmarks.forEach(benchmark => runBenchmark(benchmark, enviroments));
119123
}
120124

121125
function getArguments(argv) {

src/__fixtures__/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { join } from 'path';
2+
import { readFileSync } from 'fs';
3+
4+
function readLocalFile(filename) {
5+
return readFileSync(join(__dirname, filename), 'utf8');
6+
}
7+
8+
export const bigSchemaSDL = readLocalFile('github-schema.graphql');
9+
export const bigSchemaIntrospectionResult = JSON.parse(
10+
readLocalFile('github-schema.json'),
11+
);

src/__tests__/starWarsData.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,23 @@ export type Character = {
100100
appearsIn: Array<number>,
101101
};
102102

103-
export type Human = {
103+
export type Human = {|
104104
type: 'Human',
105105
id: string,
106106
name: string,
107107
friends: Array<string>,
108108
appearsIn: Array<number>,
109109
homePlanet: string,
110-
};
110+
|};
111111

112-
export type Droid = {
112+
export type Droid = {|
113113
type: 'Droid',
114114
id: string,
115115
name: string,
116116
friends: Array<string>,
117117
appearsIn: Array<number>,
118118
primaryFunction: string,
119-
};
119+
|};
120120

121121
/**
122122
* Helper function to get a character by ID.

src/execution/execute.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import type {
9494
* Namely, schema of the type system that is currently executing,
9595
* and the fragments defined in the query document
9696
*/
97-
export type ExecutionContext = {
97+
export type ExecutionContext = {|
9898
schema: GraphQLSchema,
9999
fragments: ObjMap<FragmentDefinitionNode>,
100100
rootValue: mixed,
@@ -103,7 +103,7 @@ export type ExecutionContext = {
103103
variableValues: { [variable: string]: mixed },
104104
fieldResolver: GraphQLFieldResolver<any, any>,
105105
errors: Array<GraphQLError>,
106-
};
106+
|};
107107

108108
/**
109109
* The result of GraphQL execution.

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export {
9898
isWrappingType,
9999
isNullableType,
100100
isNamedType,
101+
isRequiredArgument,
102+
isRequiredInputField,
101103
isSpecifiedScalarType,
102104
isIntrospectionType,
103105
isSpecifiedDirective,

0 commit comments

Comments
 (0)