Skip to content

Commit 747c474

Browse files
committed
chore(Prettier): Add prettier and refactor code style
1 parent d031b9a commit 747c474

16 files changed

+126
-102
lines changed

.eslintrc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
{
2-
"extends": "airbnb-base",
2+
"extends": [
3+
"airbnb-base",
4+
"prettier"
5+
],
36
"parser": "babel-eslint",
47
"rules": {
58
"no-underscore-dangle": 0,
6-
"no-unused-expressions": 0,
79
"arrow-body-style": 0,
10+
"arrow-parens": 0,
11+
"prefer-template": 0,
12+
"no-use-before-define": 0,
13+
"no-else-return": 0,
14+
"comma-dangle": ["error", {
15+
"arrays": "always-multiline",
16+
"objects": "always-multiline",
17+
"imports": "always-multiline",
18+
"exports": "always-multiline",
19+
"functions": "ignore",
20+
}],
21+
"no-plusplus": 0,
22+
"import/no-extraneous-dependencies": 0,
823
"import/prefer-default-export": 0,
9-
"import/no-extraneous-dependencies": 0
24+
"prettier/prettier": ["error", {
25+
"printWidth": 100,
26+
"singleQuote": true,
27+
"trailingComma": "es5",
28+
}],
29+
"no-unused-expressions": 0,
1030
},
1131
"env": {
1232
"mocha": true
1333
},
1434
"plugins": [
15-
"flowtype"
35+
"flowtype",
36+
"prettier"
1637
]
1738
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
},
2525
"homepage": "https://github.com/nodkz/graphql-compose-relay",
2626
"peerDependencies": {
27-
"graphql": ">=0.7.1 || >=0.8.0 || >=0.9.0",
2827
"graphql-compose": ">=1.19.3"
2928
},
3029
"devDependencies": {
@@ -44,13 +43,16 @@
4443
"cz-conventional-changelog": "^2.0.0",
4544
"eslint": "^3.19.0",
4645
"eslint-config-airbnb-base": "^11.2.0",
46+
"eslint-config-prettier": "^2.1.1",
4747
"eslint-plugin-flowtype": "^2.34.0",
4848
"eslint-plugin-import": "^2.3.0",
49+
"eslint-plugin-prettier": "^2.1.1",
4950
"flow-bin": "^0.47.0",
5051
"graphql": "^0.10.1",
5152
"graphql-compose": "^1.19.3",
5253
"mocha": "^3.4.2",
5354
"nyc": "^11.0.2",
55+
"prettier": "^1.4.2",
5456
"rimraf": "^2.6.1",
5557
"sane": "^1.7.0",
5658
"semantic-release": "^6.3.6"
@@ -84,8 +86,8 @@
8486
"lint": "eslint src test *.js",
8587
"test": "babel-node ./node_modules/.bin/_mocha --compilers js:babel-core/register --reporter dot --require ./resources/mocha-bootload src/**/__tests__/**/*-test.js",
8688
"watch": "babel-node ./resources/watch.js",
87-
"link": "yarn build && yarn link graphql && yarn link graphql-compose && yarn link",
88-
"unlink": "yarn unlink graphql && yarn unlink graphql-compose && yarn add graphql graphql-compose",
89+
"link": "yarn build && yarn link graphql-compose && yarn link",
90+
"unlink": "yarn unlink graphql-compose && graphql-compose",
8991
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
9092
}
9193
}

src/__mocks__/rootMutationTypeComposer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { TypeComposer } from 'graphql-compose';
55

66
const RootMutation = new GraphQLObjectType({
77
name: 'Mutation',
8-
fields: {
9-
},
8+
fields: {},
109
});
1110

1211
export const rootMutationTypeComposer = new TypeComposer(RootMutation);

src/__mocks__/rootQueryTypeComposer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { TypeComposer } from 'graphql-compose';
55

66
const RootQuery = new GraphQLObjectType({
77
name: 'Query',
8-
fields: {
9-
},
8+
fields: {},
109
});
1110

