Skip to content

Commit

Permalink
Merge branch 'master' into tgriesser/feat/894-context-lifecycle-subsc…
Browse files Browse the repository at this point in the history
…ription

* master:
  v15.0.0
  Update deps (graphql#2502)
  Update Flow (graphql#2500)
  Update prettier (graphql#2499)
  Move custom ESLint rules into internal package (graphql#2498)
  • Loading branch information
tgriesser committed Apr 6, 2020
2 parents 1d0b6af + 278bde0 commit 27fb3f3
Show file tree
Hide file tree
Showing 98 changed files with 11,622 additions and 4,306 deletions.
19 changes: 16 additions & 3 deletions .eslintrc.yml
Expand Up @@ -6,12 +6,20 @@ env:
node: true
reportUnusedDisableDirectives: true
plugins:
- graphql-internal
- flowtype
- import

rules:
##############################################################################
# `eslint-plugin-flowtype` rule list based on `v4.6.x`
# Internal rules located in 'resources/eslint-rules'.
# See './resources/eslint-rules/README.md'
##############################################################################

graphql-internal/no-dir-import: error

##############################################################################
# `eslint-plugin-flowtype` rule list based on `v4.7.x`
# https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype
##############################################################################

Expand Down Expand Up @@ -431,9 +439,10 @@ overrides:
- plugin:import/typescript
rules:
flowtype/require-valid-file-annotation: off
flowtype/no-types-missing-file-annotation: off

##########################################################################
# `@typescript-eslint/eslint-plugin` rule list based on `v2.21.x`
# `@typescript-eslint/eslint-plugin` rule list based on `v2.26.x`
##########################################################################

# Supported Rules
Expand All @@ -443,6 +452,7 @@ overrides:
'@typescript-eslint/await-thenable': error
'@typescript-eslint/ban-ts-comment': error
'@typescript-eslint/ban-types': error
'@typescript-eslint/class-literal-property-style': off
'@typescript-eslint/consistent-type-assertions':
[error, { assertionStyle: as, objectLiteralTypeAssertions: never }]
'@typescript-eslint/consistent-type-definitions': off # TODO consider
Expand Down Expand Up @@ -477,6 +487,9 @@ overrides:
'@typescript-eslint/no-unnecessary-qualifier': error
'@typescript-eslint/no-unnecessary-type-arguments': error
'@typescript-eslint/no-unnecessary-type-assertion': error
'@typescript-eslint/no-unsafe-call': off # TODO consider
'@typescript-eslint/no-unsafe-member-access': off # TODO consider
'@typescript-eslint/no-unsafe-return': off # TODO consider
'@typescript-eslint/no-unused-vars-experimental': off
'@typescript-eslint/no-var-requires': error
'@typescript-eslint/prefer-as-const': off # TODO consider
Expand All @@ -487,7 +500,7 @@ overrides:
'@typescript-eslint/prefer-nullish-coalescing': error
'@typescript-eslint/prefer-optional-chain': error
'@typescript-eslint/prefer-readonly': error
'@typescript-eslint/prefer-readonly-parameter-types': off # FIXME: crash eslint
'@typescript-eslint/prefer-readonly-parameter-types': off # TODO consider
'@typescript-eslint/prefer-regexp-exec': error
'@typescript-eslint/prefer-string-starts-ends-with': off # TODO switch to error after IE11 drop
'@typescript-eslint/promise-function-async': off
Expand Down
2 changes: 1 addition & 1 deletion .flowconfig
Expand Up @@ -40,4 +40,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$DisableFlowOnNegativeTest

[version]
^0.120.0
^0.121.0
3 changes: 1 addition & 2 deletions .prettierrc
@@ -1,5 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "lf"
"trailingComma": "all"
}
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -74,7 +74,7 @@ Then, serve the result of a query against that type schema.
```js
var query = '{ hello }';

graphql(schema, query).then(result => {
graphql(schema, query).then((result) => {
// Prints
// {
// data: { hello: "world" }
Expand All @@ -90,7 +90,7 @@ it, reporting errors otherwise.
```js
var query = '{ BoyHowdy }';

graphql(schema, query).then(result => {
graphql(schema, query).then((result) => {
// Prints
// {
// errors: [
Expand Down
4 changes: 2 additions & 2 deletions docs/Guides-ConstructingTypes.md
Expand Up @@ -41,7 +41,7 @@ var fakeDatabase = {
};

var root = {
user: function({ id }) {
user: function ({ id }) {
return fakeDatabase[id];
},
};
Expand Down Expand Up @@ -98,7 +98,7 @@ var queryType = new graphql.GraphQLObjectType({
args: {
id: { type: graphql.GraphQLString },
},
resolve: function(_, { id }) {
resolve: function (_, { id }) {
return fakeDatabase[id];
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorial-Authentication.md
Expand Up @@ -30,7 +30,7 @@ function loggingMiddleware(req, res, next) {
}

var root = {
ip: function(args, request) {
ip: function (args, request) {
return request.ip;
},
};
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorial-BasicTypes.md
Expand Up @@ -39,7 +39,7 @@ var root = {
return Math.random();
},
rollThreeDice: () => {
return [1, 2, 3].map(_ => 1 + Math.floor(Math.random() * 6));
return [1, 2, 3].map((_) => 1 + Math.floor(Math.random() * 6));
},
};

Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorial-GettingStarted.md
Expand Up @@ -40,7 +40,7 @@ var root = {
};

// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then(response => {
graphql(schema, '{ hello }', root).then((response) => {
console.log(response);
});
```
Expand Down
8 changes: 4 additions & 4 deletions docs/Tutorial-GraphQLClients.md
Expand Up @@ -36,8 +36,8 @@ fetch('/graphql', {
},
body: JSON.stringify({ query: '{ hello }' }),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

You should see the data returned, logged in the console:
Expand Down Expand Up @@ -76,8 +76,8 @@ fetch('/graphql', {
variables: { dice, sides },
}),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

Using this syntax for variables is a good idea because it automatically prevents bugs due to escaping, and it makes it easier to monitor your server.
Expand Down
18 changes: 8 additions & 10 deletions docs/Tutorial-Mutations.md
Expand Up @@ -27,11 +27,11 @@ Both mutations and queries can be handled by root resolvers, so the root that im
```js
var fakeDatabase = {};
var root = {
setMessage: function({ message }) {
setMessage: function ({ message }) {
fakeDatabase.message = message;
return message;
},
getMessage: function() {
getMessage: function () {
return fakeDatabase.message;
},
};
Expand Down Expand Up @@ -112,22 +112,20 @@ class Message {
var fakeDatabase = {};

var root = {
getMessage: function({ id }) {
getMessage: function ({ id }) {
if (!fakeDatabase[id]) {
throw new Error('no message exists with id ' + id);
}
return new Message(id, fakeDatabase[id]);
},
createMessage: function({ input }) {
createMessage: function ({ input }) {
// Create a random id for our "database".
var id = require('crypto')
.randomBytes(10)
.toString('hex');
var id = require('crypto').randomBytes(10).toString('hex');

fakeDatabase[id] = input;
return new Message(id, input);
},
updateMessage: function({ id, input }) {
updateMessage: function ({ id, input }) {
if (!fakeDatabase[id]) {
throw new Error('no message exists with id ' + id);
}
Expand Down Expand Up @@ -188,8 +186,8 @@ fetch('/graphql', {
},
}),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

One particular type of mutation is operations that change users, like signing up a new user. While you can implement this using GraphQL mutations, you can reuse many existing libraries if you learn about [GraphQL with authentication and Express middleware](/graphql-js/authentication-and-express-middleware/).
4 changes: 2 additions & 2 deletions docs/Tutorial-ObjectTypes.md
Expand Up @@ -50,7 +50,7 @@ class RandomDie {
}

var root = {
getDie: function({ numSides }) {
getDie: function ({ numSides }) {
return new RandomDie(numSides || 6);
},
};
Expand Down Expand Up @@ -111,7 +111,7 @@ class RandomDie {

// The root provides the top-level API endpoints
var root = {
getDie: function({ numSides }) {
getDie: function ({ numSides }) {
return new RandomDie(numSides || 6);
},
};
Expand Down
10 changes: 5 additions & 5 deletions docs/Tutorial-PassingArguments.md
Expand Up @@ -28,7 +28,7 @@ So far, our resolver functions took no arguments. When a resolver takes argument

```js
var root = {
rollDice: function(args) {
rollDice: function (args) {
var output = [];
for (var i = 0; i < args.numDice; i++) {
output.push(1 + Math.floor(Math.random() * (args.numSides || 6)));
Expand All @@ -42,7 +42,7 @@ It's convenient to use [ES6 destructuring assignment](https://developer.mozilla.

```js
var root = {
rollDice: function({ numDice, numSides }) {
rollDice: function ({ numDice, numSides }) {
var output = [];
for (var i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
Expand Down Expand Up @@ -70,7 +70,7 @@ var schema = buildSchema(`

// The root provides a resolver function for each API endpoint
var root = {
rollDice: function({ numDice, numSides }) {
rollDice: function ({ numDice, numSides }) {
var output = [];
for (var i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
Expand Down Expand Up @@ -125,8 +125,8 @@ fetch('/graphql', {
variables: { dice, sides },
}),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

Using `$dice` and `$sides` as variables in GraphQL means we don't have to worry about escaping on the client side.
Expand Down
29 changes: 15 additions & 14 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "graphql",
"version": "15.0.0-rc.2",
"version": "15.0.0",
"description": "A Query Language and Runtime which can target any service.",
"license": "MIT",
"private": true,
Expand Down Expand Up @@ -28,7 +28,7 @@
"test:ci": "yarn check --integrity && npm run prettier:check && npm run lint -- --no-cache && npm run check && npm run testonly:cover && npm run check:ts && npm run check:spelling && npm run build",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.js",
"testonly:cover": "nyc npm run testonly",
"lint": "eslint --rulesdir './resources/eslint-rules' --rule 'no-dir-import: error' --cache --ext .js,.ts src resources",
"lint": "eslint --cache --ext .js,.ts src resources",
"benchmark": "node --noconcurrent_sweeping --expose-gc --predictable ./resources/benchmark.js",
"prettier": "prettier --ignore-path .gitignore --write --list-different \"**/*.{js,ts,md,json,yml}\"",
"prettier:check": "prettier --ignore-path .gitignore --check \"**/*.{js,ts,md,json,yml}\"",
Expand All @@ -44,23 +44,24 @@
},
"dependencies": {},
"devDependencies": {
"@babel/core": "7.8.7",
"@babel/plugin-transform-flow-strip-types": "7.8.3",
"@babel/preset-env": "7.8.7",
"@babel/register": "7.8.6",
"@typescript-eslint/eslint-plugin": "2.22.0",
"@typescript-eslint/parser": "2.22.0",
"@babel/core": "7.9.0",
"@babel/plugin-transform-flow-strip-types": "7.9.0",
"@babel/preset-env": "7.9.0",
"@babel/register": "7.9.0",
"@typescript-eslint/eslint-plugin": "2.26.0",
"@typescript-eslint/parser": "2.26.0",
"babel-eslint": "10.1.0",
"chai": "4.2.0",
"cspell": "4.0.55",
"dtslint": "3.3.0",
"dtslint": "3.4.1",
"eslint": "6.8.0",
"eslint-plugin-flowtype": "4.6.0",
"eslint-plugin-import": "2.20.1",
"flow-bin": "0.120.1",
"mocha": "7.1.0",
"eslint-plugin-flowtype": "4.7.0",
"eslint-plugin-graphql-internal": "link:./resources/eslint-rules",
"eslint-plugin-import": "2.20.2",
"flow-bin": "0.121.0",
"mocha": "7.1.1",
"nyc": "15.0.0",
"prettier": "1.19.1",
"prettier": "2.0.2",
"typescript": "^3.8.3"
}
}
6 changes: 3 additions & 3 deletions resources/benchmark-fork.js
Expand Up @@ -43,15 +43,15 @@ function sampleModule(modulePath) {
let message;
let error;

child.on('message', msg => (message = msg));
child.on('error', e => (error = e));
child.on('message', (msg) => (message = msg));
child.on('error', (e) => (error = e));
child.on('close', () => {
if (message) {
return resolve(message);
}
reject(error || new Error('Forked process closed without error'));
});
}).then(result => {
}).then((result) => {
global.gc();
return result;
});
Expand Down
6 changes: 3 additions & 3 deletions resources/benchmark.js
Expand Up @@ -229,7 +229,7 @@ function maxBy(array, fn) {

// Prepare all revisions and run benchmarks matching a pattern against them.
async function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
const environments = revisions.map(revision => ({
const environments = revisions.map((revision) => ({
revision,
distPath: prepareRevision(revision),
}));
Expand Down Expand Up @@ -269,8 +269,8 @@ async function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
function matchBenchmarks(patterns) {
let benchmarks = findFiles(LOCAL_DIR('src'), '*/__tests__/*-benchmark.js');
if (patterns.length > 0) {
benchmarks = benchmarks.filter(benchmark =>
patterns.some(pattern => path.join('src', benchmark).includes(pattern)),
benchmarks = benchmarks.filter((benchmark) =>
patterns.some((pattern) => path.join('src', benchmark).includes(pattern)),
);
}

Expand Down
4 changes: 2 additions & 2 deletions resources/build.js
Expand Up @@ -77,8 +77,8 @@ function showStats() {
stats.sort((a, b) => b[1] - a[1]);
stats = stats.map(([type, size]) => [type, (size / 1024).toFixed(2) + ' KB']);

const typeMaxLength = Math.max(...stats.map(x => x[0].length));
const sizeMaxLength = Math.max(...stats.map(x => x[1].length));
const typeMaxLength = Math.max(...stats.map((x) => x[0].length));
const sizeMaxLength = Math.max(...stats.map((x) => x[1].length));
for (const [type, size] of stats) {
console.log(
type.padStart(typeMaxLength) + ' | ' + size.padStart(sizeMaxLength),
Expand Down

0 comments on commit 27fb3f3

Please sign in to comment.