Skip to content

Commit 5db099f

Browse files
committed
init
1 parent ba1e6c7 commit 5db099f

12 files changed

+7121
-60
lines changed

.editorconfig

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# http://editorconfig.org
1+
# editorconfig.org
22
root = true
33

44
[*]
5-
charset = utf-8
6-
end_of_line = lf
7-
indent_size = 2
85
indent_style = space
9-
insert_final_newline = true
10-
max_line_length = 80
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
119
trim_trailing_whitespace = true
10+
insert_final_newline = true
1211

1312
[*.md]
14-
max_line_length = 0
1513
trim_trailing_whitespace = false

.eslintrc.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module.exports = {
2+
root: true,
3+
env: { es6: true },
4+
ignorePatterns: ['node_modules', 'build', 'coverage'],
5+
globals: { BigInt: true, console: true, WebAssembly: true },
6+
overrides: [
7+
{
8+
files: ['**/*.ts', '**/*.tsx'],
9+
extends: [
10+
'airbnb-typescript',
11+
'airbnb/hooks',
12+
'plugin:@typescript-eslint/recommended',
13+
'prettier',
14+
'prettier/react',
15+
'prettier/@typescript-eslint',
16+
],
17+
parserOptions: {
18+
tsconfigRootDir: __dirname,
19+
project: './tsconfig.json',
20+
},
21+
rules: {
22+
'import/order': [
23+
'error',
24+
{
25+
groups: ['builtin', 'external', 'parent', 'sibling', 'index'],
26+
'newlines-between': 'always',
27+
alphabetize: {
28+
order: 'asc',
29+
},
30+
},
31+
],
32+
'no-restricted-imports': 'off',
33+
'@typescript-eslint/explicit-module-boundary-types': 'off',
34+
},
35+
settings: {
36+
'import/parsers': {
37+
'@typescript-eslint/parser': ['.ts', '.tsx'],
38+
},
39+
'import/resolver': {
40+
typescript: {
41+
project: 'packages/*/tsconfig.json',
42+
},
43+
node: {
44+
extensions: ['.js', '.ts', '.jsx', '.tsx', '.json'],
45+
},
46+
},
47+
},
48+
},
49+
],
50+
};

.eslintrc.json

-34
This file was deleted.

.prettierrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true
4+
}

.vscode/extensions.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"recommendations": [
3-
"dbaeumer.vscode-eslint",
3+
"editorconfig.editorconfig",
44
"esbenp.prettier-vscode",
5-
"eamodio.gitlens",
6-
"streetsidesoftware.code-spell-checker",
5+
"dbaeumer.vscode-eslint",
6+
"mgmcdermott.vscode-language-babel"
77
]
88
}

.vscode/settings.json

+48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
{
2+
"css.validate": false,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true,
5+
"source.fixAll.stylelint": true
6+
},
27
"editor.formatOnSave": true,
8+
"editor.defaultFormatter": "esbenp.prettier-vscode",
9+
"html.format.enable": false,
10+
"javascript.format.enable": false,
11+
"json.format.enable": false,
12+
"scss.validate": false,
13+
"typescript.format.enable": false,
14+
"[html]": {
15+
"editor.defaultFormatter": "esbenp.prettier-vscode"
16+
},
17+
"[css]": {
18+
"editor.defaultFormatter": "esbenp.prettier-vscode"
19+
},
20+
"[scss]": {
21+
"editor.defaultFormatter": "esbenp.prettier-vscode"
22+
},
23+
"[sass]": {
24+
"editor.defaultFormatter": "esbenp.prettier-vscode"
25+
},
26+
"[json]": {
27+
"editor.defaultFormatter": "esbenp.prettier-vscode"
28+
},
29+
"[javascript]": {
30+
"editor.defaultFormatter": "esbenp.prettier-vscode"
31+
},
32+
"[javascriptreact]": {
33+
"editor.defaultFormatter": "esbenp.prettier-vscode"
34+
},
35+
"[typescript]": {
36+
"editor.defaultFormatter": "esbenp.prettier-vscode"
37+
},
38+
"[typescriptreact]": {
39+
"editor.defaultFormatter": "esbenp.prettier-vscode"
40+
},
41+
"eslint.validate": [
42+
"javascript",
43+
"javascriptreact",
44+
"typescript",
45+
"typescriptreact",
46+
"graphql"
47+
],
48+
"eslint.options": {
49+
"extentions": [".js", ".graphql"]
50+
},
351
"typescript.tsdk": "node_modules/typescript/lib",
452
"typescript.enablePromptUseWorkspaceTsdk": true
553
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# graphql-codegen-plugin-typescript-swr
22

