Skip to content

Commit 8f9255f

Browse files
authored
feat: update all dependencies (#10)
Update package.json to use latest dependencies Also add `yarn lint` script that will run eslint and tsc
1 parent b15f48c commit 8f9255f

File tree

4 files changed

+2380
-2319
lines changed

4 files changed

+2380
-2319
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

package.json

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,40 @@
2222
"fakes"
2323
],
2424
"dependencies": {
25-
"@graphql-codegen/plugin-helpers": "^1.8.1",
25+
"@graphql-codegen/plugin-helpers": "^1.13.1",
2626
"casual": "^1.6.2",
2727
"pascal-case": "^3.1.1"
2828
},
2929
"peerDependencies": {
3030
"graphql": "^14.0.0"
3131
},
3232
"devDependencies": {
33-
"@auto-it/conventional-commits": "^7.12.3",
34-
"@graphql-codegen/testing": "^1.8.2",
35-
"@types/faker": "^4.1.6",
36-
"@types/jest": "^24.0.19",
37-
"@typescript-eslint/eslint-plugin": "^1.4.2",
38-
"@typescript-eslint/parser": "^1.4.2",
33+
"@auto-it/conventional-commits": "^9.25.0",
34+
"@graphql-codegen/testing": "^1.13.1",
35+
"@types/faker": "^4.1.11",
36+
"@types/jest": "^25.1.5",
37+
"@typescript-eslint/eslint-plugin": "^2.26.0",
38+
"@typescript-eslint/parser": "^2.26.0",
3939
"auto": "^9.25.0",
40-
"eslint": "6.0.0",
41-
"eslint-config-landr": "0.1.0",
42-
"eslint-config-prettier": "^4.1.0",
43-
"eslint-plugin-import": "^2.17.2",
44-
"eslint-plugin-jest": "^22.20.0",
45-
"eslint-plugin-prettier": "^3.0.1",
46-
"graphql": "^14.5.8",
47-
"graphql-toolkit": "^0.5.19-beta.0",
48-
"jest": "^24.9.0",
49-
"prettier": "^1.18.2",
50-
"prettier-config-landr": "^0.0.6",
51-
"ts-jest": "^24.1.0",
52-
"typescript": "^3.3.3333"
40+
"eslint": "6.8.0",
41+
"eslint-config-landr": "0.2.1",
42+
"eslint-config-prettier": "^6.10.1",
43+
"eslint-plugin-import": "^2.20.2",
44+
"eslint-plugin-jest": "^23.8.2",
45+
"eslint-plugin-prettier": "^3.1.2",
46+
"graphql": "^14.0.0",
47+
"graphql-toolkit": "^0.7.5",
48+
"jest": "^25.2.7",
49+
"prettier": "^2.0.2",
50+
"prettier-config-landr": "^0.0.7",
51+
"ts-jest": "^25.3.1",
52+
"typescript": "^3.8.3"
5353
},
5454
"sideEffects": false,
5555
"scripts": {
5656
"build": "tsc -m esnext --outDir dist/esnext && tsc -m commonjs --outDir dist/commonjs",
5757
"test": "jest",
58+
"lint": "eslint 'src/**/*.{js,ts,tsx}' --quiet --fix && tsc --noEmit",
5859
"auto:version": "yarn version --`auto version` --message 'Bump version to: %s [skip ci]'",
5960
"auto:publish": "yarn publish && git push --follow-tags --set-upstream origin $CIRCLE_BRANCH",
6061
"release": "auto changelog && yarn auto:version && yarn auto:publish && auto release"

src/index.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { printSchema, parse, visit, ASTKindToNode, NamedTypeNode, TypeNode, VisitFn } from 'graphql';
22
import casual from 'casual';
33
import { PluginFunction } from '@graphql-codegen/plugin-helpers';
4-
import { pascalCase } from 'pascal-case';
5-
6-
export function toPascalCase(str: string) {
7-
if (str.charAt(0) === '_') {
8-
return str.replace(/^(_*)(.*)/, (_match, underscorePrefix, typeName) => `${underscorePrefix}${pascalCase(typeName || '')}`);
9-
}
4+
import { pascalCase } from 'pascal-case';
5+
6+
export function toPascalCase(str: string) {
7+
if (str.charAt(0) === '_') {
8+
return str.replace(
9+
/^(_*)(.*)/,
10+
(_match, underscorePrefix, typeName) => `${underscorePrefix}${pascalCase(typeName || '')}`,
11+
);
12+
}
1013

11-
return pascalCase(str || '');
14+
return pascalCase(str || '');
1215
}
1316

1417
const toMockName = (name: string) => {
@@ -22,7 +25,7 @@ const hashedString = (value: string) => {
2225
return hash;
2326
}
2427
for (let i = 0; i < value.length; i++) {
25-
let char = value.charCodeAt(i);
28+
const char = value.charCodeAt(i);
2629
// eslint-disable-next-line no-bitwise
2730
hash = (hash << 5) - hash + char;
2831
// eslint-disable-next-line no-bitwise
@@ -56,14 +59,15 @@ const getNamedType = (
5659
return casual.integer(0, 9999);
5760
case 'Date':
5861
return `'${new Date(casual.unix_time).toISOString()}'`;
59-
default:
60-
const foundType = types.find(enumType => enumType.name === name);
62+
default: {
63+
const foundType = types.find((enumType: TypeItem) => enumType.name === name);
6164
if (foundType) {
6265
switch (foundType.type) {
63-
case 'enum':
66+
case 'enum': {
6467
// It's an enum
6568
const value = foundType.values ? foundType.values[0] : '';
6669
return `${foundType.name}.${toPascalCase(value)}`;
70+
}
6771
case 'union':
6872
// Return the first union type node.
6973
return getNamedType(typeName, fieldName, types, foundType.types && foundType.types[0]);
@@ -72,6 +76,7 @@ const getNamedType = (
7276
}
7377
}
7478
return `${toMockName(name)}()`;
79+
}
7580
}
7681
};
7782

@@ -86,9 +91,10 @@ const generateMockValue = (
8691
return getNamedType(typeName, fieldName, types, currentType as NamedTypeNode);
8792
case 'NonNullType':
8893
return generateMockValue(typeName, fieldName, types, currentType.type);
89-
case 'ListType':
94+
case 'ListType': {
9095
const value = generateMockValue(typeName, fieldName, types, currentType.type);
9196
return `[${value}]`;
97+
}
9298
}
9399
};
94100

@@ -126,27 +132,27 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
126132
// List of types that are enums
127133
const types: TypeItem[] = [];
128134
const visitor: VisitorType = {
129-
EnumTypeDefinition: node => {
135+
EnumTypeDefinition: (node) => {
130136
const name = node.name.value;
131137
if (!types.find((enumType: TypeItem) => enumType.name === name)) {
132138
types.push({
133139
name,
134140
type: 'enum',
135-
values: node.values ? node.values.map(node => node.name.value) : [],
141+
values: node.values ? node.values.map((node) => node.name.value) : [],
136142
});
137143
}
138144
},
139-
UnionTypeDefinition: node => {
145+
UnionTypeDefinition: (node) => {
140146
const name = node.name.value;
141-
if (!types.find(enumType => enumType.name === name)) {
147+
if (!types.find((enumType) => enumType.name === name)) {
142148
types.push({
143149
name,
144150
type: 'union',
145151
types: node.types,
146152
});
147153
}
148154
},
149-
FieldDefinition: node => {
155+
FieldDefinition: (node) => {
150156
const fieldName = node.name.value;
151157

152158
return {
@@ -158,15 +164,15 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
158164
},
159165
};
160166
},
161-
InputObjectTypeDefinition: node => {
167+
InputObjectTypeDefinition: (node) => {
162168
const fieldName = node.name.value;
163169

164170
return {
165171
typeName: fieldName,
166172
mockFn: () => {
167173
const mockFields = node.fields
168174
? node.fields
169-
.map(field => {
175+
.map((field) => {
170176
const value = generateMockValue(fieldName, field.name.value, types, field.type);
171177

172178
return ` ${field.name.value}: ${value},`;
@@ -178,7 +184,7 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu
178184
},
179185
};
180186
},
181-
ObjectTypeDefinition: node => {
187+
ObjectTypeDefinition: (node) => {
182188
// This function triggered per each type
183189
const typeName = node.name.value;
184190

0 commit comments

Comments
 (0)