Skip to content

Commit 3007181

Browse files
committed
Apply new lint rules
1 parent eae0245 commit 3007181

32 files changed

+262
-200
lines changed

src/createApolloClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ApolloClient } from 'apollo-client';
22
import { mockNetworkInterfaceWithSchema } from 'apollo-test-utils';
33
import getSchemaFromData from './introspection/getSchemaFromData';
44

5-
export default data => {
5+
export default (data) => {
66
const schema = getSchemaFromData(data);
77
const mockNetworkInterface = mockNetworkInterfaceWithSchema({ schema });
88

src/graphQLClientServer.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import mock, { proxy } from 'xhr-mock';
22
import handleRequestFactory from './handleRequest';
33

44
/**
5-
* Starts a GraphQL Server in your browser: intercepts every call to http://localhost:3000/graphql
5+
* Starts a GraphQL Server in your browser: intercepts every call to http://localhost:3000/graphql
66
* and returns a response from the supplied data.
7-
*
7+
*
88
* @export A sinon.js FakeServer (http://sinonjs.org/releases/v2.3.6/fake-xhr-and-server/#fake-server)
9-
* @param {any} data
9+
* @param {any} data
1010
* @param {any} url Specifies the endpoint to intercept (Default is 'http://localhost:3000/graphql').
11-
*
11+
*
1212
* @example
1313
* const data = {
1414
* "posts": [
@@ -36,11 +36,11 @@ import handleRequestFactory from './handleRequest';
3636
* }
3737
* ],
3838
* };
39-
*
39+
*
4040
* GraphQLClientServer(data);
4141
* GraphQLClientServer(data, 'http://localhost:8080/api/graphql');
4242
*/
43-
export default function({ data, url }) {
43+
export default function ({ data, url }) {
4444
const handleRequest = handleRequestFactory(data);
4545

4646
return {
@@ -52,10 +52,10 @@ export default function({ data, url }) {
5252
mock.post(
5353
url,
5454
(req, res) =>
55-
new Promise(resolve => {
55+
new Promise((resolve) => {
5656
handleRequest(url, {
5757
body: req.body(),
58-
}).then(response => {
58+
}).then((response) => {
5959
res.status(response.status);
6060
res.headers(response.headers);
6161
res.body(response.body);

src/handleRequest.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { graphql } from 'graphql';
22
import schemaBuilder from './schemaBuilder';
33

44
/**
5-
* Starts a GraphQL Server in your browser: intercepts every call to http://localhost:3000/graphql
5+
* Starts a GraphQL Server in your browser: intercepts every call to http://localhost:3000/graphql
66
* and returns a response from the supplied data.
7-
*
7+
*
88
* @export A sinon.js FakeServer (http://sinonjs.org/releases/v2.3.6/fake-xhr-and-server/#fake-server)
9-
* @param {any} data
9+
* @param {any} data
1010
* @param {any} url Specifies the endpoint to intercept (Default is 'http://localhost:3000/graphql').
11-
*
11+
*
1212
* @example
1313
* const data = {
1414
* "posts": [
@@ -36,11 +36,11 @@ import schemaBuilder from './schemaBuilder';
3636
* }
3737
* ],
3838
* };
39-
*
39+
*
4040
* GraphQLClientServer(data);
4141
* GraphQLClientServer(data, 'http://localhost:8080/api/graphql');
4242
*/
43-
export default function(data) {
43+
export default function (data) {
4444
const schema = schemaBuilder(data);
4545
return (url, opts = {}) => {
4646
let body = opts.body;
@@ -58,12 +58,12 @@ export default function(data) {
5858
undefined,
5959
query.variables
6060
).then(
61-
result => ({
61+
(result) => ({
6262
status: 200,
6363
headers: { 'Content-Type': 'application/json' },
6464
body: JSON.stringify(result),
6565
}),
66-
error => ({
66+
(error) => ({
6767
status: 500,
6868
headers: { 'Content-Type': 'application/json' },
6969
body: JSON.stringify(error),

src/introspection/getFieldsFromEntities.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import getValuesFromEntities from './getValuesFromEntities';
33

44
/**
55
* Get a list of GraphQL fields from a list of entities
6-
*
6+
*
77
* @example
88
* const entities = [
99
* {

src/introspection/getFilterTypesFromData.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import getValuesFromEntities from './getValuesFromEntities';
1111
import getTypeFromValues from './getTypeFromValues';
1212
import { getTypeFromKey } from '../nameConverter';
1313

14-
const getRangeFiltersFromEntities = entities => {
14+
const getRangeFiltersFromEntities = (entities) => {
1515
const fieldValues = getValuesFromEntities(entities);
1616
return Object.keys(fieldValues).reduce((fields, fieldName) => {
1717
const fieldType = getTypeFromValues(
@@ -35,7 +35,7 @@ const getRangeFiltersFromEntities = entities => {
3535

3636
/**
3737
* Get a list of GraphQLObjectType for filtering data
38-
*
38+
*
3939
* @example
4040
* const data = {
4141
* "posts": [
@@ -89,7 +89,7 @@ const getRangeFiltersFromEntities = entities => {
8989
* // }),
9090
* // }
9191
*/
92-
export default data =>
92+
export default (data) =>
9393
Object.keys(data).reduce(
9494
(types, key) =>
9595
Object.assign({}, types, {

src/introspection/getFilterTypesFromData.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const UsersType = new GraphQLObjectType({
5050

5151
test('creates one filter type per entity', () => {
5252
const filterTypes = getFilterTypesFromData(data);
53-
expect(Object.values(filterTypes).map(type => type.toString())).toEqual([
53+
expect(Object.values(filterTypes).map((type) => type.toString())).toEqual([
5454
'PostFilter',
5555
'UserFilter',
5656
]);

src/introspection/getSchemaFromData.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getRelatedType } from '../nameConverter';
1919

2020
/**
2121
* Get a GraphQL schema from data
22-
*
22+
*
2323
* @example
2424
* const data = {
2525
* "posts": [
@@ -76,7 +76,7 @@ import { getRelatedType } from '../nameConverter';
7676
* // removeUser(id: ID!): Boolean
7777
* // }
7878
*/
79-
export default data => {
79+
export default (data) => {
8080
const types = getTypesFromData(data);
8181
const typesByName = types.reduce((types, type) => {
8282
types[type.name] = type;
@@ -127,18 +127,19 @@ export default data => {
127127
name: 'Mutation',
128128
fields: types.reduce((fields, type) => {
129129
const typeFields = typesByName[type.name].getFields();
130-
const nullableTypeFields = Object.keys(
131-
typeFields
132-
).reduce((f, fieldName) => {
133-
f[fieldName] = Object.assign({}, typeFields[fieldName], {
134-
type:
135-
fieldName !== 'id' &&
136-
typeFields[fieldName].type instanceof GraphQLNonNull
137-
? typeFields[fieldName].type.ofType
138-
: typeFields[fieldName].type,
139-
});
140-
return f;
141-
}, {});
130+
const nullableTypeFields = Object.keys(typeFields).reduce(
131+
(f, fieldName) => {
132+
f[fieldName] = Object.assign({}, typeFields[fieldName], {
133+
type:
134+
fieldName !== 'id' &&
135+
typeFields[fieldName].type instanceof GraphQLNonNull
136+
? typeFields[fieldName].type.ofType
137+
: typeFields[fieldName].type,
138+
});
139+
return f;
140+
},
141+
{}
142+
);
142143
fields[`create${type.name}`] = {
143144
type: typesByName[type.name],
144145
args: typeFields,
@@ -164,7 +165,7 @@ export default data => {
164165

165166
/**
166167
* extend schema to add relationship fields
167-
*
168+
*
168169
* @example
169170
* If the `post` key contains a 'user_id' field, then
170171
* add one-to-many and many-to-one type extensions:
@@ -174,7 +175,7 @@ export default data => {
174175
const schemaExtension = Object.values(typesByName).reduce((ext, type) => {
175176
Object.keys(type.getFields())
176177
.filter(isRelationshipField)
177-
.map(fieldName => {
178+
.map((fieldName) => {
178179
const relType = getRelatedType(fieldName);
179180
const rel = pluralize(type.toString());
180181
ext += `

src/introspection/getSchemaFromData.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ test('creates three mutation fields per data type', () => {
280280

281281
test('pluralizes and capitalizes correctly', () => {
282282
const data = {
283-
feet: [{ id: 1, size: 42 }, { id: 2, size: 39 }],
283+
feet: [
284+
{ id: 1, size: 42 },
285+
{ id: 2, size: 39 },
286+
],
284287
categories: [{ id: 1, name: 'foo' }],
285288
};
286289
const queries = getSchemaFromData(data).getQueryType().getFields();

src/introspection/getTypeFromValues.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import {
1010
import GraphQLJSON from 'graphql-type-json';
1111
import DateType from './DateType';
1212

13-
const isNumeric = value => !isNaN(parseFloat(value)) && isFinite(value);
14-
const valuesAreNumeric = values => values.every(isNumeric);
15-
const isInteger = value => Number.isInteger(value);
16-
const valuesAreInteger = values => values.every(isInteger);
17-
const isBoolean = value => typeof value === 'boolean';
18-
const valuesAreBoolean = values => values.every(isBoolean);
19-
const isString = value => typeof value === 'string';
20-
const valuesAreString = values => values.every(isString);
21-
const isArray = value => Array.isArray(value);
22-
const valuesAreArray = values => values.every(isArray);
23-
const isDate = value => value instanceof Date;
24-
const valuesAreDate = values => values.every(isDate);
25-
const isObject = value =>
13+
const isNumeric = (value) => !isNaN(parseFloat(value)) && isFinite(value);
14+
const valuesAreNumeric = (values) => values.every(isNumeric);
15+
const isInteger = (value) => Number.isInteger(value);
16+
const valuesAreInteger = (values) => values.every(isInteger);
17+
const isBoolean = (value) => typeof value === 'boolean';
18+
const valuesAreBoolean = (values) => values.every(isBoolean);
19+
const isString = (value) => typeof value === 'string';
20+
const valuesAreString = (values) => values.every(isString);
21+
const isArray = (value) => Array.isArray(value);
22+
const valuesAreArray = (values) => values.every(isArray);
23+
const isDate = (value) => value instanceof Date;
24+
const valuesAreDate = (values) => values.every(isDate);
25+
const isObject = (value) =>
2626
Object.prototype.toString.call(value) === '[object Object]';
27-
const valuesAreObject = values => values.every(isObject);
27+
const valuesAreObject = (values) => values.every(isObject);
2828

2929
const requiredTypeOrNormal = (type, isRequired) =>
3030
isRequired ? new GraphQLNonNull(type) : type;
@@ -36,7 +36,7 @@ export default (name, values = [], isRequired = false) => {
3636
if (values.length > 0) {
3737
if (valuesAreArray(values)) {
3838
const leafValues = values.reduce((agg, arr) => {
39-
arr.forEach(value => agg.push(value));
39+
arr.forEach((value) => agg.push(value));
4040
return agg;
4141
}, []);
4242
if (valuesAreBoolean(leafValues)) {

src/introspection/getTypeFromValues.spec.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ test('returns GraphQLList for arrays', () => {
2020
expect(getTypeFromValues('foo', [[true, false], [true]])).toEqual(
2121
new GraphQLList(GraphQLBoolean)
2222
);
23-
expect(getTypeFromValues('foo', [['a', 'b'], ['c', 'd']])).toEqual(
24-
new GraphQLList(GraphQLString)
25-
);
26-
expect(getTypeFromValues('foo', [[123, 456], [789, 123]])).toEqual(
27-
new GraphQLList(GraphQLInt)
28-
);
29-
expect(getTypeFromValues('foo', [[1.23, 456], [-5, 123]])).toEqual(
30-
new GraphQLList(GraphQLFloat)
31-
);
23+
expect(
24+
getTypeFromValues('foo', [
25+
['a', 'b'],
26+
['c', 'd'],
27+
])
28+
).toEqual(new GraphQLList(GraphQLString));
29+
expect(
30+
getTypeFromValues('foo', [
31+
[123, 456],
32+
[789, 123],
33+
])
34+
).toEqual(new GraphQLList(GraphQLInt));
35+
expect(
36+
getTypeFromValues('foo', [
37+
[1.23, 456],
38+
[-5, 123],
39+
])
40+
).toEqual(new GraphQLList(GraphQLFloat));
3241
});
3342

3443
test('returns GraphQLBoolean for booleans', () =>

src/introspection/getTypesFromData.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getTypeFromKey } from '../nameConverter';
66

77
/**
88
* Get a list of GraphQLObjectType from data
9-
*
9+
*
1010
* @example
1111
* const data = {
1212
* "posts": [
@@ -54,13 +54,13 @@ import { getTypeFromKey } from '../nameConverter';
5454
* // }),
5555
* // ]
5656
*/
57-
export default data =>
57+
export default (data) =>
5858
Object.keys(data)
59-
.map(typeName => ({
59+
.map((typeName) => ({
6060
name: camelize(singularize(typeName)),
6161
fields: getFieldsFromEntities(data[typeName]),
6262
}))
63-
.map(typeObject => new GraphQLObjectType(typeObject));
63+
.map((typeObject) => new GraphQLObjectType(typeObject));
6464

65-
export const getTypeNamesFromData = data =>
65+
export const getTypeNamesFromData = (data) =>
6666
Object.keys(data).map(getTypeFromKey);

src/introspection/getTypesFromData.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ test('Integration test', () => {
5151
},
5252
});
5353
const types = getTypesFromData(data);
54-
expect(types.map(t => t.toString())).toEqual(['Post', 'User']);
55-
expect(types.map(t => t.getFields())).toEqual([
54+
expect(types.map((t) => t.toString())).toEqual(['Post', 'User']);
55+
expect(types.map((t) => t.getFields())).toEqual([
5656
PostType.getFields(),
5757
UsersType.getFields(),
5858
]);

src/introspection/getValuesFromEntities.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Gets a list of values indexed by field based on a list of entities
3-
*
3+
*
44
* @example
55
* const entities = [
66
* {
@@ -24,9 +24,9 @@
2424
* // user_id: [123, 456],
2525
* // }
2626
*/
27-
export default entities =>
27+
export default (entities) =>
2828
entities.reduce((values, entity) => {
29-
Object.keys(entity).forEach(fieldName => {
29+
Object.keys(entity).forEach((fieldName) => {
3030
if (!values[fieldName]) {
3131
values[fieldName] = [];
3232
}

src/introspection/getValuesFromEntities.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ test('does not take empty values into account', () => {
77
});
88
test('returns an array of values for every field', () => {
99
expect(
10-
getValuesFromEntities([{ id: 1, foo: 'bar' }, { id: 2, foo: 'baz' }])
10+
getValuesFromEntities([
11+
{ id: 1, foo: 'bar' },
12+
{ id: 2, foo: 'baz' },
13+
])
1114
).toEqual({
1215
id: [1, 2],
1316
foo: ['bar', 'baz'],

src/jsonGraphqlExpress.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import schemaBuilder from './schemaBuilder';
4545
*
4646
* app.listen(PORT);
4747
*/
48-
export default data =>
48+
export default (data) =>
4949
graphqlHTTP({
5050
schema: schemaBuilder(data),
5151
graphiql: true,

0 commit comments

Comments
 (0)