1211
export const rootQueryTypeComposer = new TypeComposer(RootQuery);

src/__mocks__/userTypeComposer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const findByIdResolver = new Resolver({
3535
type: new GraphQLNonNull(GraphQLInt),
3636
},
3737
},
38-
resolve: (resolveParams) => {
38+
resolve: resolveParams => {
3939
const args = resolveParams.args || {};
4040
if (args._id.toString() === '1') {
4141
return Promise.resolve({
@@ -80,7 +80,7 @@ export const createOneResolver = new Resolver({
8080
}),
8181
},
8282
},
83-
resolve: (resolveParams) => {
83+
resolve: resolveParams => {
8484
return Promise.resolve({
8585
recordId: resolveParams.args.input.id,
8686
record: (resolveParams.args && resolveParams.args.input) || {},
@@ -121,7 +121,7 @@ export const manyArgsWithInputResolver = new Resolver({
121121
type: GraphQLInt,
122122
},
123123
},
124-
resolve: (resolveParams) => {
124+
resolve: resolveParams => {
125125
return Promise.resolve({
126126
recordId: resolveParams.args.input.id,
127127
record: (resolveParams.args && resolveParams.args.input) || {},
@@ -151,7 +151,7 @@ export const manyArgsWithoutInputResolver = new Resolver({
151151
type: GraphQLInt,
152152
},
153153
},
154-
resolve: (resolveParams) => {
154+
resolve: resolveParams => {
155155
return Promise.resolve({
156156
recordId: resolveParams.args.input.id,
157157
record: (resolveParams.args && resolveParams.args.input) || {},

src/__tests__/composeWithRelay-test.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('composeWithRelay', () => {
3636
it('should thow error if typeComposer does not have findById resolver', () => {
3737
const tc = userTypeComposer.clone('AnotherUserType');
3838
tc.removeResolver('findById');
39-
expect(() => composeWithRelay(tc)).to.throw('does not have resolver with name \'findById\'');
39+
expect(() => composeWithRelay(tc)).to.throw("does not have resolver with name 'findById'");
4040
});
4141
});
4242

@@ -61,7 +61,8 @@ describe('composeWithRelay', () => {
6161
});
6262

6363
it('should resolve globalId in `user.id` field', async () => {
64-
rootQueryTypeComposer.setField('user',
64+
rootQueryTypeComposer.setField(
65+
'user',
6566
userTypeComposer.getResolver('findById').getFieldConfig()
6667
);
6768
const schema = new GraphQLSchema({
@@ -73,13 +74,14 @@ describe('composeWithRelay', () => {
7374
name
7475
}
7576
}`;
76-
const result = await graphql(schema, query);
77+
const result = await graphql.graphql(schema, query);
7778
expect(result).nested.property('data.user.id').equal(toGlobalId('User', 1));
7879
expect(result).nested.property('data.user.name').equal('Pavel');
7980
});
8081

8182
it('should resolve globalId in `node.id` field', async () => {
82-
rootQueryTypeComposer.setField('user',
83+
rootQueryTypeComposer.setField(
84+
'user',
8385
userTypeComposer.getResolver('findById').getFieldConfig()
8486
);
8587
const schema = new GraphQLSchema({
@@ -94,13 +96,14 @@ describe('composeWithRelay', () => {
9496
id
9597
name
9698
}`;
97-
const result = await graphql(schema, query);
99+
const result = await graphql.graphql(schema, query);
98100
expect(result).nested.property('data.node.id').equal(toGlobalId('User', 1));
99101
expect(result).nested.property('data.node.name').equal('Pavel');
100102
});
101103

102104
it('should passthru clientMutationId in mutations', async () => {
103-
rootMutationComposer.setField('createUser',
105+
rootMutationComposer.setField(
106+
'createUser',
104107
userTypeComposer.getResolver('createOne').getFieldConfig()
105108
);
106109
const schema = new GraphQLSchema({
@@ -115,11 +118,9 @@ describe('composeWithRelay', () => {
115118
clientMutationId
116119
}
117120
}`;
118-
const result = await graphql(schema, query);
119-
expect(result).nested.property('data.createUser.record.name')
120-
.equal('Ok');
121-
expect(result).nested.property('data.createUser.clientMutationId')
122-
.equal('123');
121+
const result = await graphql.graphql(schema, query);
122+
expect(result).nested.property('data.createUser.record.name').equal('Ok');
123+
expect(result).nested.property('data.createUser.clientMutationId').equal('123');
123124
});
124125
});
125126
});

src/__tests__/globalId-test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { expect } from 'chai';
2-
import {
3-
base64,
4-
unbase64,
5-
toGlobalId,
6-
fromGlobalId,
7-
} from '../globalId';
8-
2+
import { base64, unbase64, toGlobalId, fromGlobalId } from '../globalId';
93

104
describe('globalId', () => {
115
it('should have correct method base64()', () => {
@@ -24,8 +18,13 @@ describe('globalId', () => {
2418
});
2519

2620
it('should have correct method fromGlobalId()', () => {
27-
expect(fromGlobalId('VXNlcjo3ODk=')).to.deep.equal({ type: 'User', id: '789' });
28-
expect(fromGlobalId('QXJ0aWNsZToyMg=='))
29-
.to.deep.equal({ type: 'Article', id: '22' });
21+
expect(fromGlobalId('VXNlcjo3ODk=')).to.deep.equal({
22+
type: 'User',
23+
id: '789',
24+
});
25+
expect(fromGlobalId('QXJ0aWNsZToyMg==')).to.deep.equal({
26+
type: 'Article',
27+
id: '22',
28+
});
3029
});
3130
});

src/__tests__/nodeFieldConfig-test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('nodeFieldConfig', () => {
1313
User: {
1414
resolver: findByIdResolver,
1515
tc: userTypeComposer,
16-
}
16+
},
1717
};
1818
const config = getNodeFieldConfig(typeToFindByIdMap);
1919

@@ -36,15 +36,11 @@ describe('nodeFieldConfig', () => {
3636
});
3737

3838
it('should return null if findById not defined for type', () => {
39-
expect(
40-
config.resolve({}, { id: toGlobalId('UnexistedType', 1) })
41-
).to.be.null;
39+
expect(config.resolve({}, { id: toGlobalId('UnexistedType', 1) })).to.be.null;
4240
});
4341

4442
it('should return Promise if type exists, but id not exist', () => {
45-
expect(
46-
config.resolve({}, { id: toGlobalId('User', 666) })
47-
).instanceof(Promise);
43+
expect(config.resolve({}, { id: toGlobalId('User', 666) })).instanceof(Promise);
4844
});
4945

5046
it('should return Promise with user data', async () => {

src/__tests__/wrapMutationResolver.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import { expect } from 'chai';
2-
import {
3-
GraphQLString,
4-
GraphQLID,
5-
GraphQLNonNull,
6-
getNamedType,
7-
} from 'graphql';
2+
import { GraphQLString, GraphQLID, GraphQLNonNull, getNamedType } from 'graphql';
83
import { TypeComposer, InputTypeComposer } from 'graphql-compose';
94
import { composeWithRelay } from '../composeWithRelay';
105
import { userTypeComposer } from '../__mocks__/userTypeComposer';
116
import { toGlobalId } from '../globalId';
127

13-
148
describe('wrapMutationResolver', () => {
159
composeWithRelay(userTypeComposer);
1610
const fieldConfig = userTypeComposer.getResolver('createOne').getFieldConfig();
17-
const fieldConfigManyArgsWithInput
18-
= userTypeComposer.getResolver('manyArgsWithInput').getFieldConfig();
19-
const fieldConfigManyArgsWithoutInput
20-
= userTypeComposer.getResolver('manyArgsWithoutInput').getFieldConfig();
11+
const fieldConfigManyArgsWithInput = userTypeComposer
12+
.getResolver('manyArgsWithInput')
13+
.getFieldConfig();
14+
const fieldConfigManyArgsWithoutInput = userTypeComposer
15+
.getResolver('manyArgsWithoutInput')
16+
.getFieldConfig();
2117

2218
describe('args', () => {
2319
it('should add `clientMutationId` field to args.input', () => {
@@ -26,12 +22,12 @@ describe('wrapMutationResolver', () => {
2622
expect(itc.getFieldType('clientMutationId')).equal(GraphQLString);
2723
});
2824

29-
3025
it('should create required args.input! if not exists', () => {
3126
expect(fieldConfigManyArgsWithoutInput.args).property('input').to.be.ok;
3227

33-
expect(fieldConfigManyArgsWithoutInput.args)
34-
.nested.property('input.type').instanceof(GraphQLNonNull);
28+
expect(fieldConfigManyArgsWithoutInput.args).nested
29+
.property('input.type')
30+
.instanceof(GraphQLNonNull);
3531
});
3632

3733
it('should create args.input if not exists and move all args into it', () => {
@@ -71,18 +67,12 @@ describe('wrapMutationResolver', () => {
7167

7268
describe('resolve', () => {
7369
it('should passthru `clientMutationId`', async () => {
74-
const result = await fieldConfig.resolve(
75-
{},
76-
{ input: { clientMutationId: '333' } }
77-
);
70+
const result = await fieldConfig.resolve({}, { input: { clientMutationId: '333' } });
7871
expect(result).property('clientMutationId').equal('333');
7972
});
8073

8174
it('should return `nodeId` with globalId', async () => {
82-
const result = await fieldConfig.resolve(
83-
{},
84-
{ input: { id: 'newRecord' } }
85-
);
75+
const result = await fieldConfig.resolve({}, { input: { id: 'newRecord' } });
8676
expect(result).property('nodeId').equal(toGlobalId('User', 'newRecord'));
8777
});
8878
});

src/composeWithRelay.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import { getNodeFieldConfig } from './nodeFieldConfig';
1313
export const typeMapForNode = {};
1414
export const nodeFieldConfig = getNodeFieldConfig(typeMapForNode);
1515

16-
export function composeWithRelay(
17-
typeComposer: TypeComposer
18-
): TypeComposer {
16+
export function composeWithRelay(typeComposer: TypeComposer): TypeComposer {
1917
if (!(typeComposer instanceof TypeComposer)) {
2018
throw new Error('You should provide TypeComposer instance to composeWithRelay method');
2119
}
@@ -31,14 +29,18 @@ export function composeWithRelay(
3129
}
3230

3331
if (!typeComposer.hasRecordIdFn()) {
34-
throw new Error(`TypeComposer(${typeComposer.getTypeName()}) should have recordIdFn. `
35-
+ 'This function returns ID from provided object.');
32+
throw new Error(
33+
`TypeComposer(${typeComposer.getTypeName()}) should have recordIdFn. ` +
34+
'This function returns ID from provided object.'
35+
);
3636
}
3737

3838
const findById = typeComposer.getResolver('findById');
3939
if (!findById) {
40-
throw new Error(`TypeComposer(${typeComposer.getTypeName()}) provided to composeWithRelay `
41-
+ 'should have findById resolver.');
40+
throw new Error(
41+
`TypeComposer(${typeComposer.getTypeName()}) provided to composeWithRelay ` +
42+
'should have findById resolver.'
43+
);
4244
}
4345
typeMapForNode[typeComposer.getTypeName()] = {
4446
resolver: findById,
@@ -49,10 +51,7 @@ export function composeWithRelay(
4951
id: {
5052
type: new GraphQLNonNull(GraphQLID),
5153
description: 'The globally unique ID among all types',
52-
resolve: (source) => toGlobalId(
53-
typeComposer.getTypeName(),
54-
typeComposer.getRecordId(source)
55-
),
54+
resolve: source => toGlobalId(typeComposer.getTypeName(), typeComposer.getRecordId(source)),
5655
},
5756
});
5857

0 commit comments

Comments
 (0)