Skip to content

Commit 3bd939f

Browse files
committed
Fix minor lint errors
1 parent a7d4070 commit 3bd939f

File tree

2 files changed

+53
-50
lines changed

2 files changed

+53
-50
lines changed

src/__tests__/jsonToGraphQLQuery.tests.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('jsonToGraphQL()', () => {
3333
}
3434
};
3535
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
36-
`query {
36+
`query {
3737
Posts {
3838
id
3939
title
@@ -57,7 +57,7 @@ describe('jsonToGraphQL()', () => {
5757
}
5858
};
5959
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
60-
`query {
60+
`query {
6161
Posts (orderBy: "post_date", userId: 12) {
6262
id
6363
title
@@ -84,7 +84,7 @@ describe('jsonToGraphQL()', () => {
8484
}
8585
};
8686
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
87-
`query {
87+
`query {
8888
Posts (where: {published: true, rating: {_gt: 3}}, orderBy: "post_date") {
8989
id
9090
title
@@ -111,7 +111,7 @@ describe('jsonToGraphQL()', () => {
111111
}
112112
};
113113
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
114-
`query {
114+
`query {
115115
Posts (or: [{published: true}, {rating: [{_gt: 3}]}], orderBy: "post_date") {
116116
id
117117
title
@@ -137,7 +137,7 @@ describe('jsonToGraphQL()', () => {
137137
}
138138
} as any;
139139
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
140-
`query {
140+
`query {
141141
Posts (where: {id: null}, orderBy: null) {
142142
id
143143
title
@@ -166,7 +166,7 @@ describe('jsonToGraphQL()', () => {
166166
}
167167
} as any;
168168
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
169-
`query {
169+
`query {
170170
Posts @client (where: {id: 10}, orderBy: "flibble") {
171171
id
172172
title
@@ -209,8 +209,8 @@ describe('jsonToGraphQL()', () => {
209209
}
210210
};
211211
const expected = 'query { diet @client { id options { ' +
212-
'mood { category id selected } weight { category icon id text } } ' +
213-
'title } someOtherAbritraryKey @client { arb1 arb2 } }';
212+
'mood { category id selected } weight { category icon id text } } ' +
213+
'title } someOtherAbritraryKey @client { arb1 arb2 } }';
214214
expect(jsonToGraphQLQuery(query)).to.equal(expected);
215215
});
216216

@@ -260,7 +260,7 @@ describe('jsonToGraphQL()', () => {
260260
}
261261
};
262262
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
263-
`query {
263+
`query {
264264
Posts {
265265
id
266266
title
@@ -295,7 +295,7 @@ describe('jsonToGraphQL()', () => {
295295
}
296296
};
297297
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
298-
`query {
298+
`query {
299299
Posts (arg1: 20, arg2: "flibble") {
300300
id
301301
title
@@ -320,7 +320,7 @@ describe('jsonToGraphQL()', () => {
320320
}
321321
};
322322
expect(jsonToGraphQLQuery(query, { pretty: true })).to.equal(
323-
`mutation {
323+
`mutation {
324324
create_post (title: "My Awesome Post", body: "This post is awesome!")
325325
}`);
326326
});
@@ -385,24 +385,24 @@ describe('jsonToGraphQL()', () => {
385385
});
386386

387387
it('does not include fields which value is false', () => {
388-
const query = {
389-
query: {
390-
Posts: {
391-
__args: {
392-
a: false
388+
const query = {
389+
query: {
390+
Posts: {
391+
__args: {
392+
a: false
393+
},
394+
id: true,
395+
name: false
393396
},
394-
id: true,
395-
name: false
396-
},
397-
Lorem: {
398-
id: true
399-
},
400-
Ipsum: false
401-
}
402-
};
403-
expect(jsonToGraphQLQuery(query)).to.equal(
404-
'query { Posts (a: false) { id } Lorem { id } }'
405-
);
397+
Lorem: {
398+
id: true
399+
},
400+
Ipsum: false
401+
}
402+
};
403+
expect(jsonToGraphQLQuery(query)).to.equal(
404+
'query { Posts (a: false) { id } Lorem { id } }'
405+
);
406406
});
407407

408408
it('ignores a field that exists in the initial object', () => {
@@ -436,7 +436,7 @@ describe('jsonToGraphQL()', () => {
436436
query: {
437437
Posts: {
438438
__on: {
439-
__fragmentName: "ConfigurablePost",
439+
__fragmentName: 'ConfigurablePost',
440440
id: true
441441
}
442442
}
@@ -453,7 +453,7 @@ describe('jsonToGraphQL()', () => {
453453
Posts: {
454454
title: true,
455455
__on: {
456-
__fragmentName: "ConfigurablePost",
456+
__fragmentName: 'ConfigurablePost',
457457
id: true
458458
}
459459
}
@@ -469,14 +469,14 @@ describe('jsonToGraphQL()', () => {
469469
query: {
470470
Posts: {
471471
__on: [
472-
{
473-
__fragmentName: "ConfigurablePost",
474-
id: true
475-
},
476-
{
477-
__fragmentName: "UnconfigurablePost",
478-
name: true
479-
}]
472+
{
473+
__fragmentName: 'ConfigurablePost',
474+
id: true
475+
},
476+
{
477+
__fragmentName: 'UnconfigurablePost',
478+
name: true
479+
}]
480480
}
481481
}
482482
};

src/jsonToGraphQLQuery.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { EnumType } from './types/EnumType';
22
import { VariableType } from './types/VariableType';
33

4-
export const configFields = ['__args', '__alias', '__aliasFor', '__variables', '__directives', '__on', '__fragmentName'];
4+
export const configFields = [
5+
'__args', '__alias', '__aliasFor', '__variables', '__directives', '__on', '__fragmentName'
6+
];
57

68
function stringify(obj_from_json: any): string {
79
if (obj_from_json instanceof EnumType) {
@@ -61,7 +63,7 @@ function buildDirectives(dirsObj: any): string {
6163
}
6264
else {
6365
throw new Error(`Unsupported type for directive: ${typeof directiveValue}. Types allowed: object, boolean.\n` +
64-
`Offending object: ${JSON.stringify(dirsObj)}`);
66+
`Offending object: ${JSON.stringify(dirsObj)}`);
6567
}
6668
}
6769

@@ -74,7 +76,7 @@ function filterNonConfigFields(fieldName: string, ignoreFields: string[]) {
7476
return configFields.indexOf(fieldName) == -1 && ignoreFields.indexOf(fieldName) == -1;
7577
}
7678

77-
function convertQuery(node: any, level: number, output: Array<[ string, number ]>, options: IJsonToGraphQLOptions) {
79+
function convertQuery(node: any, level: number, output: Array<[string, number]>, options: IJsonToGraphQLOptions) {
7880
Object.keys(node)
7981
.filter((key) => filterNonConfigFields(key, options.ignoreFields))
8082
.forEach((key) => {
@@ -105,8 +107,8 @@ function convertQuery(node: any, level: number, output: Array<[ string, number ]
105107
const numDirectives = Object.keys(node[key].__directives).length;
106108
if (numDirectives > 1) {
107109
throw new Error(`Too many directives. The object/key ` +
108-
`'${Object.keys(node[key])[0]}' had ${numDirectives} directives, ` +
109-
`but only 1 directive per object/key is supported at this time.`);
110+
`'${Object.keys(node[key])[0]}' had ${numDirectives} directives, ` +
111+
`but only 1 directive per object/key is supported at this time.`);
110112
}
111113
dirsStr = `@${buildDirectives(node[key].__directives)}`;
112114
}
@@ -122,27 +124,28 @@ function convertQuery(node: any, level: number, output: Array<[ string, number ]
122124
token = `${node[key].__alias}: ${token}`;
123125
}
124126

125-
output.push([ token + (subFields || inlineFragmentsExist ? ' {' : ''), level ]);
127+
output.push([token + (subFields || inlineFragmentsExist ? ' {' : ''), level]);
126128
convertQuery(node[key], level + 1, output, options);
127129

128130
if (inlineFragmentsExist) {
129-
let inlineFragments: Array<{__fragmentName: string}> = node[key].__on instanceof Array ? node[key].__on : [node[key].__on];
131+
const inlineFragments: Array<{ __fragmentName: string }>
132+
= node[key].__on instanceof Array ? node[key].__on : [node[key].__on];
130133
inlineFragments.forEach((inlineFragment) => {
131-
let name = inlineFragment.__fragmentName;
134+
const name = inlineFragment.__fragmentName;
132135
output.push([`... on ${name} {`, level + 1]);
133136
convertQuery(inlineFragment, level + 2, output, options);
134-
output.push([ '}', level + 1 ]);
137+
output.push(['}', level + 1]);
135138
});
136139
}
137140

138141
if (subFields || inlineFragmentsExist) {
139-
output.push([ '}', level ]);
142+
output.push(['}', level]);
140143
}
141144

142145
} else if (node[key]) {
143-
output.push([ `${key}`, level ]);
146+
output.push([`${key}`, level]);
144147
}
145-
});
148+
});
146149
}
147150

148151
export interface IJsonToGraphQLOptions {

0 commit comments

Comments
 (0)