3-
A GraphQL code generator plug-in that automatically generates utility functions for SWR.
3+
A [GraphQL code generator](https://graphql-code-generator.com/) plug-in that automatically generates utility functions for [SWR](https://swr.vercel.app/).

package.json

+36-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
"module": "build/module/index.js",
88
"repository": "https://github.com/croutonn/graphql-codegen-plugin-typescript-swr",
99
"license": "MIT",
10-
"keywords": [],
10+
"keywords": [
11+
"graphql",
12+
"codegen",
13+
"typescript",
14+
"ts",
15+
"swr",
16+
"stale-while-revalidate",
17+
"react"
18+
],
1119
"scripts": {
1220
"build": "run-p build:*",
1321
"build:main": "tsc -p tsconfig.json",
@@ -40,30 +48,44 @@
4048
"engines": {
4149
"node": ">=10"
4250
},
43-
"dependencies": {},
51+
"dependencies": {
52+
"@graphql-codegen/plugin-helpers": "^1.17.9",
53+
"@graphql-codegen/visitor-plugin-common": "^1.17.15",
54+
"auto-bind": "^4.0.0",
55+
"camel-case": "^4.1.1",
56+
"graphql": "^15.3.0",
57+
"pascal-case": "^3.1.1",
58+
"swr": "^0.3.5",
59+
"tslib": "^2.0.3"
60+
},
4461
"devDependencies": {
4562
"@ava/typescript": "^1.1.1",
4663
"@istanbuljs/nyc-config-typescript": "^1.0.1",
47-
"@typescript-eslint/eslint-plugin": "^4.0.1",
48-
"@typescript-eslint/parser": "^4.0.1",
49-
"ava": "^3.12.1",
50-
"codecov": "^3.5.0",
64+
"@types/node": "^14.11.8",
65+
"@typescript-eslint/eslint-plugin": "^4.4.1",
66+
"ava": "^3.13.0",
67+
"codecov": "^3.8.0",
5168
"cspell": "^4.1.0",
5269
"cz-conventional-changelog": "^3.3.0",
53-
"eslint": "^7.8.0",
54-
"eslint-config-prettier": "^6.11.0",
55-
"eslint-plugin-eslint-comments": "^3.2.0",
56-
"eslint-plugin-functional": "^3.0.2",
57-
"eslint-plugin-import": "^2.22.0",
70+
"eslint": "^7.11.0",
71+
"eslint-config-airbnb": "^18.2.0",
72+
"eslint-config-airbnb-typescript": "^11.0.0",
73+
"eslint-config-prettier": "^6.12.0",
74+
"eslint-import-resolver-typescript": "^2.3.0",
75+
"eslint-plugin-import": "^2.22.1",
76+
"eslint-plugin-jsx-a11y": "^6.3.1",
77+
"eslint-plugin-react": "^7.21.4",
78+
"eslint-plugin-react-hooks": "^4.1.2",
5879
"gh-pages": "^3.1.0",
5980
"npm-run-all": "^4.1.5",
6081
"nyc": "^15.1.0",
6182
"open-cli": "^6.0.1",
62-
"prettier": "^2.1.1",
83+
"prettier": "^2.1.2",
84+
"react": "^16.13.1",
6385
"standard-version": "^9.0.0",
6486
"ts-node": "^9.0.0",
65-
"typedoc": "^0.19.0",
66-
"typescript": "^4.0.2"
87+
"typedoc": "^0.19.2",
88+
"typescript": "^4.0.3"
6789
},
6890
"files": [
6991
"build/main",

src/config.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
2+
3+
/**
4+
* @description This plugin generates [`graphql-request`](https://www.npmjs.com/package/graphql-request) ready-to-use SDK, which is fully-typed.
5+
*/
6+
7+
export interface RawSWRPluginConfig extends RawClientSideBasePluginConfig {
8+
/**
9+
* @description By default the `request` method return the `data` or `errors` key from the response. If you need to access the `extensions` key you can use the `rawRequest` method.
10+
* @default false
11+
*
12+
* @exampleMarkdown
13+
* ```yml
14+
* generates:
15+
* path/to/file.ts:
16+
* plugins:
17+
* - typescript
18+
* - typescript-operations
19+
* - typescript-graphql-request
20+
* config:
21+
* rawRequest: true
22+
* ```
23+
*/
24+
rawRequest?: boolean;
25+
}

src/index.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
export * from './lib/number';
1+
import { extname } from 'path';
2+
3+
import {
4+
Types,
5+
PluginValidateFn,
6+
PluginFunction,
7+
} from '@graphql-codegen/plugin-helpers';
8+
import {
9+
RawClientSideBasePluginConfig,
10+
LoadedFragment,
11+
} from '@graphql-codegen/visitor-plugin-common';
12+
import {
13+
visit,
14+
GraphQLSchema,
15+
concatAST,
16+
Kind,
17+
FragmentDefinitionNode,
18+
} from 'graphql';
19+
20+
import { RawSWRPluginConfig } from './config';
21+
import { SWRVisitor } from './visitor';
22+
23+
export const plugin: PluginFunction<RawSWRPluginConfig> = (
24+
schema: GraphQLSchema,
25+
documents: Types.DocumentFile[],
26+
config: RawGraphQLRequestPluginConfig
27+
) => {
28+
const allAst = concatAST(documents.map((v) => v.document));
29+
};
30+
31+
export const validate: PluginValidateFn<any> = async (
32+
schema: GraphQLSchema,
33+
documents: Types.DocumentFile[],
34+
config: RawClientSideBasePluginConfig,
35+
outputFile: string
36+
) => {
37+
if (extname(outputFile) !== '.ts') {
38+
throw new Error(`Plugin "typescript-swr" requires extension to be ".ts"!`);
39+
}
40+
};
41+
42+
export { SWRVisitor };

src/visitor.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
ClientSideBasePluginConfig,
3+
ClientSideBaseVisitor,
4+
DocumentMode,
5+
getConfigValue,
6+
indentMultiline,
7+
LoadedFragment,
8+
} from '@graphql-codegen/visitor-plugin-common';
9+
import autoBind from 'auto-bind';
10+
import { GraphQLSchema, Kind, OperationDefinitionNode } from 'graphql';
11+
12+
import { RawSWRPluginConfig } from './config';
13+
14+
export interface SWRPluginConfig extends ClientSideBasePluginConfig {
15+
rawRequest: boolean;
16+
}
17+
18+
export class SWRVisitor extends ClientSideBaseVisitor<
19+
RawSWRPluginConfig,
20+
SWRPluginConfig
21+
> {}

0 commit comments

Comments
 (0)