Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Update prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed May 31, 2020
1 parent d1e716e commit 13806cc
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 46 deletions.
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "lf"
"trailingComma": "all"
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const extensions = ({

app.use(
'/graphql',
graphqlHTTP(request => {
graphqlHTTP((request) => {
return {
schema: MyGraphQLSchema,
context: { startTime: Date.now() },
Expand Down Expand Up @@ -323,7 +323,7 @@ incoming request, you may use it directly for building other similar services.
```js
const graphqlHTTP = require('express-graphql');

graphqlHTTP.getGraphQLParams(request).then(params => {
graphqlHTTP.getGraphQLParams(request).then((params) => {
// do something...
});
```
Expand All @@ -334,7 +334,7 @@ During development, it's useful to get more information from errors, such as
stack traces. Providing a function to `customFormatErrorFn` enables this:

```js
customFormatErrorFn: error => ({
customFormatErrorFn: (error) => ({
message: error.message,
locations: error.locations,
stack: error.stack ? error.stack.split('\n') : [],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"mocha": "6.2.2",
"multer": "1.4.2",
"nyc": "14.1.1",
"prettier": "1.19.1",
"prettier": "2.0.5",
"promise-polyfill": "8.1.3",
"react": "16.11.0",
"react-dom": "16.11.0",
Expand Down
4 changes: 2 additions & 2 deletions resources/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,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
20 changes: 10 additions & 10 deletions resources/gen-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ if (match == null) {
const [, githubOrg, githubRepo] = match;

getChangeLog()
.then(changelog => process.stdout.write(changelog))
.catch(error => console.error(error));
.then((changelog) => process.stdout.write(changelog))
.catch((error) => console.error(error));

function getChangeLog() {
const { version } = packageJSON;
Expand All @@ -73,7 +73,7 @@ function getChangeLog() {
}

const date = exec('git log -1 --format=%cd --date=short');
return getCommitsInfo(commitsList.split('\n')).then(commitsInfo =>
return getCommitsInfo(commitsList.split('\n')).then((commitsInfo) =>
genChangeLog(tag, date, commitsInfo),
);
}
Expand Down Expand Up @@ -138,12 +138,12 @@ function graphqlRequestImpl(query, variables, cb) {
},
});

req.on('response', res => {
req.on('response', (res) => {
let responseBody = '';

res.setEncoding('utf8');
res.on('data', d => (responseBody += d));
res.on('error', error => resultCB(error));
res.on('data', (d) => (responseBody += d));
res.on('error', (error) => resultCB(error));

res.on('end', () => {
if (res.statusCode !== 200) {
Expand Down Expand Up @@ -172,7 +172,7 @@ function graphqlRequestImpl(query, variables, cb) {
});
});

req.on('error', error => cb(error));
req.on('error', (error) => cb(error));
req.write(JSON.stringify({ query, variables }));
req.end();
}
Expand Down Expand Up @@ -231,7 +231,7 @@ function commitsInfoToPRs(commits) {
const prs = {};
for (const commit of commits) {
const associatedPRs = commit.associatedPullRequests.nodes.filter(
pr => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
(pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
);
if (associatedPRs.length === 0) {
throw new Error(
Expand All @@ -246,8 +246,8 @@ function commitsInfoToPRs(commits) {

const pr = associatedPRs[0];
const labels = pr.labels.nodes
.map(label => label.name)
.filter(label => label.startsWith('PR: '));
.map((label) => label.name)
.filter((label) => label.startsWith('PR: '));

if (labels.length === 0) {
throw new Error(`PR #${pr.number} missing label`);
Expand Down
7 changes: 2 additions & 5 deletions resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ function removeTrailingNewLine(str) {
return str;
}

return str
.split('\n')
.slice(0, -1)
.join('\n');
return str.split('\n').slice(0, -1).join('\n');
}

function mkdirRecursive(dirPath) {
Expand Down Expand Up @@ -68,7 +65,7 @@ function readdirRecursive(dirPath, opts = {}) {
if (ignoreDir && ignoreDir.test(name)) {
continue;
}
const list = readdirRecursive(path.join(dirPath, name), opts).map(f =>
const list = readdirRecursive(path.join(dirPath, name), opts).map((f) =>
path.join(name, f),
);
result.push(...list);
Expand Down
18 changes: 8 additions & 10 deletions src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) {
// 0 only in "production" mode.
app.set('json spaces', 0);
}
app.on('error', error => {
app.on('error', (error) => {
// eslint-disable-next-line no-console
console.warn('App encountered an error:', error);
});
Expand Down Expand Up @@ -721,19 +721,17 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) {
})),
);

const response = await request(app)
.post(urlString())
.send({
query: `
const response = await request(app).post(urlString()).send({
query: `
query helloYou { test(who: "You"), ...shared }
query helloWorld { test(who: "World"), ...shared }
query helloDolly { test(who: "Dolly"), ...shared }
fragment shared on QueryRoot {
shared: test(who: "Everyone")
}
`,
operationName: 'helloWorld',
});
operationName: 'helloWorld',
});

expect(JSON.parse(response.text)).to.deep.equal({
data: {
Expand Down Expand Up @@ -901,7 +899,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) {
post(
app,
urlString(),
graphqlHTTP(req => ({
graphqlHTTP((req) => ({
schema: TestMutationSchema,
rootValue: { request: req },
})),
Expand Down Expand Up @@ -1056,7 +1054,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) {
get(
app,
urlString(),
graphqlHTTP(req => ({
graphqlHTTP((req) => ({
schema: TestSchema,
pretty:
((url.parse(req.url, true) || {}).query || {}).pretty === '1',
Expand Down Expand Up @@ -1979,7 +1977,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) {
});

describe('Custom validation rules', () => {
const AlwaysInvalidRule = function(context) {
const AlwaysInvalidRule = function (context) {
return {
enter() {
context.reportError(
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ function graphqlHTTP(options: Options): Middleware {
// Parse the Request to get GraphQL request parameters.
return getGraphQLParams(request)
.then(
graphQLParams => {
(graphQLParams) => {
params = graphQLParams;
// Then, resolve the Options to get OptionsData.
return resolveOptions(params);
},
error => {
(error) => {
// When we failed to parse the GraphQL parameters, we still need to get
// the options object, so make an options call to resolve just that.
const dummyParams = {
Expand All @@ -227,7 +227,7 @@ function graphqlHTTP(options: Options): Middleware {
return resolveOptions(dummyParams).then(() => Promise.reject(error));
},
)
.then(optionsData => {
.then((optionsData) => {
// Assert that schema is required.
if (!optionsData.schema) {
throw new Error('GraphQL middleware options must contain a schema.');
Expand Down Expand Up @@ -333,7 +333,7 @@ function graphqlHTTP(options: Options): Middleware {
return { errors: [contextError] };
}
})
.then(result => {
.then((result) => {
// Collect and apply any metadata extensions if a function was provided.
// https://graphql.github.io/graphql-spec/#sec-Response-Format
if (result && extensionsFn) {
Expand All @@ -345,7 +345,7 @@ function graphqlHTTP(options: Options): Middleware {
result,
context,
}),
).then(extensions => {
).then((extensions) => {
if (extensions && typeof extensions === 'object') {
(result: any).extensions = extensions;
}
Expand All @@ -354,12 +354,12 @@ function graphqlHTTP(options: Options): Middleware {
}
return result;
})
.catch(error => {
.catch((error) => {
// If an error was caught, report the httpError status, or 500.
response.statusCode = error.status || 500;
return { errors: [error] };
})
.then(result => {
.then((result) => {
// If no data was included in the result, that indicates a runtime query
// error, indicate as such with a generic status code.
// Note: Information about the error itself will still be contained in
Expand Down
4 changes: 2 additions & 2 deletions types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ graphqlHTTP({
}),
});

graphqlHTTP(request => ({
graphqlHTTP((request) => ({
graphiql: true,
schema,
context: request.headers,
validationRules,
}));

graphqlHTTP(async request => {
graphqlHTTP(async (request) => {
return {
graphiql: true,
schema: await Promise.resolve(schema),
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2622,10 +2622,10 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=

prettier@1.19.1:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
prettier@2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==

process-nextick-args@~2.0.0:
version "2.0.1"
Expand Down

0 comments on commit 13806cc

Please sign in to comment.