├── .all-contributorsrc
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitattributes
├── .github
├── FUNDING.yml
└── workflows
│ └── ci.yml
├── .gitignore
├── .vim
└── coc-settings.json
├── .vscode
└── extensions.json
├── .yarn
├── plugins
│ └── @yarnpkg
│ │ └── plugin-workspace-tools.cjs
└── releases
│ └── yarn-3.2.1.cjs
├── .yarnrc.yml
├── LICENSE
├── README.md
├── examples
├── flow
│ ├── .flowconfig
│ ├── .gitattributes
│ ├── .gitignore
│ ├── .vim
│ │ └── coc-settings.json
│ ├── flow-typed
│ │ └── npm
│ │ │ ├── @babel
│ │ │ └── preset-flow_vx.x.x.js
│ │ │ ├── @octokit
│ │ │ └── rest_v18.x.x.js
│ │ │ ├── colors_v1.x.x.js
│ │ │ ├── flow-bin_v0.x.x.js
│ │ │ ├── fs-extra_v8.x.x.js
│ │ │ ├── gatsby-plugin-image_vx.x.x.js
│ │ │ ├── gatsby-plugin-react-helmet-async_vx.x.x.js
│ │ │ ├── gatsby-plugin-react-helmet_vx.x.x.js
│ │ │ ├── gatsby-plugin-sharp_vx.x.x.js
│ │ │ ├── gatsby-plugin-typegen_vx.x.x.js
│ │ │ ├── gatsby-source-filesystem_vx.x.x.js
│ │ │ ├── gatsby-transformer-sharp_vx.x.x.js
│ │ │ ├── gatsby_vx.x.x.js
│ │ │ ├── glob_v7.x.x.js
│ │ │ ├── jest_v27.x.x.js
│ │ │ ├── md5_v2.x.x.js
│ │ │ ├── mkdirp_v1.x.x.js
│ │ │ ├── node-stream-zip_v1.x.x.js
│ │ │ ├── prettier_v1.x.x.js
│ │ │ ├── react-dom_v18.x.x.js
│ │ │ ├── react-helmet-async_vx.x.x.js
│ │ │ ├── rimraf_v3.x.x.js
│ │ │ ├── semver_v7.x.x.js
│ │ │ ├── sharp_vx.x.x.js
│ │ │ └── yargs_v15.x.x.js
│ ├── gatsby-config.js
│ ├── gatsby-node.js
│ ├── package.json
│ └── src
│ │ ├── __generated__
│ │ ├── gatsby-introspection.json
│ │ ├── gatsby-plugin-documents.graphql
│ │ ├── gatsby-schema.graphql
│ │ └── gatsby-types.js
│ │ ├── components
│ │ ├── header.jsx
│ │ ├── layout.css
│ │ ├── layout.jsx
│ │ └── seo.jsx
│ │ ├── images
│ │ ├── gatsby-astronaut.png
│ │ └── gatsby-icon.png
│ │ └── pages
│ │ ├── 404.jsx
│ │ ├── index.jsx
│ │ └── page-2.jsx
├── mdx
│ ├── .gitignore
│ ├── gatsby-config.ts
│ ├── package.json
│ ├── src
│ │ ├── __generated__
│ │ │ ├── gatsby-introspection.json
│ │ │ ├── gatsby-plugin-documents.graphql
│ │ │ ├── gatsby-schema.graphql
│ │ │ └── gatsby-types.d.ts
│ │ ├── components
│ │ │ ├── header.tsx
│ │ │ ├── layout.css
│ │ │ ├── layout.tsx
│ │ │ └── seo.tsx
│ │ ├── images
│ │ │ ├── gatsby-astronaut.png
│ │ │ └── gatsby-icon.png
│ │ └── pages
│ │ │ ├── 404.tsx
│ │ │ ├── index.tsx
│ │ │ ├── page-2.tsx
│ │ │ └── using-mdx.mdx
│ └── tsconfig.json
└── typescript
│ ├── .gitignore
│ ├── gatsby-config.ts
│ ├── package.json
│ ├── src
│ ├── __generated__
│ │ ├── gatsby-introspection.json
│ │ ├── gatsby-plugin-documents.graphql
│ │ ├── gatsby-schema.graphql
│ │ └── gatsby-types.d.ts
│ ├── components
│ │ ├── header.tsx
│ │ ├── layout.css
│ │ ├── layout.tsx
│ │ └── seo.tsx
│ ├── images
│ │ ├── gatsby-astronaut.png
│ │ └── gatsby-icon.png
│ └── pages
│ │ ├── 404.tsx
│ │ ├── index.tsx
│ │ ├── page-2.tsx
│ │ └── using-typescript.tsx
│ └── tsconfig.json
├── package.json
├── plugin
├── .gitignore
├── LICENSE
├── README.md
├── __tests__
│ ├── __fixtures__
│ │ └── gatsby-schema.graphql
│ ├── __snapshots__
│ │ ├── schema.test.ts.snap
│ │ ├── service-codegen-flow.test.ts.snap
│ │ ├── service-codegen-typescript.test.ts.snap
│ │ ├── service-emitSchema-introspection.test.ts.snap
│ │ └── service-emitSchema-sdl.test.ts.snap
│ ├── schema.test.ts
│ ├── service-autofix.test.ts
│ ├── service-codegen-flow.test.ts
│ ├── service-codegen-typescript.test.ts
│ ├── service-emitSchema-0.test.ts
│ ├── service-emitSchema-introspection.test.ts
│ └── service-emitSchema-sdl.test.ts
├── babel.config.json
├── images
│ ├── auto-fixing-demo.gif
│ ├── gatsby-schema-visualized.png
│ ├── ts-graphql-plugin-demo.gif
│ ├── vscode-extension-preview.png
│ └── vscode-graphql-extension-preview.gif
├── index.js
├── package.json
├── src
│ ├── gatsby-node.ts
│ ├── internal
│ │ ├── config.ts
│ │ ├── machine.ts
│ │ ├── machine.typegen.ts
│ │ ├── pluginOptions.ts
│ │ ├── reporter.ts
│ │ └── utils.ts
│ ├── services
│ │ ├── autofix.ts
│ │ ├── codegen.ts
│ │ ├── emitPluginDocument.ts
│ │ └── emitSchema.ts
│ ├── types.flow.js
│ ├── types.ts
│ ├── typing
│ │ └── gatsby.d.ts
│ └── utils.ts
├── test
│ └── reporter.ts
├── tsconfig.build.json
└── tsconfig.json
├── tsconfig.json
└── yarn.lock
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "gatsby-plugin-typegen",
3 | "projectOwner": "cometkim",
4 | "repoType": "github",
5 | "repoHost": "https://github.com",
6 | "files": [
7 | "README.md",
8 | "plugin/README.md"
9 | ],
10 | "imageSize": 100,
11 | "commit": true,
12 | "commitConvention": "none",
13 | "contributors": [
14 | {
15 | "login": "cometkim",
16 | "name": "Hyeseong Kim",
17 | "avatar_url": "https://avatars3.githubusercontent.com/u/9696352?v=4",
18 | "profile": "https://blog.cometkim.kr/",
19 | "contributions": [
20 | "maintenance",
21 | "code",
22 | "doc",
23 | "bug",
24 | "ideas",
25 | "review"
26 | ]
27 | },
28 | {
29 | "login": "relefant",
30 | "name": "Richard Sewell",
31 | "avatar_url": "https://avatars0.githubusercontent.com/u/10079653?v=4",
32 | "profile": "https://github.com/relefant",
33 | "contributions": [
34 | "code",
35 | "maintenance"
36 | ]
37 | },
38 | {
39 | "login": "d4rekanguok",
40 | "name": "Derek Nguyen",
41 | "avatar_url": "https://avatars2.githubusercontent.com/u/3383539?v=4",
42 | "profile": "https://github.com/d4rekanguok",
43 | "contributions": [
44 | "code",
45 | "maintenance"
46 | ]
47 | },
48 | {
49 | "login": "sdobz",
50 | "name": "Vincent Khougaz",
51 | "avatar_url": "https://avatars1.githubusercontent.com/u/948178?v=4",
52 | "profile": "https://specific.solutions.limited",
53 | "contributions": [
54 | "code"
55 | ]
56 | },
57 | {
58 | "login": "disjukr",
59 | "name": "JongChan Choi",
60 | "avatar_url": "https://avatars0.githubusercontent.com/u/690661?v=4",
61 | "profile": "https://0xabcdef.com/",
62 | "contributions": [
63 | "code",
64 | "doc"
65 | ]
66 | },
67 | {
68 | "login": "johnrom",
69 | "name": "John Rom",
70 | "avatar_url": "https://avatars3.githubusercontent.com/u/1881482?v=4",
71 | "profile": "http://www.johnrom.com",
72 | "contributions": [
73 | "code"
74 | ]
75 | },
76 | {
77 | "login": "Js-Brecht",
78 | "name": "Jeremy Albright",
79 | "avatar_url": "https://avatars3.githubusercontent.com/u/1935258?v=4",
80 | "profile": "https://github.com/Js-Brecht",
81 | "contributions": [
82 | "code",
83 | "bug",
84 | "ideas",
85 | "review"
86 | ]
87 | },
88 | {
89 | "login": "lfrancke",
90 | "name": "Lars Francke",
91 | "avatar_url": "https://avatars2.githubusercontent.com/u/122850?v=4",
92 | "profile": "http://www.opencore.com",
93 | "contributions": [
94 | "doc"
95 | ]
96 | },
97 | {
98 | "login": "hasparus",
99 | "name": "Piotr Monwid-Olechnowicz",
100 | "avatar_url": "https://avatars0.githubusercontent.com/u/15332326?v=4",
101 | "profile": "https://haspar.us",
102 | "contributions": [
103 | "doc"
104 | ]
105 | },
106 | {
107 | "login": "edykim",
108 | "name": "Edward Kim",
109 | "avatar_url": "https://avatars3.githubusercontent.com/u/33057457?v=4",
110 | "profile": "http://edykim.com",
111 | "contributions": [
112 | "bug",
113 | "code"
114 | ]
115 | },
116 | {
117 | "login": "forivall",
118 | "name": "Emily Marigold Klassen",
119 | "avatar_url": "https://avatars1.githubusercontent.com/u/760204?v=4",
120 | "profile": "http://forivall.com",
121 | "contributions": [
122 | "doc"
123 | ]
124 | },
125 | {
126 | "login": "ThijmenDeValk",
127 | "name": "Thijmen",
128 | "avatar_url": "https://avatars.githubusercontent.com/u/10213180?v=4",
129 | "profile": "http://madebythijmen.nl",
130 | "contributions": [
131 | "maintenance"
132 | ]
133 | },
134 | {
135 | "login": "GallardoCode",
136 | "name": "Ricardo Gallardo",
137 | "avatar_url": "https://avatars.githubusercontent.com/u/37138993?v=4",
138 | "profile": "https://github.com/GallardoCode",
139 | "contributions": [
140 | "doc"
141 | ]
142 | },
143 | {
144 | "login": "ofqwx",
145 | "name": "Antonio Aznarez",
146 | "avatar_url": "https://avatars.githubusercontent.com/u/7224857?v=4",
147 | "profile": "https://github.com/ofqwx",
148 | "contributions": [
149 | "code"
150 | ]
151 | }
152 | ],
153 | "contributorsPerLine": 7,
154 | "skipCi": true
155 | }
156 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | indent_size = 2
7 | indent_style = space
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | **/*.d.ts
2 | **/*.js
3 | !.eslintrc.js
4 | !plugin/babel.config.js
5 | !plugin/jest.config.js
6 |
7 | *.typegen.ts
8 |
9 | # Hack for flow
10 | plugin/src/types.js
11 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | /* eslint-env node */
2 |
3 | require('@rushstack/eslint-patch/modern-module-resolution');
4 |
5 | module.exports = {
6 | root: true,
7 | globals: {
8 | GatsbyTypes: 'readonly',
9 | },
10 | parserOptions: {
11 | tsconfigRootDir: __dirname,
12 | project: [
13 | './tsconfig.json',
14 | './plugin/tsconfig.json',
15 | './examples/**/tsconfig.json',
16 | ],
17 | },
18 | plugins: [
19 | '@cometjs',
20 | ],
21 | extends: [
22 | 'plugin:@cometjs/auto',
23 | ],
24 | rules: {
25 | '@typescript-eslint/no-var-requires': 'off',
26 | '@typescript-eslint/no-unsafe-call': 'off',
27 | '@typescript-eslint/no-unsafe-return': 'off',
28 | '@typescript-eslint/no-unsafe-argument': 'off',
29 | '@typescript-eslint/no-unsafe-assignment': 'off',
30 | '@typescript-eslint/no-unsafe-member-access': 'off',
31 | },
32 | };
33 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | /.yarn/** linguist-vendored
2 | /.pnp.* binary linguist-generated
3 |
4 | /.vscode/*.json linguist-language=JSON5
5 |
6 | **/__generated__/** linguist-generated
7 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | open_collective: gatsby-plugin-typegen
2 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Integration
2 |
3 | on:
4 | push:
5 | branches: [main]
6 |
7 | pull_request:
8 | branches: [main]
9 |
10 | jobs:
11 | chore:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v3
15 | - name: Use Node.js 16.x
16 | uses: actions/setup-node@v3
17 | with:
18 | node-version: 16
19 | - name: Get yarn cache directory path
20 | id: yarn-cache-dir-path
21 | run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
22 | - uses: actions/cache@v3
23 | id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
24 | with:
25 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
26 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
27 | restore-keys: |
28 | ${{ runner.os }}-yarn-
29 | - name: Check dependencies
30 | run: yarn install --immutable
31 | - run: yarn lint
32 | - run: yarn tsc:check
33 |
34 | plugin:
35 | runs-on: ubuntu-latest
36 | steps:
37 | - uses: actions/checkout@v3
38 | - name: Use Node.js 16.x
39 | uses: actions/setup-node@v3
40 | with:
41 | node-version: 16
42 | - name: Get yarn cache directory path
43 | id: yarn-cache-dir-path
44 | run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
45 | - uses: actions/cache@v3
46 | id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
47 | with:
48 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
49 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
50 | restore-keys: |
51 | ${{ runner.os }}-yarn-
52 | - name: Check dependencies
53 | run: yarn install --immutable
54 | - run: yarn workspace gatsby-plugin-typegen test --coverage
55 | - run: yarn workspace gatsby-plugin-typegen build
56 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.log
3 |
4 | # Coverage directory used by tools like istanbul
5 | coverage
6 |
7 | # Dependency directories
8 | node_modules/
9 |
10 | # Optional eslint cache
11 | .eslintcache
12 |
13 | # Output of 'npm pack'
14 | *.tgz
15 |
16 | # Yarn without P'n'P
17 | .pnp.*
18 | .yarn/*
19 | !.yarn/patches
20 | !.yarn/plugins
21 | !.yarn/releases
22 | !.yarn/sdks
23 | !.yarn/versions
24 |
--------------------------------------------------------------------------------
/.vim/coc-settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "eslint.format.enable": true,
3 | "eslint.autoFixOnSave": true,
4 | "eslint.packageManager": "yarn"
5 | }
6 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "dbaeumer.vscode-eslint"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/.yarnrc.yml:
--------------------------------------------------------------------------------
1 | nmMode: hardlinks-global
2 |
3 | nodeLinker: node-modules
4 |
5 | packageExtensions:
6 | "@xstate/machine-extractor@*":
7 | dependencies:
8 | "@babel/core": "*"
9 | "@xstate/tools-shared@*":
10 | dependencies:
11 | prettier: "*"
12 |
13 | plugins:
14 | - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
15 | spec: "@yarnpkg/plugin-workspace-tools"
16 |
17 | yarnPath: .yarn/releases/yarn-3.2.1.cjs
18 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Hyeseong Kim
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # gatsby-plugin-typegen
2 |
3 | [](https://opencollective.com/gatsby-plugin-typegen)
4 |
5 | [](#contributors-)
6 |
7 |
8 | Let's give developers using GatsbyJS better DX with extreme type-safety.
9 |
10 | - [Plugin](plugin): Source code of the plugin.
11 |
12 | - [TypeScript example](examples/typescript)
13 |
14 | - [Flow example](examples/flow)
15 |
16 | ## Contributors ✨
17 |
18 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
19 |
20 |
21 |
22 |
23 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
50 |
51 | ## Backers
52 |
53 | Thank you to all our backers! 🙏 [[Become a backers](https://opencollective.com/gatsby-plugin-typegen/contribute)]
54 |
55 |
56 |
57 | ## Sponsors
58 |
59 | Does your company has large GatsbyJS codebase? Consider supporting this project! It can help contributors to develop tools and discover patterns so that we can use GatsbyJS more soundly. [[Become a sponsor](https://opencollective.com/gatsby-plugin-typegen/contribute)]
60 |
61 |
62 |
63 |
64 | ## LICENSE
65 |
66 | MIT
67 |
--------------------------------------------------------------------------------
/examples/flow/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 |
3 | [include]
4 |
5 | [libs]
6 | ./src/__generated__/gatsby-types.js
7 |
8 | [lints]
9 |
10 | [options]
11 |
12 | [strict]
13 |
--------------------------------------------------------------------------------
/examples/flow/.gitattributes:
--------------------------------------------------------------------------------
1 | flow-typed/**/*.js linguist-vendored
2 |
--------------------------------------------------------------------------------
/examples/flow/.gitignore:
--------------------------------------------------------------------------------
1 | .cache/
2 | public/
3 |
--------------------------------------------------------------------------------
/examples/flow/.vim/coc-settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "typescript.validate.enable": false,
3 | "flow.enable": true,
4 | "flow.useNPMPackagedFlow": true
5 | }
6 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/@babel/preset-flow_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 4bd02b62b28ea3597f6f0f3f0d9567a2
2 | // flow-typed version: <>/@babel/preset-flow_v^7.17.12/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * '@babel/preset-flow'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module '@babel/preset-flow' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module '@babel/preset-flow/lib' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module '@babel/preset-flow/lib/normalize-options' {
30 | declare module.exports: any;
31 | }
32 |
33 | // Filename aliases
34 | declare module '@babel/preset-flow/lib/index' {
35 | declare module.exports: $Exports<'@babel/preset-flow/lib'>;
36 | }
37 | declare module '@babel/preset-flow/lib/index.js' {
38 | declare module.exports: $Exports<'@babel/preset-flow/lib'>;
39 | }
40 | declare module '@babel/preset-flow/lib/normalize-options.js' {
41 | declare module.exports: $Exports<'@babel/preset-flow/lib/normalize-options'>;
42 | }
43 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/@octokit/rest_v18.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: a09a5a92a3c1ded961684da6ff393a70
2 | // flow-typed version: 15ea1b476e/@octokit/rest_v18.x.x/flow_>=v0.83.x
3 |
4 | declare module '@octokit/rest' {
5 | declare class Octokit {
6 | (options?: {| [key: string]: any |}): this;
7 |
8 | actions: {| [key: string]: any |},
9 | activity: {| [key: string]: any |},
10 | apps: {| [key: string]: any |},
11 | auth: (...args: Array) => Promise<{| [key: string]: any |}>,
12 | billing: {| [key: string]: any |},
13 | checks: {| [key: string]: any |},
14 | codeScanning: {| [key: string]: any |},
15 | codesOfConduct: {| [key: string]: any |},
16 | emojis: {| [key: string]: any |},
17 | enterpriseAdmin: {| [key: string]: any |},
18 | gists: {| [key: string]: any |},
19 | git: {| [key: string]: any |},
20 | gitignore: {| [key: string]: any |},
21 | graphql: (...args: Array) => any,
22 | hook: (...args: Array) => any,
23 | interactions: {| [key: string]: any |},
24 | issues: {| [key: string]: any |},
25 | licenses: {| [key: string]: any |},
26 | log:{| [key: string]: any |},
27 | markdown: {| [key: string]: any |},
28 | meta: {| [key: string]: any |},
29 | migrations: {| [key: string]: any |},
30 | orgs: {| [key: string]: any |},
31 | packages: {| [key: string]: any |},
32 | paginate: (...args: Array) => any,
33 | projects: {| [key: string]: any |},
34 | pulls: {| [key: string]: any |},
35 | rateLimit: {| [key: string]: any |},
36 | reactions: {| [key: string]: any |},
37 | repos: {
38 | getContent: ({|
39 | owner: string,
40 | repo: string,
41 | path?: string,
42 | ref?: string,
43 | |}) => Promise<{|
44 | data: Array<{|
45 | download_url: any,
46 | git_url: string,
47 | html_url: string,
48 | name: string,
49 | path: string,
50 | sha: string,
51 | size: number,
52 | type: string,
53 | url: string,
54 | _links: {|
55 | git: string,
56 | html: string,
57 | self: string,
58 | |}
59 | |}>,
60 | headers: {| [key: string]: any |},
61 | status: number,
62 | url: string,
63 | |}>,
64 | [key: string]: any,
65 | },
66 | request: (...args: Array) => any,
67 | rest: {| [key: string]: any |},
68 | search: {| [key: string]: any |},
69 | secretScanning: {| [key: string]: any |},
70 | teams: {| [key: string]: any |},
71 | users: {| [key: string]: any |},
72 | }
73 |
74 | declare module.exports: {|
75 | Octokit: typeof Octokit,
76 | |};
77 | }
78 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/colors_v1.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 6c56e55f6af24f47c33f50f10270785f
2 | // flow-typed version: 590676b089/colors_v1.x.x/flow_>=v0.104.x
3 |
4 | declare module "colors" {
5 | declare type Color = {
6 | (text: string): string,
7 | strip: Color,
8 | stripColors: Color,
9 | black: Color,
10 | red: Color,
11 | green: Color,
12 | yellow: Color,
13 | blue: Color,
14 | magenta: Color,
15 | cyan: Color,
16 | white: Color,
17 | gray: Color,
18 | grey: Color,
19 | bgBlack: Color,
20 | bgRed: Color,
21 | bgGreen: Color,
22 | bgYellow: Color,
23 | bgBlue: Color,
24 | bgMagenta: Color,
25 | bgCyan: Color,
26 | bgWhite: Color,
27 | reset: Color,
28 | bold: Color,
29 | dim: Color,
30 | italic: Color,
31 | underline: Color,
32 | inverse: Color,
33 | hidden: Color,
34 | strikethrough: Color,
35 | rainbow: Color,
36 | zebra: Color,
37 | america: Color,
38 | trap: Color,
39 | random: Color,
40 | zalgo: Color,
41 | ...
42 | };
43 |
44 | declare module.exports: {
45 | enabled: boolean,
46 | themes: {...},
47 | enable(): void,
48 | disable(): void,
49 | setTheme(theme: {...}): void,
50 | strip: Color,
51 | stripColors: Color,
52 | black: Color,
53 | red: Color,
54 | green: Color,
55 | yellow: Color,
56 | blue: Color,
57 | magenta: Color,
58 | cyan: Color,
59 | white: Color,
60 | gray: Color,
61 | grey: Color,
62 | bgBlack: Color,
63 | bgRed: Color,
64 | bgGreen: Color,
65 | bgYellow: Color,
66 | bgBlue: Color,
67 | bgMagenta: Color,
68 | bgCyan: Color,
69 | bgWhite: Color,
70 | reset: Color,
71 | bold: Color,
72 | dim: Color,
73 | italic: Color,
74 | underline: Color,
75 | inverse: Color,
76 | hidden: Color,
77 | strikethrough: Color,
78 | rainbow: Color,
79 | zebra: Color,
80 | america: Color,
81 | trap: Color,
82 | random: Color,
83 | zalgo: Color,
84 | ...
85 | };
86 | }
87 |
88 | declare module "colors/safe" {
89 | declare module.exports: $Exports<"colors">;
90 | }
91 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/flow-bin_v0.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 28fdff7f110e1c75efab63ff205dda30
2 | // flow-typed version: c6154227d1/flow-bin_v0.x.x/flow_>=v0.104.x
3 |
4 | declare module "flow-bin" {
5 | declare module.exports: string;
6 | }
7 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/gatsby-plugin-react-helmet-async_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 68d88b9a910b8279e7c89d7157303023
2 | // flow-typed version: <>/gatsby-plugin-react-helmet-async_v^1.2.1/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'gatsby-plugin-react-helmet-async'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'gatsby-plugin-react-helmet-async' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'gatsby-plugin-react-helmet-async/gatsby-browser' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'gatsby-plugin-react-helmet-async/gatsby-ssr' {
30 | declare module.exports: any;
31 | }
32 |
33 | // Filename aliases
34 | declare module 'gatsby-plugin-react-helmet-async/gatsby-browser.js' {
35 | declare module.exports: $Exports<'gatsby-plugin-react-helmet-async/gatsby-browser'>;
36 | }
37 | declare module 'gatsby-plugin-react-helmet-async/gatsby-ssr.js' {
38 | declare module.exports: $Exports<'gatsby-plugin-react-helmet-async/gatsby-ssr'>;
39 | }
40 | declare module 'gatsby-plugin-react-helmet-async/index' {
41 | declare module.exports: $Exports<'gatsby-plugin-react-helmet-async'>;
42 | }
43 | declare module 'gatsby-plugin-react-helmet-async/index.js' {
44 | declare module.exports: $Exports<'gatsby-plugin-react-helmet-async'>;
45 | }
46 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/gatsby-plugin-react-helmet_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 13fa6a1fe3c5cd88312afd433c6749ac
2 | // flow-typed version: <>/gatsby-plugin-react-helmet_v^5.9.0/flow_v0.173.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'gatsby-plugin-react-helmet'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'gatsby-plugin-react-helmet' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'gatsby-plugin-react-helmet/gatsby-node' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'gatsby-plugin-react-helmet/gatsby-ssr' {
30 | declare module.exports: any;
31 | }
32 |
33 | // Filename aliases
34 | declare module 'gatsby-plugin-react-helmet/gatsby-node.js' {
35 | declare module.exports: $Exports<'gatsby-plugin-react-helmet/gatsby-node'>;
36 | }
37 | declare module 'gatsby-plugin-react-helmet/gatsby-ssr.js' {
38 | declare module.exports: $Exports<'gatsby-plugin-react-helmet/gatsby-ssr'>;
39 | }
40 | declare module 'gatsby-plugin-react-helmet/index' {
41 | declare module.exports: $Exports<'gatsby-plugin-react-helmet'>;
42 | }
43 | declare module 'gatsby-plugin-react-helmet/index.js' {
44 | declare module.exports: $Exports<'gatsby-plugin-react-helmet'>;
45 | }
46 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/gatsby-plugin-sharp_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 4e938ca9aac2c711170f43ae7f91c82d
2 | // flow-typed version: <>/gatsby-plugin-sharp_v^4.16.1/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'gatsby-plugin-sharp'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'gatsby-plugin-sharp' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'gatsby-plugin-sharp/duotone' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'gatsby-plugin-sharp/gatsby-node' {
30 | declare module.exports: any;
31 | }
32 |
33 | declare module 'gatsby-plugin-sharp/gatsby-worker' {
34 | declare module.exports: any;
35 | }
36 |
37 | declare module 'gatsby-plugin-sharp/image-data' {
38 | declare module.exports: any;
39 | }
40 |
41 | declare module 'gatsby-plugin-sharp/plugin-options' {
42 | declare module.exports: any;
43 | }
44 |
45 | declare module 'gatsby-plugin-sharp/process-file' {
46 | declare module.exports: any;
47 | }
48 |
49 | declare module 'gatsby-plugin-sharp/report-error' {
50 | declare module.exports: any;
51 | }
52 |
53 | declare module 'gatsby-plugin-sharp/safe-sharp.d' {
54 | declare module.exports: any;
55 | }
56 |
57 | declare module 'gatsby-plugin-sharp/safe-sharp' {
58 | declare module.exports: any;
59 | }
60 |
61 | declare module 'gatsby-plugin-sharp/sharp-error' {
62 | declare module.exports: any;
63 | }
64 |
65 | declare module 'gatsby-plugin-sharp/trace-svg' {
66 | declare module.exports: any;
67 | }
68 |
69 | declare module 'gatsby-plugin-sharp/utils' {
70 | declare module.exports: any;
71 | }
72 |
73 | // Filename aliases
74 | declare module 'gatsby-plugin-sharp/duotone.js' {
75 | declare module.exports: $Exports<'gatsby-plugin-sharp/duotone'>;
76 | }
77 | declare module 'gatsby-plugin-sharp/gatsby-node.js' {
78 | declare module.exports: $Exports<'gatsby-plugin-sharp/gatsby-node'>;
79 | }
80 | declare module 'gatsby-plugin-sharp/gatsby-worker.js' {
81 | declare module.exports: $Exports<'gatsby-plugin-sharp/gatsby-worker'>;
82 | }
83 | declare module 'gatsby-plugin-sharp/image-data.js' {
84 | declare module.exports: $Exports<'gatsby-plugin-sharp/image-data'>;
85 | }
86 | declare module 'gatsby-plugin-sharp/index' {
87 | declare module.exports: $Exports<'gatsby-plugin-sharp'>;
88 | }
89 | declare module 'gatsby-plugin-sharp/index.js' {
90 | declare module.exports: $Exports<'gatsby-plugin-sharp'>;
91 | }
92 | declare module 'gatsby-plugin-sharp/plugin-options.js' {
93 | declare module.exports: $Exports<'gatsby-plugin-sharp/plugin-options'>;
94 | }
95 | declare module 'gatsby-plugin-sharp/process-file.js' {
96 | declare module.exports: $Exports<'gatsby-plugin-sharp/process-file'>;
97 | }
98 | declare module 'gatsby-plugin-sharp/report-error.js' {
99 | declare module.exports: $Exports<'gatsby-plugin-sharp/report-error'>;
100 | }
101 | declare module 'gatsby-plugin-sharp/safe-sharp.d.js' {
102 | declare module.exports: $Exports<'gatsby-plugin-sharp/safe-sharp.d'>;
103 | }
104 | declare module 'gatsby-plugin-sharp/safe-sharp.js' {
105 | declare module.exports: $Exports<'gatsby-plugin-sharp/safe-sharp'>;
106 | }
107 | declare module 'gatsby-plugin-sharp/sharp-error.js' {
108 | declare module.exports: $Exports<'gatsby-plugin-sharp/sharp-error'>;
109 | }
110 | declare module 'gatsby-plugin-sharp/trace-svg.js' {
111 | declare module.exports: $Exports<'gatsby-plugin-sharp/trace-svg'>;
112 | }
113 | declare module 'gatsby-plugin-sharp/utils.js' {
114 | declare module.exports: $Exports<'gatsby-plugin-sharp/utils'>;
115 | }
116 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/gatsby-plugin-typegen_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 4abbdf52da955e04405b80744df5da6b
2 | // flow-typed version: <>/gatsby-plugin-typegen_vportal:../../plugin/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'gatsby-plugin-typegen'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'gatsby-plugin-typegen' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'gatsby-plugin-typegen/gatsby-node' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'gatsby-plugin-typegen/internal/config' {
30 | declare module.exports: any;
31 | }
32 |
33 | declare module 'gatsby-plugin-typegen/internal/machine' {
34 | declare module.exports: any;
35 | }
36 |
37 | declare module 'gatsby-plugin-typegen/internal/machine.typegen' {
38 | declare module.exports: any;
39 | }
40 |
41 | declare module 'gatsby-plugin-typegen/internal/pluginOptions' {
42 | declare module.exports: any;
43 | }
44 |
45 | declare module 'gatsby-plugin-typegen/internal/reporter' {
46 | declare module.exports: any;
47 | }
48 |
49 | declare module 'gatsby-plugin-typegen/internal/utils' {
50 | declare module.exports: any;
51 | }
52 |
53 | declare module 'gatsby-plugin-typegen/services/autofix' {
54 | declare module.exports: any;
55 | }
56 |
57 | declare module 'gatsby-plugin-typegen/services/codegen' {
58 | declare module.exports: any;
59 | }
60 |
61 | declare module 'gatsby-plugin-typegen/services/emitPluginDocument' {
62 | declare module.exports: any;
63 | }
64 |
65 | declare module 'gatsby-plugin-typegen/services/emitSchema' {
66 | declare module.exports: any;
67 | }
68 |
69 | declare module 'gatsby-plugin-typegen/src/types.flow' {
70 | declare module.exports: any;
71 | }
72 |
73 | declare module 'gatsby-plugin-typegen/types.flow' {
74 | declare module.exports: any;
75 | }
76 |
77 | declare module 'gatsby-plugin-typegen/types' {
78 | declare module.exports: any;
79 | }
80 |
81 | declare module 'gatsby-plugin-typegen/typing/gatsby.d' {
82 | declare module.exports: any;
83 | }
84 |
85 | declare module 'gatsby-plugin-typegen/utils' {
86 | declare module.exports: any;
87 | }
88 |
89 | // Filename aliases
90 | declare module 'gatsby-plugin-typegen/gatsby-node.js' {
91 | declare module.exports: $Exports<'gatsby-plugin-typegen/gatsby-node'>;
92 | }
93 | declare module 'gatsby-plugin-typegen/index' {
94 | declare module.exports: $Exports<'gatsby-plugin-typegen'>;
95 | }
96 | declare module 'gatsby-plugin-typegen/index.js' {
97 | declare module.exports: $Exports<'gatsby-plugin-typegen'>;
98 | }
99 | declare module 'gatsby-plugin-typegen/internal/config.js' {
100 | declare module.exports: $Exports<'gatsby-plugin-typegen/internal/config'>;
101 | }
102 | declare module 'gatsby-plugin-typegen/internal/machine.js' {
103 | declare module.exports: $Exports<'gatsby-plugin-typegen/internal/machine'>;
104 | }
105 | declare module 'gatsby-plugin-typegen/internal/machine.typegen.js' {
106 | declare module.exports: $Exports<'gatsby-plugin-typegen/internal/machine.typegen'>;
107 | }
108 | declare module 'gatsby-plugin-typegen/internal/pluginOptions.js' {
109 | declare module.exports: $Exports<'gatsby-plugin-typegen/internal/pluginOptions'>;
110 | }
111 | declare module 'gatsby-plugin-typegen/internal/reporter.js' {
112 | declare module.exports: $Exports<'gatsby-plugin-typegen/internal/reporter'>;
113 | }
114 | declare module 'gatsby-plugin-typegen/internal/utils.js' {
115 | declare module.exports: $Exports<'gatsby-plugin-typegen/internal/utils'>;
116 | }
117 | declare module 'gatsby-plugin-typegen/services/autofix.js' {
118 | declare module.exports: $Exports<'gatsby-plugin-typegen/services/autofix'>;
119 | }
120 | declare module 'gatsby-plugin-typegen/services/codegen.js' {
121 | declare module.exports: $Exports<'gatsby-plugin-typegen/services/codegen'>;
122 | }
123 | declare module 'gatsby-plugin-typegen/services/emitPluginDocument.js' {
124 | declare module.exports: $Exports<'gatsby-plugin-typegen/services/emitPluginDocument'>;
125 | }
126 | declare module 'gatsby-plugin-typegen/services/emitSchema.js' {
127 | declare module.exports: $Exports<'gatsby-plugin-typegen/services/emitSchema'>;
128 | }
129 | declare module 'gatsby-plugin-typegen/src/types.flow.js' {
130 | declare module.exports: $Exports<'gatsby-plugin-typegen/src/types.flow'>;
131 | }
132 | declare module 'gatsby-plugin-typegen/types.flow.js' {
133 | declare module.exports: $Exports<'gatsby-plugin-typegen/types.flow'>;
134 | }
135 | declare module 'gatsby-plugin-typegen/types.js' {
136 | declare module.exports: $Exports<'gatsby-plugin-typegen/types'>;
137 | }
138 | declare module 'gatsby-plugin-typegen/typing/gatsby.d.js' {
139 | declare module.exports: $Exports<'gatsby-plugin-typegen/typing/gatsby.d'>;
140 | }
141 | declare module 'gatsby-plugin-typegen/utils.js' {
142 | declare module.exports: $Exports<'gatsby-plugin-typegen/utils'>;
143 | }
144 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/gatsby-source-filesystem_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 0e5a9bbebdf81d517feaea3d358006ef
2 | // flow-typed version: <>/gatsby-source-filesystem_v^4.16.0/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'gatsby-source-filesystem'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'gatsby-source-filesystem' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'gatsby-source-filesystem/create-file-node-from-buffer' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'gatsby-source-filesystem/create-file-node' {
30 | declare module.exports: any;
31 | }
32 |
33 | declare module 'gatsby-source-filesystem/create-file-path' {
34 | declare module.exports: any;
35 | }
36 |
37 | declare module 'gatsby-source-filesystem/create-remote-file-node' {
38 | declare module.exports: any;
39 | }
40 |
41 | declare module 'gatsby-source-filesystem/error-utils' {
42 | declare module.exports: any;
43 | }
44 |
45 | declare module 'gatsby-source-filesystem/extend-file-node' {
46 | declare module.exports: any;
47 | }
48 |
49 | declare module 'gatsby-source-filesystem/gatsby-node' {
50 | declare module.exports: any;
51 | }
52 |
53 | declare module 'gatsby-source-filesystem/utils' {
54 | declare module.exports: any;
55 | }
56 |
57 | // Filename aliases
58 | declare module 'gatsby-source-filesystem/create-file-node-from-buffer.js' {
59 | declare module.exports: $Exports<'gatsby-source-filesystem/create-file-node-from-buffer'>;
60 | }
61 | declare module 'gatsby-source-filesystem/create-file-node.js' {
62 | declare module.exports: $Exports<'gatsby-source-filesystem/create-file-node'>;
63 | }
64 | declare module 'gatsby-source-filesystem/create-file-path.js' {
65 | declare module.exports: $Exports<'gatsby-source-filesystem/create-file-path'>;
66 | }
67 | declare module 'gatsby-source-filesystem/create-remote-file-node.js' {
68 | declare module.exports: $Exports<'gatsby-source-filesystem/create-remote-file-node'>;
69 | }
70 | declare module 'gatsby-source-filesystem/error-utils.js' {
71 | declare module.exports: $Exports<'gatsby-source-filesystem/error-utils'>;
72 | }
73 | declare module 'gatsby-source-filesystem/extend-file-node.js' {
74 | declare module.exports: $Exports<'gatsby-source-filesystem/extend-file-node'>;
75 | }
76 | declare module 'gatsby-source-filesystem/gatsby-node.js' {
77 | declare module.exports: $Exports<'gatsby-source-filesystem/gatsby-node'>;
78 | }
79 | declare module 'gatsby-source-filesystem/index' {
80 | declare module.exports: $Exports<'gatsby-source-filesystem'>;
81 | }
82 | declare module 'gatsby-source-filesystem/index.js' {
83 | declare module.exports: $Exports<'gatsby-source-filesystem'>;
84 | }
85 | declare module 'gatsby-source-filesystem/utils.js' {
86 | declare module.exports: $Exports<'gatsby-source-filesystem/utils'>;
87 | }
88 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/gatsby-transformer-sharp_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 58146507270e8f58aef1ea4300696ee3
2 | // flow-typed version: <>/gatsby-transformer-sharp_v^4.16.0/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'gatsby-transformer-sharp'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'gatsby-transformer-sharp' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'gatsby-transformer-sharp/create-resolvers' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'gatsby-transformer-sharp/customize-schema' {
30 | declare module.exports: any;
31 | }
32 |
33 | declare module 'gatsby-transformer-sharp/error-utils' {
34 | declare module.exports: any;
35 | }
36 |
37 | declare module 'gatsby-transformer-sharp/fragments' {
38 | declare module.exports: any;
39 | }
40 |
41 | declare module 'gatsby-transformer-sharp/gatsby-node' {
42 | declare module.exports: any;
43 | }
44 |
45 | declare module 'gatsby-transformer-sharp/on-node-create' {
46 | declare module.exports: any;
47 | }
48 |
49 | declare module 'gatsby-transformer-sharp/safe-sharp' {
50 | declare module.exports: any;
51 | }
52 |
53 | declare module 'gatsby-transformer-sharp/src/create-resolvers' {
54 | declare module.exports: any;
55 | }
56 |
57 | declare module 'gatsby-transformer-sharp/src/customize-schema' {
58 | declare module.exports: any;
59 | }
60 |
61 | declare module 'gatsby-transformer-sharp/src/error-utils' {
62 | declare module.exports: any;
63 | }
64 |
65 | declare module 'gatsby-transformer-sharp/src/fragments' {
66 | declare module.exports: any;
67 | }
68 |
69 | declare module 'gatsby-transformer-sharp/src/gatsby-node' {
70 | declare module.exports: any;
71 | }
72 |
73 | declare module 'gatsby-transformer-sharp/src/on-node-create' {
74 | declare module.exports: any;
75 | }
76 |
77 | declare module 'gatsby-transformer-sharp/src/safe-sharp' {
78 | declare module.exports: any;
79 | }
80 |
81 | declare module 'gatsby-transformer-sharp/src/supported-extensions' {
82 | declare module.exports: any;
83 | }
84 |
85 | declare module 'gatsby-transformer-sharp/supported-extensions' {
86 | declare module.exports: any;
87 | }
88 |
89 | declare module 'gatsby-transformer-sharp/types' {
90 | declare module.exports: any;
91 | }
92 |
93 | // Filename aliases
94 | declare module 'gatsby-transformer-sharp/create-resolvers.js' {
95 | declare module.exports: $Exports<'gatsby-transformer-sharp/create-resolvers'>;
96 | }
97 | declare module 'gatsby-transformer-sharp/customize-schema.js' {
98 | declare module.exports: $Exports<'gatsby-transformer-sharp/customize-schema'>;
99 | }
100 | declare module 'gatsby-transformer-sharp/error-utils.js' {
101 | declare module.exports: $Exports<'gatsby-transformer-sharp/error-utils'>;
102 | }
103 | declare module 'gatsby-transformer-sharp/fragments.js' {
104 | declare module.exports: $Exports<'gatsby-transformer-sharp/fragments'>;
105 | }
106 | declare module 'gatsby-transformer-sharp/gatsby-node.js' {
107 | declare module.exports: $Exports<'gatsby-transformer-sharp/gatsby-node'>;
108 | }
109 | declare module 'gatsby-transformer-sharp/index' {
110 | declare module.exports: $Exports<'gatsby-transformer-sharp'>;
111 | }
112 | declare module 'gatsby-transformer-sharp/index.js' {
113 | declare module.exports: $Exports<'gatsby-transformer-sharp'>;
114 | }
115 | declare module 'gatsby-transformer-sharp/on-node-create.js' {
116 | declare module.exports: $Exports<'gatsby-transformer-sharp/on-node-create'>;
117 | }
118 | declare module 'gatsby-transformer-sharp/safe-sharp.js' {
119 | declare module.exports: $Exports<'gatsby-transformer-sharp/safe-sharp'>;
120 | }
121 | declare module 'gatsby-transformer-sharp/src/create-resolvers.js' {
122 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/create-resolvers'>;
123 | }
124 | declare module 'gatsby-transformer-sharp/src/customize-schema.js' {
125 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/customize-schema'>;
126 | }
127 | declare module 'gatsby-transformer-sharp/src/error-utils.js' {
128 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/error-utils'>;
129 | }
130 | declare module 'gatsby-transformer-sharp/src/fragments.js' {
131 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/fragments'>;
132 | }
133 | declare module 'gatsby-transformer-sharp/src/gatsby-node.js' {
134 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/gatsby-node'>;
135 | }
136 | declare module 'gatsby-transformer-sharp/src/on-node-create.js' {
137 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/on-node-create'>;
138 | }
139 | declare module 'gatsby-transformer-sharp/src/safe-sharp.js' {
140 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/safe-sharp'>;
141 | }
142 | declare module 'gatsby-transformer-sharp/src/supported-extensions.js' {
143 | declare module.exports: $Exports<'gatsby-transformer-sharp/src/supported-extensions'>;
144 | }
145 | declare module 'gatsby-transformer-sharp/supported-extensions.js' {
146 | declare module.exports: $Exports<'gatsby-transformer-sharp/supported-extensions'>;
147 | }
148 | declare module 'gatsby-transformer-sharp/types.js' {
149 | declare module.exports: $Exports<'gatsby-transformer-sharp/types'>;
150 | }
151 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/glob_v7.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: d2a519d7d007e9ba3e5bf2ac3ff76eca
2 | // flow-typed version: f243e51ed7/glob_v7.x.x/flow_>=v0.104.x
3 |
4 | declare module "glob" {
5 | declare type MinimatchOptions = {|
6 | debug?: boolean,
7 | nobrace?: boolean,
8 | noglobstar?: boolean,
9 | dot?: boolean,
10 | noext?: boolean,
11 | nocase?: boolean,
12 | nonull?: boolean,
13 | matchBase?: boolean,
14 | nocomment?: boolean,
15 | nonegate?: boolean,
16 | flipNegate?: boolean
17 | |};
18 |
19 | declare type Options = {|
20 | ...MinimatchOptions,
21 | cwd?: string,
22 | root?: string,
23 | nomount?: boolean,
24 | mark?: boolean,
25 | nosort?: boolean,
26 | stat?: boolean,
27 | silent?: boolean,
28 | strict?: boolean,
29 | cache?: { [path: string]: boolean | "DIR" | "FILE" | $ReadOnlyArray, ... },
30 | statCache?: { [path: string]: boolean | { isDirectory(): boolean, ... } | void, ... },
31 | symlinks?: { [path: string]: boolean | void, ... },
32 | realpathCache?: { [path: string]: string, ... },
33 | sync?: boolean,
34 | nounique?: boolean,
35 | nodir?: boolean,
36 | ignore?: string | $ReadOnlyArray,
37 | follow?: boolean,
38 | realpath?: boolean,
39 | absolute?: boolean
40 | |};
41 |
42 | /**
43 | * Called when an error occurs, or matches are found
44 | * err
45 | * matches: filenames found matching the pattern
46 | */
47 | declare type CallBack = (err: ?Error, matches: Array) => void;
48 |
49 | declare class Glob extends events$EventEmitter {
50 | constructor(pattern: string): this;
51 | constructor(pattern: string, callback: CallBack): this;
52 | constructor(pattern: string, options: Options, callback: CallBack): this;
53 |
54 | minimatch: {...};
55 | options: Options;
56 | aborted: boolean;
57 | cache: { [path: string]: boolean | "DIR" | "FILE" | $ReadOnlyArray, ... };
58 | statCache: { [path: string]: boolean | { isDirectory(): boolean, ... } | void, ... };
59 | symlinks: { [path: string]: boolean | void, ... };
60 | realpathCache: { [path: string]: string, ... };
61 | found: Array;
62 |
63 | pause(): void;
64 | resume(): void;
65 | abort(): void;
66 | }
67 |
68 | declare class GlobModule {
69 | Glob: Class;
70 |
71 | (pattern: string, callback: CallBack): void;
72 | (pattern: string, options: Options, callback: CallBack): void;
73 |
74 | hasMagic(pattern: string, options?: Options): boolean;
75 | sync(pattern: string, options?: Options): Array;
76 | }
77 |
78 | declare module.exports: GlobModule;
79 | }
80 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/md5_v2.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 198b480a6b35dbf3a74cb37d21258b00
2 | // flow-typed version: c6154227d1/md5_v2.x.x/flow_>=v0.104.x
3 |
4 | // @flow
5 |
6 | declare module "md5" {
7 | declare module.exports: (
8 | message: string | Buffer,
9 | options?: {
10 | asString?: boolean,
11 | asBytes?: boolean,
12 | encoding?: string,
13 | ...
14 | }
15 | ) => string;
16 | }
17 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/mkdirp_v1.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 28ddcca31abd597a77830710de25f5fe
2 | // flow-typed version: a75473352d/mkdirp_v1.x.x/flow_>=v0.83.x
3 |
4 | declare module 'mkdirp' {
5 | import typeof { mkdir, stat } from 'fs';
6 |
7 | declare type FsImplementation = {
8 | +mkdir?: mkdir,
9 | +stat?: stat,
10 | ...
11 | };
12 |
13 | declare type Options = number | string | {| mode?: number; fs?: FsImplementation |};
14 |
15 | declare type Callback = (err: ?Error, path: ?string) => void;
16 |
17 | declare module.exports: {|
18 | (path: string, options?: Options | Callback): Promise;
19 | sync(path: string, options?: Options): string | void;
20 | manual(path: string, options?: Options | Callback): Promise;
21 | manualSync(path: string, options?: Options): string | void;
22 | native(path: string, options?: Options | Callback): Promise;
23 | nativeSync(path: string, options?: Options): string | void;
24 | |};
25 | }
26 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/node-stream-zip_v1.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: bd18604d0696d9e4ad0da443cf74273b
2 | // flow-typed version: 1ff21d416b/node-stream-zip_v1.x.x/flow_>=v0.104.x
3 |
4 | declare module 'node-stream-zip' {
5 | declare type StreamZipOptions = {|
6 | /**
7 | * File to read
8 | * @default undefined
9 | */
10 | file?: string;
11 |
12 | /**
13 | * Alternatively, you can pass fd here
14 | * @default undefined
15 | */
16 | fd?: number;
17 |
18 | /**
19 | * You will be able to work with entries inside zip archive,
20 | * otherwise the only way to access them is entry event
21 | * @default true
22 | */
23 | storeEntries?: boolean;
24 |
25 | /**
26 | * By default, entry name is checked for malicious characters, like ../ or c:\123,
27 | * pass this flag to disable validation error
28 | * @default false
29 | */
30 | skipEntryNameValidation?: boolean;
31 |
32 | /**
33 | * Filesystem read chunk size
34 | * @default automatic based on file size
35 | */
36 | chunkSize?: number;
37 |
38 | /**
39 | * Encoding used to decode file names
40 | * @default UTF8
41 | */
42 | nameEncoding?: string;
43 | |}
44 |
45 | declare type ZipEntry = {|
46 | /**
47 | * file name
48 | */
49 | name: string;
50 |
51 | /**
52 | * true if it's a directory entry
53 | */
54 | isDirectory: boolean;
55 |
56 | /**
57 | * true if it's a file entry, see also isDirectory
58 | */
59 | isFile: boolean;
60 |
61 | /**
62 | * file comment
63 | */
64 | comment: string;
65 |
66 | /**
67 | * if the file is encrypted
68 | */
69 | encrypted: boolean;
70 |
71 | /**
72 | * version made by
73 | */
74 | verMade: number;
75 |
76 | /**
77 | * version needed to extract
78 | */
79 | version: number;
80 |
81 | /**
82 | * encrypt, decrypt flags
83 | */
84 | flags: number;
85 |
86 | /**
87 | * compression method
88 | */
89 | method: number;
90 |
91 | /**
92 | * modification time
93 | */
94 | time: number;
95 |
96 | /**
97 | * uncompressed file crc-32 value
98 | */
99 | crc: number;
100 |
101 | /**
102 | * compressed size
103 | */
104 | compressedSize: number;
105 |
106 | /**
107 | * uncompressed size
108 | */
109 | size: number;
110 |
111 | /**
112 | * volume number start
113 | */
114 | diskStart: number;
115 |
116 | /**
117 | * internal file attributes
118 | */
119 | inattr: number;
120 |
121 | /**
122 | * external file attributes
123 | */
124 | attr: number;
125 |
126 | /**
127 | * LOC header offset
128 | */
129 | offset: number;
130 | |}
131 |
132 | declare class StreamZipAsync {
133 | constructor(config: StreamZipOptions): this;
134 |
135 | entriesCount: Promise;
136 | comment: Promise;
137 |
138 | entry(name: string): Promise;
139 | entries(): Promise<{ [name: string]: ZipEntry }>;
140 | entryData(entry: string | ZipEntry): Promise;
141 | stream(entry: string | ZipEntry): Promise;
142 | extract(entry: string | ZipEntry | null, outPath: string): Promise;
143 |
144 | on(event: 'entry', handler: (entry: ZipEntry) => void): void;
145 | on(event: 'extract', handler: (entry: ZipEntry, outPath: string) => void): void;
146 |
147 | close(): Promise;
148 | }
149 |
150 | declare class StreamZip {
151 | constructor(config: StreamZipOptions): this;
152 |
153 | entriesCount: number;
154 | comment: string;
155 |
156 | on(event: 'error', handler: (error: any) => void): void;
157 | on(event: 'entry', handler: (entry: ZipEntry) => void): void;
158 | on(event: 'ready', handler: () => void): void;
159 | on(event: 'extract', handler: (entry: ZipEntry, outPath: string) => void): void;
160 |
161 | entry(name: string): ?ZipEntry;
162 |
163 | entries(): { [name: string]: ZipEntry };
164 |
165 | stream(
166 | entry: string | ZipEntry,
167 | callback: (err: any | null, stream?: ReadableStream) => void
168 | ): void;
169 |
170 | entryDataSync(entry: string | ZipEntry): Buffer;
171 |
172 | openEntry(
173 | entry: string | ZipEntry,
174 | callback: (err: any | null, entry?: ZipEntry) => void,
175 | sync: boolean
176 | ): void;
177 |
178 | extract(
179 | entry: string | ZipEntry | null,
180 | outPath: string,
181 | callback: (err?: any, res?: number) => void
182 | ): void;
183 |
184 | close(callback?: (err?: any) => void): void;
185 |
186 | static async: Class;
187 | }
188 |
189 | declare module.exports: Class;
190 | }
191 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/prettier_v1.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: a18c145fa181510ba16b10d17fc3a5a8
2 | // flow-typed version: 01acbe56d4/prettier_v1.x.x/flow_>=v0.104.x
3 |
4 | declare module "prettier" {
5 | declare export type AST = { [key: string]: any, ... };
6 | declare export type Doc = {
7 | [key: string]: any,
8 | ...
9 | };
10 | declare export type FastPath = {
11 | stack: any[],
12 | getName(): null | string | number | Symbol,
13 | getValue(): T,
14 | getNode(count?: number): null | T,
15 | getParentNode(count?: number): null | T,
16 | call(callback: (path: FastPath) => U, ...names: Array): U,
17 | each(callback: (path: FastPath) => void, ...names: Array): void,
18 | map(callback: (path: FastPath, index: number) => U, ...names: Array): U[],
19 | ...
20 | };
21 |
22 | declare export type PrettierParserName =
23 | | "babylon" // deprecated
24 | | "babel"
25 | | "babel-flow"
26 | | "flow"
27 | | "typescript"
28 | | "postcss" // deprecated
29 | | "css"
30 | | "less"
31 | | "scss"
32 | | "json"
33 | | "json5"
34 | | "json-stringify"
35 | | "graphql"
36 | | "markdown"
37 | | "vue"
38 | | "html"
39 | | "angular"
40 | | "mdx"
41 | | "yaml";
42 |
43 | declare export type PrettierParser = {
44 | [name: PrettierParserName]: (text: string, options?: { [key: string]: any, ... }) => AST,
45 | ...
46 | };
47 |
48 | declare export type CustomParser = (
49 | text: string,
50 | parsers: PrettierParser,
51 | options: Options
52 | ) => AST;
53 |
54 | declare export type Options = {|
55 | printWidth?: number,
56 | tabWidth?: number,
57 | useTabs?: boolean,
58 | semi?: boolean,
59 | singleQuote?: boolean,
60 | trailingComma?: "none" | "es5" | "all",
61 | bracketSpacing?: boolean,
62 | jsxBracketSameLine?: boolean,
63 | arrowParens?: "avoid" | "always",
64 | rangeStart?: number,
65 | rangeEnd?: number,
66 | parser?: PrettierParserName | CustomParser,
67 | filepath?: string,
68 | requirePragma?: boolean,
69 | insertPragma?: boolean,
70 | proseWrap?: "always" | "never" | "preserve",
71 | plugins?: Array
72 | |};
73 |
74 | declare export type Plugin = {
75 | languages: SupportLanguage,
76 | parsers: { [parserName: string]: Parser, ... },
77 | printers: { [astFormat: string]: Printer, ... },
78 | options?: SupportOption[],
79 | ...
80 | };
81 |
82 | declare export type Parser = {
83 | parse: (
84 | text: string,
85 | parsers: { [parserName: string]: Parser, ... },
86 | options: { [key: string]: any, ... }
87 | ) => AST,
88 | astFormat: string,
89 | hasPragma?: (text: string) => boolean,
90 | locStart: (node: any) => number,
91 | locEnd: (node: any) => number,
92 | preprocess?: (text: string, options: { [key: string]: any, ... }) => string,
93 | ...
94 | };
95 |
96 | declare export type Printer = {
97 | print: (
98 | path: FastPath<>,
99 | options: { [key: string]: any, ... },
100 | print: (path: FastPath<>) => Doc
101 | ) => Doc,
102 | embed: (
103 | path: FastPath<>,
104 | print: (path: FastPath<>) => Doc,
105 | textToDoc: (text: string, options: { [key: string]: any, ... }) => Doc,
106 | options: { [key: string]: any, ... }
107 | ) => ?Doc,
108 | insertPragma?: (text: string) => string,
109 | massageAstNode?: (node: any, newNode: any, parent: any) => any,
110 | hasPrettierIgnore?: (path: FastPath<>) => boolean,
111 | canAttachComment?: (node: any) => boolean,
112 | willPrintOwnComments?: (path: FastPath<>) => boolean,
113 | printComments?: (path: FastPath<>, print: (path: FastPath<>) => Doc, options: { [key: string]: any, ... }, needsSemi: boolean) => Doc,
114 | handleComments?: {
115 | ownLine?: (commentNode: any, text: string, options: { [key: string]: any, ... }, ast: any, isLastComment: boolean) => boolean,
116 | endOfLine?: (commentNode: any, text: string, options: { [key: string]: any, ... }, ast: any, isLastComment: boolean) => boolean,
117 | remaining?: (commentNode: any, text: string, options: { [key: string]: any, ... }, ast: any, isLastComment: boolean) => boolean,
118 | ...
119 | },
120 | ...
121 | };
122 |
123 | declare export type CursorOptions = {|
124 | cursorOffset: number,
125 | printWidth?: $PropertyType,
126 | tabWidth?: $PropertyType,
127 | useTabs?: $PropertyType,
128 | semi?: $PropertyType,
129 | singleQuote?: $PropertyType,
130 | trailingComma?: $PropertyType,
131 | bracketSpacing?: $PropertyType,
132 | jsxBracketSameLine?: $PropertyType,
133 | arrowParens?: $PropertyType,
134 | parser?: $PropertyType,
135 | filepath?: $PropertyType,
136 | requirePragma?: $PropertyType,
137 | insertPragma?: $PropertyType,
138 | proseWrap?: $PropertyType,
139 | plugins?: $PropertyType
140 | |};
141 |
142 | declare export type CursorResult = {|
143 | formatted: string,
144 | cursorOffset: number
145 | |};
146 |
147 | declare export type ResolveConfigOptions = {|
148 | useCache?: boolean,
149 | config?: string,
150 | editorconfig?: boolean
151 | |};
152 |
153 | declare export type SupportLanguage = {
154 | name: string,
155 | since: string,
156 | parsers: Array,
157 | group?: string,
158 | tmScope: string,
159 | aceMode: string,
160 | codemirrorMode: string,
161 | codemirrorMimeType: string,
162 | aliases?: Array,
163 | extensions: Array,
164 | filenames?: Array,
165 | linguistLanguageId: number,
166 | vscodeLanguageIds: Array,
167 | ...
168 | };
169 |
170 | declare export type SupportOption = {|
171 | since: string,
172 | type: "int" | "boolean" | "choice" | "path",
173 | deprecated?: string,
174 | redirect?: SupportOptionRedirect,
175 | description: string,
176 | oppositeDescription?: string,
177 | default: SupportOptionValue,
178 | range?: SupportOptionRange,
179 | choices?: SupportOptionChoice
180 | |};
181 |
182 | declare export type SupportOptionRedirect = {|
183 | options: string,
184 | value: SupportOptionValue
185 | |};
186 |
187 | declare export type SupportOptionRange = {|
188 | start: number,
189 | end: number,
190 | step: number
191 | |};
192 |
193 | declare export type SupportOptionChoice = {|
194 | value: boolean | string,
195 | description?: string,
196 | since?: string,
197 | deprecated?: string,
198 | redirect?: SupportOptionValue
199 | |};
200 |
201 | declare export type SupportOptionValue = number | boolean | string;
202 |
203 | declare export type SupportInfo = {|
204 | languages: Array,
205 | options: Array
206 | |};
207 |
208 | declare export type FileInfo = {|
209 | ignored: boolean,
210 | inferredParser: PrettierParserName | null,
211 | |};
212 |
213 | declare export type Prettier = {|
214 | format: (source: string, options?: Options) => string,
215 | check: (source: string, options?: Options) => boolean,
216 | formatWithCursor: (source: string, options: CursorOptions) => CursorResult,
217 | resolveConfig: {
218 | (filePath: string, options?: ResolveConfigOptions): Promise,
219 | sync(filePath: string, options?: ResolveConfigOptions): ?Options,
220 | ...
221 | },
222 | clearConfigCache: () => void,
223 | getSupportInfo: (version?: string) => SupportInfo,
224 | getFileInfo: (filePath: string) => Promise
225 | |};
226 |
227 | declare export default Prettier;
228 | }
229 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/react-dom_v18.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: de0a47185086152df6ab4a598943384d
2 | // flow-typed version: cf9120ecbb/react-dom_v18.x.x/flow_>=v0.127.x
3 |
4 | declare module 'react-dom_shared-types' {
5 | /**
6 | * Copied from react-reconciler
7 | * https://github.com/facebook/react/blob/168da8d55782f3b34e2a6aa0c4dd0587696afdbd/packages/react-reconciler/src/ReactInternalTypes.js#L271
8 | */
9 | declare type TransitionTracingCallbacks = {|
10 | onTransitionStart?: (transitionName: string, startTime: number) => void,
11 | onTransitionProgress?: (
12 | transitionName: string,
13 | startTime: number,
14 | currentTime: number,
15 | pending: Array<{|
16 | name: null | string,
17 | |}>,
18 | ) => void,
19 | onTransitionIncomplete?: (
20 | transitionName: string,
21 | startTime: number,
22 | deletions: Array<{|
23 | type: string,
24 | name?: string,
25 | newName?: string,
26 | endTime: number,
27 | |}>,
28 | ) => void,
29 | onTransitionComplete?: (
30 | transitionName: string,
31 | startTime: number,
32 | endTime: number,
33 | ) => void,
34 | onMarkerProgress?: (
35 | transitionName: string,
36 | marker: string,
37 | startTime: number,
38 | currentTime: number,
39 | pending: Array<{|
40 | name: null | string
41 | |}>,
42 | ) => void,
43 | onMarkerIncomplete?: (
44 | transitionName: string,
45 | marker: string,
46 | startTime: number,
47 | deletions: Array<{|
48 | type: string,
49 | name?: string,
50 | newName?: string,
51 | endTime: number,
52 | |}>,
53 | ) => void,
54 | onMarkerComplete?: (
55 | transitionName: string,
56 | marker: string,
57 | startTime: number,
58 | endTime: number,
59 | ) => void,
60 | |};
61 |
62 | declare type ReactEmpty = null | void | boolean;
63 |
64 | declare type ReactNodeList = ReactEmpty | React$Node;
65 |
66 | // Mutable source version can be anything (e.g. number, string, immutable data structure)
67 | // so long as it changes every time any part of the source changes.
68 | declare type MutableSourceVersion = $NonMaybeType;
69 |
70 | declare type MutableSourceGetVersionFn = (
71 | source: $NonMaybeType,
72 | ) => MutableSourceVersion;
73 |
74 | declare type MutableSource> = {|
75 | _source: Source,
76 |
77 | _getVersion: MutableSourceGetVersionFn,
78 |
79 | // Tracks the version of this source at the time it was most recently read.
80 | // Used to determine if a source is safe to read from before it has been subscribed to.
81 | // Version number is only used during mount,
82 | // since the mechanism for determining safety after subscription is expiration time.
83 | //
84 | // As a workaround to support multiple concurrent renderers,
85 | // we categorize some renderers as primary and others as secondary.
86 | // We only expect there to be two concurrent renderers at most:
87 | // React Native (primary) and Fabric (secondary);
88 | // React DOM (primary) and React ART (secondary).
89 | // Secondary renderers store their context values on separate fields.
90 | // We use the same approach for Context.
91 | _workInProgressVersionPrimary: null | MutableSourceVersion,
92 | _workInProgressVersionSecondary: null | MutableSourceVersion,
93 |
94 | // DEV only
95 | // Used to detect multiple renderers using the same mutable source.
96 | _currentPrimaryRenderer?: any,
97 | _currentSecondaryRenderer?: any,
98 |
99 | // DEV only
100 | // Used to detect side effects that update a mutable source during render.
101 | // See https://github.com/facebook/react/issues/19948
102 | _currentlyRenderingFiber?: any,
103 | _initialVersionAsOfFirstRender?: MutableSourceVersion | null,
104 | |};
105 | }
106 |
107 | declare module 'react-dom' {
108 | declare var version: string;
109 |
110 | declare function findDOMNode(
111 | componentOrElement: Element | ?React$Component
112 | ): null | Element | Text;
113 |
114 | declare function render(
115 | element: React$Element,
116 | container: Element,
117 | callback?: () => void
118 | ): React$ElementRef;
119 |
120 | declare function hydrate(
121 | element: React$Element,
122 | container: Element,
123 | callback?: () => void
124 | ): React$ElementRef;
125 |
126 | declare function createPortal(
127 | node: React$Node,
128 | container: Element
129 | ): React$Portal;
130 |
131 | declare function unmountComponentAtNode(container: any): boolean;
132 |
133 | declare function unstable_batchedUpdates(
134 | callback: (a: A, b: B, c: C, d: D, e: E) => mixed,
135 | a: A,
136 | b: B,
137 | c: C,
138 | d: D,
139 | e: E
140 | ): void;
141 |
142 | declare function unstable_renderSubtreeIntoContainer<
143 | ElementType: React$ElementType
144 | >(
145 | parentComponent: React$Component,
146 | nextElement: React$Element,
147 | container: any,
148 | callback?: () => void
149 | ): React$ElementRef;
150 | }
151 |
152 | declare module 'react-dom/client' {
153 | import type {
154 | TransitionTracingCallbacks,
155 | ReactNodeList,
156 | MutableSource,
157 | } from 'react-dom_shared-types';
158 |
159 | declare opaque type FiberRoot;
160 |
161 | declare type RootType = {
162 | render(children: ReactNodeList): void,
163 | unmount(): void,
164 | _internalRoot: FiberRoot | null,
165 | ...
166 | };
167 |
168 | declare type CreateRootOptions = {
169 | unstable_strictMode?: boolean,
170 | unstable_concurrentUpdatesByDefault?: boolean,
171 | identifierPrefix?: string,
172 | onRecoverableError?: (error: mixed) => void,
173 | transitionCallbacks?: TransitionTracingCallbacks,
174 | ...
175 | };
176 |
177 | declare export function createRoot(
178 | container: Element | DocumentFragment,
179 | options?: CreateRootOptions,
180 | ): RootType;
181 |
182 | declare type HydrateRootOptions = {
183 | // Hydration options
184 | hydratedSources?: Array>,
185 | onHydrated?: (suspenseNode: Comment) => void,
186 | onDeleted?: (suspenseNode: Comment) => void,
187 | // Options for all roots
188 | unstable_strictMode?: boolean,
189 | unstable_concurrentUpdatesByDefault?: boolean,
190 | identifierPrefix?: string,
191 | onRecoverableError?: (error: mixed) => void,
192 | ...
193 | };
194 |
195 | declare export function hydrateRoot(
196 | container: Document | Element,
197 | initialChildren: ReactNodeList,
198 | options?: HydrateRootOptions,
199 | ): RootType;
200 | }
201 |
202 | declare module 'react-dom/server' {
203 | declare var version: string;
204 |
205 | declare function renderToString(element: React$Node): string;
206 |
207 | declare function renderToStaticMarkup(element: React$Node): string;
208 |
209 | declare function renderToNodeStream(element: React$Node): stream$Readable;
210 |
211 | declare function renderToStaticNodeStream(
212 | element: React$Node
213 | ): stream$Readable;
214 | }
215 |
216 | declare module 'react-dom/test-utils' {
217 | declare interface Thenable {
218 | then(resolve: () => mixed, reject?: () => mixed): mixed,
219 | }
220 |
221 | declare var Simulate: {
222 | [eventName: string]: (
223 | element: Element,
224 | eventData?: { [key: string]: mixed, ... }
225 | ) => void,
226 | ...
227 | };
228 |
229 | declare function renderIntoDocument(
230 | instance: React$Element
231 | ): React$Component;
232 |
233 | declare function mockComponent(
234 | componentClass: React$ElementType,
235 | mockTagName?: string
236 | ): { [key: string]: mixed, ... };
237 |
238 | declare function isElement(element: React$Element): boolean;
239 |
240 | declare function isElementOfType(
241 | element: React$Element,
242 | componentClass: React$ElementType
243 | ): boolean;
244 |
245 | declare function isDOMComponent(instance: any): boolean;
246 |
247 | declare function isCompositeComponent(
248 | instance: React$Component
249 | ): boolean;
250 |
251 | declare function isCompositeComponentWithType(
252 | instance: React$Component,
253 | componentClass: React$ElementType
254 | ): boolean;
255 |
256 | declare function findAllInRenderedTree(
257 | tree: React$Component,
258 | test: (child: React$Component) => boolean
259 | ): Array>;
260 |
261 | declare function scryRenderedDOMComponentsWithClass(
262 | tree: React$Component,
263 | className: string
264 | ): Array;
265 |
266 | declare function findRenderedDOMComponentWithClass(
267 | tree: React$Component,
268 | className: string
269 | ): ?Element;
270 |
271 | declare function scryRenderedDOMComponentsWithTag(
272 | tree: React$Component,
273 | tagName: string
274 | ): Array;
275 |
276 | declare function findRenderedDOMComponentWithTag(
277 | tree: React$Component,
278 | tagName: string
279 | ): ?Element;
280 |
281 | declare function scryRenderedComponentsWithType(
282 | tree: React$Component,
283 | componentClass: React$ElementType
284 | ): Array>;
285 |
286 | declare function findRenderedComponentWithType(
287 | tree: React$Component,
288 | componentClass: React$ElementType
289 | ): ?React$Component;
290 |
291 | declare function act(callback: () => void | Thenable): Thenable;
292 | }
293 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/react-helmet-async_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 41523818a562c15eea5937d15b382477
2 | // flow-typed version: <>/react-helmet-async_v^1.3.0/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'react-helmet-async'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'react-helmet-async' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'react-helmet-async/lib' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'react-helmet-async/lib/index.modern' {
30 | declare module.exports: any;
31 | }
32 |
33 | declare module 'react-helmet-async/lib/index.module' {
34 | declare module.exports: any;
35 | }
36 |
37 | declare module 'react-helmet-async/lib/index.umd' {
38 | declare module.exports: any;
39 | }
40 |
41 | declare module 'react-helmet-async/src/client' {
42 | declare module.exports: any;
43 | }
44 |
45 | declare module 'react-helmet-async/src/constants' {
46 | declare module.exports: any;
47 | }
48 |
49 | declare module 'react-helmet-async/src/Dispatcher' {
50 | declare module.exports: any;
51 | }
52 |
53 | declare module 'react-helmet-async/src/HelmetData' {
54 | declare module.exports: any;
55 | }
56 |
57 | declare module 'react-helmet-async/src' {
58 | declare module.exports: any;
59 | }
60 |
61 | declare module 'react-helmet-async/src/Provider' {
62 | declare module.exports: any;
63 | }
64 |
65 | declare module 'react-helmet-async/src/server' {
66 | declare module.exports: any;
67 | }
68 |
69 | declare module 'react-helmet-async/src/utils' {
70 | declare module.exports: any;
71 | }
72 |
73 | // Filename aliases
74 | declare module 'react-helmet-async/lib/index' {
75 | declare module.exports: $Exports<'react-helmet-async/lib'>;
76 | }
77 | declare module 'react-helmet-async/lib/index.js' {
78 | declare module.exports: $Exports<'react-helmet-async/lib'>;
79 | }
80 | declare module 'react-helmet-async/lib/index.modern.js' {
81 | declare module.exports: $Exports<'react-helmet-async/lib/index.modern'>;
82 | }
83 | declare module 'react-helmet-async/lib/index.module.js' {
84 | declare module.exports: $Exports<'react-helmet-async/lib/index.module'>;
85 | }
86 | declare module 'react-helmet-async/lib/index.umd.js' {
87 | declare module.exports: $Exports<'react-helmet-async/lib/index.umd'>;
88 | }
89 | declare module 'react-helmet-async/src/client.js' {
90 | declare module.exports: $Exports<'react-helmet-async/src/client'>;
91 | }
92 | declare module 'react-helmet-async/src/constants.js' {
93 | declare module.exports: $Exports<'react-helmet-async/src/constants'>;
94 | }
95 | declare module 'react-helmet-async/src/Dispatcher.js' {
96 | declare module.exports: $Exports<'react-helmet-async/src/Dispatcher'>;
97 | }
98 | declare module 'react-helmet-async/src/HelmetData.js' {
99 | declare module.exports: $Exports<'react-helmet-async/src/HelmetData'>;
100 | }
101 | declare module 'react-helmet-async/src/index' {
102 | declare module.exports: $Exports<'react-helmet-async/src'>;
103 | }
104 | declare module 'react-helmet-async/src/index.js' {
105 | declare module.exports: $Exports<'react-helmet-async/src'>;
106 | }
107 | declare module 'react-helmet-async/src/Provider.js' {
108 | declare module.exports: $Exports<'react-helmet-async/src/Provider'>;
109 | }
110 | declare module 'react-helmet-async/src/server.js' {
111 | declare module.exports: $Exports<'react-helmet-async/src/server'>;
112 | }
113 | declare module 'react-helmet-async/src/utils.js' {
114 | declare module.exports: $Exports<'react-helmet-async/src/utils'>;
115 | }
116 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/rimraf_v3.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 31191d41b239d1242753bdea18136ae9
2 | // flow-typed version: 6ee04b16cf/rimraf_v3.x.x/flow_>=v0.104.x
3 |
4 | declare module 'rimraf' {
5 | declare type Options = {
6 | maxBusyTries?: number,
7 | emfileWait?: number,
8 | glob?: boolean,
9 | disableGlob?: boolean,
10 | ...
11 | };
12 |
13 | declare type Callback = (err: ?Error, path: ?string) => void;
14 |
15 | declare module.exports: {
16 | (f: string, opts?: Options | Callback, callback?: Callback): void,
17 | sync(path: string, opts?: Options): void,
18 | ...
19 | };
20 | }
21 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/semver_v7.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: bf6205896c200fb28700dfa8d29f2b8a
2 | // flow-typed version: 3d76504c27/semver_v7.x.x/flow_>=v0.104.x
3 |
4 | declare module "semver" {
5 | declare type Release =
6 | | "major"
7 | | "premajor"
8 | | "minor"
9 | | "preminor"
10 | | "patch"
11 | | "prepatch"
12 | | "prerelease";
13 |
14 | // The supported comparators are taken from the source here:
15 | // https://github.com/npm/node-semver/blob/8bd070b550db2646362c9883c8d008d32f66a234/semver.js#L623
16 | declare type Operator =
17 | | "==="
18 | | "!=="
19 | | "=="
20 | | "="
21 | | "" // Not sure why you would want this, but whatever.
22 | | "!="
23 | | ">"
24 | | ">="
25 | | "<"
26 | | "<=";
27 |
28 | declare class SemVer {
29 | build: Array;
30 | loose: ?boolean;
31 | major: number;
32 | minor: number;
33 | patch: number;
34 | prerelease: Array;
35 | raw: string;
36 | version: string;
37 |
38 | constructor(version: string | SemVer, options?: Options): SemVer;
39 | compare(other: string | SemVer): -1 | 0 | 1;
40 | compareMain(other: string | SemVer): -1 | 0 | 1;
41 | comparePre(other: string | SemVer): -1 | 0 | 1;
42 | compareBuild(other: string | SemVer): -1 | 0 | 1;
43 | format(): string;
44 | inc(release: Release, identifier: string): this;
45 | }
46 |
47 | declare class Comparator {
48 | options?: Options;
49 | operator: Operator;
50 | semver: SemVer;
51 | value: string;
52 |
53 | constructor(comp: string | Comparator, options?: Options): Comparator;
54 | parse(comp: string): void;
55 | test(version: string): boolean;
56 | }
57 |
58 | declare class Range {
59 | loose: ?boolean;
60 | raw: string;
61 | set: Array>;
62 |
63 | constructor(range: string | Range, options?: Options): Range;
64 | format(): string;
65 | parseRange(range: string): Array;
66 | test(version: string): boolean;
67 | toString(): string;
68 | }
69 |
70 | declare var SEMVER_SPEC_VERSION: string;
71 | declare var re: Array;
72 | declare var src: Array;
73 |
74 | declare type Options = {
75 | options?: Options,
76 | includePrerelease?: boolean,
77 | ...
78 | } | boolean;
79 |
80 | // Functions
81 | declare function valid(v: string | SemVer, options?: Options): string | null;
82 | declare function clean(v: string | SemVer, options?: Options): string | null;
83 | declare function inc(
84 | v: string | SemVer,
85 | release: Release,
86 | options?: Options,
87 | identifier?: string
88 | ): string | null;
89 | declare function inc(
90 | v: string | SemVer,
91 | release: Release,
92 | identifier: string
93 | ): string | null;
94 | declare function major(v: string | SemVer, options?: Options): number;
95 | declare function minor(v: string | SemVer, options?: Options): number;
96 | declare function patch(v: string | SemVer, options?: Options): number;
97 | declare function intersects(r1: string | SemVer, r2: string | SemVer, loose?: boolean): boolean;
98 | declare function minVersion(r: string | Range): Range | null;
99 |
100 | // Comparison
101 | declare function gt(
102 | v1: string | SemVer,
103 | v2: string | SemVer,
104 | options?: Options
105 | ): boolean;
106 | declare function gte(
107 | v1: string | SemVer,
108 | v2: string | SemVer,
109 | options?: Options
110 | ): boolean;
111 | declare function lt(
112 | v1: string | SemVer,
113 | v2: string | SemVer,
114 | options?: Options
115 | ): boolean;
116 | declare function lte(
117 | v1: string | SemVer,
118 | v2: string | SemVer,
119 | options?: Options
120 | ): boolean;
121 | declare function eq(
122 | v1: string | SemVer,
123 | v2: string | SemVer,
124 | options?: Options
125 | ): boolean;
126 | declare function neq(
127 | v1: string | SemVer,
128 | v2: string | SemVer,
129 | options?: Options
130 | ): boolean;
131 | declare function cmp(
132 | v1: string | SemVer,
133 | comparator: Operator,
134 | v2: string | SemVer,
135 | options?: Options
136 | ): boolean;
137 | declare function compare(
138 | v1: string | SemVer,
139 | v2: string | SemVer,
140 | options?: Options
141 | ): -1 | 0 | 1;
142 | declare function rcompare(
143 | v1: string | SemVer,
144 | v2: string | SemVer,
145 | options?: Options
146 | ): -1 | 0 | 1;
147 | declare function diff(v1: string | SemVer, v2: string | SemVer): ?Release;
148 | declare function intersects(comparator: Comparator): boolean;
149 | declare function sort(
150 | list: Array,
151 | options?: Options
152 | ): Array;
153 | declare function rsort(
154 | list: Array,
155 | options?: Options
156 | ): Array;
157 | declare function compareIdentifiers(
158 | v1: string | SemVer,
159 | v2: string | SemVer
160 | ): -1 | 0 | 1;
161 | declare function rcompareIdentifiers(
162 | v1: string | SemVer,
163 | v2: string | SemVer
164 | ): -1 | 0 | 1;
165 |
166 | // Ranges
167 | declare function validRange(
168 | range: string | Range,
169 | options?: Options
170 | ): string | null;
171 | declare function satisfies(
172 | version: string | SemVer,
173 | range: string | Range,
174 | options?: Options
175 | ): boolean;
176 | declare function maxSatisfying(
177 | versions: Array,
178 | range: string | Range,
179 | options?: Options
180 | ): string | SemVer | null;
181 | declare function minSatisfying(
182 | versions: Array,
183 | range: string | Range,
184 | options?: Options
185 | ): string | SemVer | null;
186 | declare function gtr(
187 | version: string | SemVer,
188 | range: string | Range,
189 | options?: Options
190 | ): boolean;
191 | declare function ltr(
192 | version: string | SemVer,
193 | range: string | Range,
194 | options?: Options
195 | ): boolean;
196 | declare function outside(
197 | version: string | SemVer,
198 | range: string | Range,
199 | hilo: ">" | "<",
200 | options?: Options
201 | ): boolean;
202 | declare function intersects(
203 | range: Range
204 | ): boolean;
205 | declare function simplifyRange(
206 | ranges: Array,
207 | range: string | Range,
208 | options?: Options,
209 | ): string | Range;
210 | declare function subset(
211 | sub: string | Range,
212 | dom: string | Range,
213 | options?: Options,
214 | ): boolean;
215 |
216 | // Coercion
217 | declare function coerce(
218 | version: string | SemVer,
219 | options?: Options
220 | ): ?SemVer
221 |
222 | // Not explicitly documented, or deprecated
223 | declare function parse(version: string, options?: Options): ?SemVer;
224 | declare function toComparators(
225 | range: string | Range,
226 | options?: Options
227 | ): Array>;
228 | }
229 |
230 | declare module "semver/preload" {
231 | declare module.exports: $Exports<"semver">;
232 | }
233 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/sharp_vx.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 60530952aa1f23dee64e273881d7e400
2 | // flow-typed version: <>/sharp_v^0.30.6/flow_v0.180.0
3 |
4 | /**
5 | * This is an autogenerated libdef stub for:
6 | *
7 | * 'sharp'
8 | *
9 | * Fill this stub out by replacing all the `any` types.
10 | *
11 | * Once filled out, we encourage you to share your work with the
12 | * community by sending a pull request to:
13 | * https://github.com/flowtype/flow-typed
14 | */
15 |
16 | declare module 'sharp' {
17 | declare module.exports: any;
18 | }
19 |
20 | /**
21 | * We include stubs for each file inside this npm package in case you need to
22 | * require those files directly. Feel free to delete any files that aren't
23 | * needed.
24 | */
25 | declare module 'sharp/install/can-compile' {
26 | declare module.exports: any;
27 | }
28 |
29 | declare module 'sharp/install/dll-copy' {
30 | declare module.exports: any;
31 | }
32 |
33 | declare module 'sharp/install/libvips' {
34 | declare module.exports: any;
35 | }
36 |
37 | declare module 'sharp/lib/agent' {
38 | declare module.exports: any;
39 | }
40 |
41 | declare module 'sharp/lib/channel' {
42 | declare module.exports: any;
43 | }
44 |
45 | declare module 'sharp/lib/colour' {
46 | declare module.exports: any;
47 | }
48 |
49 | declare module 'sharp/lib/composite' {
50 | declare module.exports: any;
51 | }
52 |
53 | declare module 'sharp/lib/constructor' {
54 | declare module.exports: any;
55 | }
56 |
57 | declare module 'sharp/lib' {
58 | declare module.exports: any;
59 | }
60 |
61 | declare module 'sharp/lib/input' {
62 | declare module.exports: any;
63 | }
64 |
65 | declare module 'sharp/lib/is' {
66 | declare module.exports: any;
67 | }
68 |
69 | declare module 'sharp/lib/libvips' {
70 | declare module.exports: any;
71 | }
72 |
73 | declare module 'sharp/lib/operation' {
74 | declare module.exports: any;
75 | }
76 |
77 | declare module 'sharp/lib/output' {
78 | declare module.exports: any;
79 | }
80 |
81 | declare module 'sharp/lib/platform' {
82 | declare module.exports: any;
83 | }
84 |
85 | declare module 'sharp/lib/resize' {
86 | declare module.exports: any;
87 | }
88 |
89 | declare module 'sharp/lib/sharp' {
90 | declare module.exports: any;
91 | }
92 |
93 | declare module 'sharp/lib/utility' {
94 | declare module.exports: any;
95 | }
96 |
97 | // Filename aliases
98 | declare module 'sharp/install/can-compile.js' {
99 | declare module.exports: $Exports<'sharp/install/can-compile'>;
100 | }
101 | declare module 'sharp/install/dll-copy.js' {
102 | declare module.exports: $Exports<'sharp/install/dll-copy'>;
103 | }
104 | declare module 'sharp/install/libvips.js' {
105 | declare module.exports: $Exports<'sharp/install/libvips'>;
106 | }
107 | declare module 'sharp/lib/agent.js' {
108 | declare module.exports: $Exports<'sharp/lib/agent'>;
109 | }
110 | declare module 'sharp/lib/channel.js' {
111 | declare module.exports: $Exports<'sharp/lib/channel'>;
112 | }
113 | declare module 'sharp/lib/colour.js' {
114 | declare module.exports: $Exports<'sharp/lib/colour'>;
115 | }
116 | declare module 'sharp/lib/composite.js' {
117 | declare module.exports: $Exports<'sharp/lib/composite'>;
118 | }
119 | declare module 'sharp/lib/constructor.js' {
120 | declare module.exports: $Exports<'sharp/lib/constructor'>;
121 | }
122 | declare module 'sharp/lib/index' {
123 | declare module.exports: $Exports<'sharp/lib'>;
124 | }
125 | declare module 'sharp/lib/index.js' {
126 | declare module.exports: $Exports<'sharp/lib'>;
127 | }
128 | declare module 'sharp/lib/input.js' {
129 | declare module.exports: $Exports<'sharp/lib/input'>;
130 | }
131 | declare module 'sharp/lib/is.js' {
132 | declare module.exports: $Exports<'sharp/lib/is'>;
133 | }
134 | declare module 'sharp/lib/libvips.js' {
135 | declare module.exports: $Exports<'sharp/lib/libvips'>;
136 | }
137 | declare module 'sharp/lib/operation.js' {
138 | declare module.exports: $Exports<'sharp/lib/operation'>;
139 | }
140 | declare module 'sharp/lib/output.js' {
141 | declare module.exports: $Exports<'sharp/lib/output'>;
142 | }
143 | declare module 'sharp/lib/platform.js' {
144 | declare module.exports: $Exports<'sharp/lib/platform'>;
145 | }
146 | declare module 'sharp/lib/resize.js' {
147 | declare module.exports: $Exports<'sharp/lib/resize'>;
148 | }
149 | declare module 'sharp/lib/sharp.js' {
150 | declare module.exports: $Exports<'sharp/lib/sharp'>;
151 | }
152 | declare module 'sharp/lib/utility.js' {
153 | declare module.exports: $Exports<'sharp/lib/utility'>;
154 | }
155 |
--------------------------------------------------------------------------------
/examples/flow/flow-typed/npm/yargs_v15.x.x.js:
--------------------------------------------------------------------------------
1 | // flow-typed signature: 1f51ede354b708d1bf2ac3d98fd21d0b
2 | // flow-typed version: fe275d55fd/yargs_v15.x.x/flow_>=v0.118.x
3 |
4 | declare module "yargs" {
5 | declare type Argv = {
6 | [key: string]: any,
7 | _: Array,
8 | $0: string,
9 | ...
10 | };
11 |
12 | declare type Options = $Shape<{
13 | alias: string | Array,
14 | array: boolean,
15 | boolean: boolean,
16 | choices: Array,
17 | coerce: (arg: {[key: string]: any, ...} | any) => mixed,
18 | config: boolean,
19 | configParser: (configPath: string) => { [key: string]: mixed, ... },
20 | conflicts: string | Array | { [key: string]: string, ... },
21 | count: boolean,
22 | default: mixed,
23 | defaultDescription: string,
24 | demandOption: boolean | string,
25 | desc: string,
26 | describe: string,
27 | description: string,
28 | global: boolean,
29 | group: string,
30 | implies: string | { [key: string]: string, ... },
31 | nargs: number,
32 | normalize: boolean,
33 | number: boolean,
34 | required: boolean,
35 | requiresArg: boolean,
36 | skipValidation: boolean,
37 | string: boolean,
38 | type: "array" | "boolean" | "count" | "number" | "string",
39 | ...
40 | }>;
41 |
42 | declare type CommonModuleObject = {|
43 | command?: string | Array,
44 | aliases?: Array | string,
45 | builder?: { [key: string]: Options, ... } | ((yargsInstance: Yargs) => mixed),
46 | handler?: ((argv: Argv) => void) | ((argv: Argv) => Promise)
47 | |};
48 |
49 | declare type ModuleObjectDesc = {|
50 | ...CommonModuleObject,
51 | desc?: string | false
52 | |};
53 |
54 | declare type ModuleObjectDescribe = {|
55 | ...CommonModuleObject,
56 | describe?: string | false
57 | |};
58 |
59 | declare type ModuleObjectDescription = {|
60 | ...CommonModuleObject,
61 | description?: string | false
62 | |};
63 |
64 | declare type ModuleObject =
65 | | ModuleObjectDesc
66 | | ModuleObjectDescribe
67 | | ModuleObjectDescription;
68 |
69 | declare type MiddleWareCallback =
70 | | (argv: Argv, yargsInstance?: Yargs) => void
71 | | (argv: Argv, yargsInstance?: Yargs) => Promise;
72 |
73 | declare type Middleware = MiddleWareCallback | Array;
74 |
75 | declare class Yargs {
76 | (args: Array): Yargs;
77 |
78 | alias(key: string, alias: string): this;
79 | alias(alias: { [key: string]: string | Array, ... }): this;
80 | argv: Argv;
81 | array(key: string | Array): this;
82 | boolean(parameter: string | Array): this;
83 | check(fn: (argv: Argv, options: Array) => ?boolean): this;
84 | choices(key: string, allowed: Array): this;
85 | choices(allowed: { [key: string]: Array, ... }): this;
86 | coerce(key: string, fn: (value: any) => mixed): this;
87 | coerce(object: { [key: string]: (value: any) => mixed, ... }): this;
88 | coerce(keys: Array, fn: (value: any) => mixed): this;
89 |
90 | command(
91 | cmd: string | Array,
92 | desc: string | false,
93 | builder?: { [key: string]: Options, ... } | ((yargsInstance: Yargs) => mixed),
94 | handler?: Function
95 | ): this;
96 |
97 | command(
98 | cmd: string | Array,
99 | desc: string | false,
100 | module: ModuleObject
101 | ): this;
102 |
103 | command(module: ModuleObject): this;
104 |
105 | commandDir(
106 | directory: string,
107 | options?: {
108 | exclude?: string | Function,
109 | extensions?: Array,
110 | include?: string | Function,
111 | recurse?: boolean,
112 | visit?: Function,
113 | ...
114 | },
115 | ): this;
116 |
117 | completion(
118 | cmd?: string,
119 | description?: string | false | (
120 | current: string,
121 | argv: Argv,
122 | done: (compeltion: Array) => void
123 | ) => ?(Array | Promise>),
124 | fn?: (
125 | current: string,
126 | argv: Argv,
127 | done: (completion: Array) => void
128 | ) => ?(Array | Promise>)
129 | ): this;
130 |
131 | config(
132 | key?: string,
133 | description?: string,
134 | parseFn?: (configPath: string) => { [key: string]: mixed, ... }
135 | ): this;
136 | config(
137 | key: string,
138 | parseFn?: (configPath: string) => { [key: string]: mixed, ... }
139 | ): this;
140 | config(config: { [key: string]: mixed, ... }): this;
141 |
142 | conflicts(key: string, value: string | Array): this;
143 | conflicts(keys: { [key: string]: string | Array, ... }): this;
144 |
145 | count(name: string): this;
146 |
147 | default(key: string, value: mixed, description?: string): this;
148 | default(defaults: { [key: string]: mixed, ... }): this;
149 |
150 | // Deprecated: use demandOption() and demandCommand() instead.
151 | demand(key: string, msg?: string | boolean): this;
152 | demand(count: number, max?: number, msg?: string | boolean): this;
153 |
154 | demandOption(key: string | Array, msg?: string | boolean): this;
155 |
156 | demandCommand(): this;
157 | demandCommand(min: number, minMsg?: string): this;
158 | demandCommand(
159 | min: number,
160 | max: number,
161 | minMsg?: string,
162 | maxMsg?: string
163 | ): this;
164 |
165 | describe(key: string, description: string): this;
166 | describe(describeObject: { [key: string]: string, ... }): this;
167 |
168 | detectLocale(shouldDetect: boolean): this;
169 |
170 | env(prefix?: string): this;
171 |
172 | epilog(text: string): this;
173 | epilogue(text: string): this;
174 |
175 | example(cmd: string, desc?: string): this;
176 |
177 | exitProcess(enable: boolean): this;
178 |
179 | fail(fn: (failureMessage: string, err: Error, yargs: Yargs) => mixed): this;
180 |
181 | getCompletion(args: Array, fn: () => void): this;
182 |
183 | global(globals: string | Array, isGlobal?: boolean): this;
184 |
185 | group(key: string | Array, groupName: string): this;
186 |
187 | help(option: boolean): this;
188 |
189 | help(option?: string, desc?: string): this;
190 |
191 | hide(key: string): this;
192 |
193 | implies(key: string, value: string | Array): this;
194 | implies(keys: { [key: string]: string | Array, ... }): this;
195 |
196 | locale(
197 | locale: | "de"
198 | | "en"
199 | | "es"
200 | | "fr"
201 | | "hi"
202 | | "hu"
203 | | "id"
204 | | "it"
205 | | "ja"
206 | | "ko"
207 | | "nb"
208 | | "pirate"
209 | | "pl"
210 | | "pt"
211 | | "pt_BR"
212 | | "ru"
213 | | "th"
214 | | "tr"
215 | | "zh_CN"
216 | ): this;
217 | locale(): string;
218 |
219 | middleware(
220 | middlewareCallbacks: Middleware,
221 | applyBeforeValidation?: boolean,
222 | ): this;
223 |
224 | nargs(key: string, count: number): this;
225 |
226 | normalize(key: string): this;
227 |
228 | number(key: string | Array): this;
229 |
230 | onFinishCommand(handler: () => mixed): this;
231 |
232 | option(key: string, options?: Options): this;
233 | option(optionMap: { [key: string]: Options, ... }): this;
234 |
235 | options(key: string, options?: Options): this;
236 | options(optionMap: { [key: string]: Options, ... }): this;
237 |
238 | parse(
239 | args?: string | Array,
240 | context?: { [key: string]: any, ... },
241 | parseCallback?: (err: Error, argv: Argv, output?: string) => void
242 | ): Argv;
243 | parse(
244 | args?: string | Array,
245 | parseCallback?: (err: Error, argv: Argv, output?: string) => void
246 | ): Argv;
247 |
248 | parserConfiguration(configuration: {[key: string]: any, ...}): this;
249 |
250 | pkgConf(key: string, cwd?: string): this;
251 |
252 | positional(key: string, opt?: Options): this;
253 |
254 | recommendCommands(): this;
255 |
256 | // Alias of demand()
257 | require(key: string, msg: string | boolean): this;
258 | require(count: number, max?: number, msg?: string | boolean): this;
259 |
260 | requiresArg(key: string | Array): this;
261 |
262 | reset(): this;
263 |
264 | scriptName(name: string): this;
265 |
266 | showCompletionScript(): this;
267 |
268 | showHelp(consoleLevel?: "error" | "warn" | "log"): this;
269 | showHelp(printCallback: (usageData: string) => void): this;
270 |
271 | showHelpOnFail(enable: boolean, message?: string): this;
272 |
273 | strict(): this;
274 |
275 | skipValidation(key: string): this;
276 |
277 | strict(global?: boolean): this;
278 |
279 | string(key: string | Array): this;
280 |
281 | terminalWidth(): number;
282 |
283 | updateLocale(obj: { [key: string]: string, ... }): this;
284 | updateStrings(obj: { [key: string]: string, ... }): this;
285 |
286 | usage(message: string, opts?: { [key: string]: Options, ... }): this;
287 |
288 | version(): this;
289 | version(version: string | false): this;
290 | version(option: string | (() => string), version: string): this;
291 | version(
292 | option: string | (() => string),
293 | description: string | (() => string),
294 | version: string
295 | ): this;
296 |
297 | wrap(columns: number | null): this;
298 | }
299 |
300 | declare module.exports: Yargs;
301 | }
302 |
--------------------------------------------------------------------------------
/examples/flow/gatsby-config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | siteMetadata: {
3 | title: 'gatsby-plugin-typegen example',
4 | description: 'gatsby-plugin-typegen example with Flow',
5 | },
6 | plugins: [
7 | 'gatsby-plugin-react-helmet-async',
8 | 'gatsby-plugin-image',
9 | {
10 | resolve: 'gatsby-source-filesystem',
11 | options: {
12 | name: 'images',
13 | path: 'src/images',
14 | },
15 | },
16 | 'gatsby-transformer-sharp',
17 | 'gatsby-plugin-sharp',
18 | {
19 | resolve: 'gatsby-plugin-typegen',
20 | options: {
21 | language: 'flow',
22 | outputPath: 'src/__generated__/gatsby-types.js',
23 | emitSchema: {
24 | 'src/__generated__/gatsby-introspection.json': true,
25 | 'src/__generated__/gatsby-schema.graphql': true,
26 | },
27 | emitPluginDocument: {
28 | 'src/__generated__/gatsby-plugin-documents.graphql': true,
29 | },
30 | },
31 | },
32 | ],
33 | };
34 |
--------------------------------------------------------------------------------
/examples/flow/gatsby-node.js:
--------------------------------------------------------------------------------
1 | exports.onCreateBabelConfig = ({ actions }) => {
2 | actions.setBabelPreset({
3 | name: require.resolve('@babel/preset-flow'),
4 | });
5 | };
6 |
--------------------------------------------------------------------------------
/examples/flow/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example-flow",
3 | "private": true,
4 | "description": "gatsby-plugin-typegen example with Flow",
5 | "version": "0.1.0",
6 | "author": {
7 | "name": "Hyeseong Kim",
8 | "email": "hey@hyeseong.kim"
9 | },
10 | "scripts": {
11 | "build": "gatsby build",
12 | "develop": "gatsby develop",
13 | "serve": "gatsby serve",
14 | "clean": "gatsby clean"
15 | },
16 | "dependencies": {
17 | "gatsby": "^4.16.0",
18 | "gatsby-plugin-image": "^2.16.1",
19 | "gatsby-plugin-react-helmet-async": "^1.2.1",
20 | "gatsby-plugin-sharp": "^4.16.1",
21 | "gatsby-plugin-typegen": "portal:../../plugin",
22 | "gatsby-source-filesystem": "^4.16.0",
23 | "gatsby-transformer-sharp": "^4.16.0",
24 | "react": "^18.1.0",
25 | "react-dom": "^18.1.0",
26 | "react-helmet-async": "^1.3.0",
27 | "sharp": "^0.30.6"
28 | },
29 | "devDependencies": {
30 | "@babel/preset-flow": "^7.17.12",
31 | "flow-bin": "^0.180.0",
32 | "flow-typed": "^3.7.0"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/examples/flow/src/__generated__/gatsby-plugin-documents.graphql:
--------------------------------------------------------------------------------
1 | fragment GatsbyImageSharpFixed on ImageSharpFixed {
2 | base64
3 | width
4 | height
5 | src
6 | srcSet
7 | }
8 |
9 | fragment GatsbyImageSharpFixed_tracedSVG on ImageSharpFixed {
10 | tracedSVG
11 | width
12 | height
13 | src
14 | srcSet
15 | }
16 |
17 | fragment GatsbyImageSharpFixed_withWebp on ImageSharpFixed {
18 | base64
19 | width
20 | height
21 | src
22 | srcSet
23 | srcWebp
24 | srcSetWebp
25 | }
26 |
27 | fragment GatsbyImageSharpFixed_withWebp_tracedSVG on ImageSharpFixed {
28 | tracedSVG
29 | width
30 | height
31 | src
32 | srcSet
33 | srcWebp
34 | srcSetWebp
35 | }
36 |
37 | fragment GatsbyImageSharpFixed_noBase64 on ImageSharpFixed {
38 | width
39 | height
40 | src
41 | srcSet
42 | }
43 |
44 | fragment GatsbyImageSharpFixed_withWebp_noBase64 on ImageSharpFixed {
45 | width
46 | height
47 | src
48 | srcSet
49 | srcWebp
50 | srcSetWebp
51 | }
52 |
53 | fragment GatsbyImageSharpFluid on ImageSharpFluid {
54 | base64
55 | aspectRatio
56 | src
57 | srcSet
58 | sizes
59 | }
60 |
61 | fragment GatsbyImageSharpFluidLimitPresentationSize on ImageSharpFluid {
62 | maxHeight: presentationHeight
63 | maxWidth: presentationWidth
64 | }
65 |
66 | fragment GatsbyImageSharpFluid_tracedSVG on ImageSharpFluid {
67 | tracedSVG
68 | aspectRatio
69 | src
70 | srcSet
71 | sizes
72 | }
73 |
74 | fragment GatsbyImageSharpFluid_withWebp on ImageSharpFluid {
75 | base64
76 | aspectRatio
77 | src
78 | srcSet
79 | srcWebp
80 | srcSetWebp
81 | sizes
82 | }
83 |
84 | fragment GatsbyImageSharpFluid_withWebp_tracedSVG on ImageSharpFluid {
85 | tracedSVG
86 | aspectRatio
87 | src
88 | srcSet
89 | srcWebp
90 | srcSetWebp
91 | sizes
92 | }
93 |
94 | fragment GatsbyImageSharpFluid_noBase64 on ImageSharpFluid {
95 | aspectRatio
96 | src
97 | srcSet
98 | sizes
99 | }
100 |
101 | fragment GatsbyImageSharpFluid_withWebp_noBase64 on ImageSharpFluid {
102 | aspectRatio
103 | src
104 | srcSet
105 | srcWebp
106 | srcSetWebp
107 | sizes
108 | }
--------------------------------------------------------------------------------
/examples/flow/src/components/header.jsx:
--------------------------------------------------------------------------------
1 | /* @flow */
2 |
3 | import * as React from 'react';
4 | import { Link } from 'gatsby';
5 |
6 | type HeaderProps = {
7 | siteTitle: string,
8 | };
9 |
10 | export default function Header({ siteTitle }: HeaderProps): React.Node {
11 | return (
12 |
38 | )
39 | }
40 |
--------------------------------------------------------------------------------
/examples/flow/src/components/layout.jsx:
--------------------------------------------------------------------------------
1 | /* @flow */
2 |
3 | import * as React from 'react';
4 | import { useStaticQuery, graphql } from 'gatsby';
5 |
6 | import Header from './header';
7 | import './layout.css';
8 |
9 | type Props = {
10 | children: ?React.Node,
11 | };
12 |
13 | export default function Layout({ children }: Props): React.Node {
14 | const data = useStaticQuery(graphql`
15 | query Layout {
16 | site {
17 | siteMetadata {
18 | title
19 | }
20 | }
21 | }
22 | `);
23 |
24 | return (
25 | <>
26 |
27 |
34 |
{children}
35 |
44 |
45 | >
46 | );
47 | }
48 |
--------------------------------------------------------------------------------
/examples/flow/src/components/seo.jsx:
--------------------------------------------------------------------------------
1 | /* @flow */
2 |
3 | import * as React from 'react';
4 | import { Helmet } from 'react-helmet-async';
5 | import { useStaticQuery, graphql } from 'gatsby';
6 |
7 | type Props = {
8 | title?: string,
9 | description?: string,
10 | lang?: string,
11 | };
12 |
13 | export default function Seo({ title, description, lang }: Props): React.Node {
14 | const { site } = useStaticQuery(
15 | graphql`
16 | query Seo {
17 | site {
18 | siteMetadata {
19 | title
20 | description
21 | }
22 | }
23 | }
24 | `
25 | );
26 |
27 | const metaDescription = description || site?.siteMetadata?.description;
28 | const defaultTitle = site?.siteMetadata?.title;
29 |
30 | return (
31 |
68 | )
69 | }
70 |
--------------------------------------------------------------------------------
/examples/flow/src/images/gatsby-astronaut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/examples/flow/src/images/gatsby-astronaut.png
--------------------------------------------------------------------------------
/examples/flow/src/images/gatsby-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/examples/flow/src/images/gatsby-icon.png
--------------------------------------------------------------------------------
/examples/flow/src/pages/404.jsx:
--------------------------------------------------------------------------------
1 | /* @flow */
2 |
3 | import * as React from 'react';
4 |
5 | import Layout from '../components/layout';
6 | import Seo from '../components/seo';
7 |
8 | export default function NotFoundPage(): React.Node {
9 | return (
10 |
11 |
12 | 404: Not Found
13 | You just hit a route that doesn't exist... the sadness.
14 |
15 | );
16 | }
17 |
--------------------------------------------------------------------------------
/examples/flow/src/pages/index.jsx:
--------------------------------------------------------------------------------
1 | /* @flow */
2 |
3 | import * as React from 'react';
4 | import { Link } from 'gatsby';
5 | import { StaticImage } from 'gatsby-plugin-image';
6 |
7 | import Layout from '../components/layout';
8 | import Seo from '../components/seo';
9 |
10 | export default function IndexPage(): React.Node {
11 | return (
12 |
13 |
14 | Hi people
15 | Welcome to your new Gatsby site.
16 | Now go build something great.
17 |
25 |
26 | Go to page 2
27 | Go to "Using TypeScript"
28 | Go to "Using SSR"
29 | Go to "Using DSG"
30 |
31 |
32 | );
33 | }
34 |
--------------------------------------------------------------------------------
/examples/flow/src/pages/page-2.jsx:
--------------------------------------------------------------------------------
1 | /* @flow */
2 |
3 | import * as React from 'react';
4 | import { Link } from 'gatsby';
5 |
6 | import Layout from '../components/layout';
7 | import Seo from '../components/seo';
8 |
9 | export default function SecondPage(): React.Node {
10 | return (
11 |
12 |
13 | Hi from the second page
14 | Welcome to page 2
15 | Go back to the homepage
16 |
17 | );
18 | }
19 |
--------------------------------------------------------------------------------
/examples/mdx/.gitignore:
--------------------------------------------------------------------------------
1 | public/
2 | .cache/
3 |
--------------------------------------------------------------------------------
/examples/mdx/gatsby-config.ts:
--------------------------------------------------------------------------------
1 | import type { GatsbyConfig } from 'gatsby';
2 |
3 | const config: GatsbyConfig = {
4 | siteMetadata: {
5 | title: 'gatsby-plugin-typegen example',
6 | description: 'gatsby-plugin-typegen example with TypeScript',
7 | },
8 | plugins: [
9 | 'gatsby-plugin-react-helmet-async',
10 | 'gatsby-plugin-image',
11 | {
12 | resolve: 'gatsby-source-filesystem',
13 | options: {
14 | name: 'images',
15 | path: 'src/images',
16 | },
17 | },
18 | 'gatsby-transformer-sharp',
19 | 'gatsby-plugin-sharp',
20 | 'gatsby-plugin-mdx',
21 | {
22 | resolve: 'gatsby-plugin-typegen',
23 | options: {
24 | outputPath: 'src/__generated__/gatsby-types.d.ts',
25 | emitSchema: {
26 | 'src/__generated__/gatsby-introspection.json': true,
27 | 'src/__generated__/gatsby-schema.graphql': true,
28 | },
29 | emitPluginDocument: {
30 | 'src/__generated__/gatsby-plugin-documents.graphql': true,
31 | },
32 | },
33 | },
34 | ],
35 | };
36 |
37 | export default config;
38 |
--------------------------------------------------------------------------------
/examples/mdx/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example-mdx",
3 | "private": true,
4 | "description": "gatsby-plugin-typegen example with MDX",
5 | "version": "0.1.0",
6 | "author": {
7 | "name": "Hyeseong Kim",
8 | "email": "hey@hyeseong.kim"
9 | },
10 | "scripts": {
11 | "build": "gatsby build",
12 | "develop": "gatsby develop",
13 | "serve": "gatsby serve",
14 | "clean": "gatsby clean"
15 | },
16 | "dependencies": {
17 | "@mdx-js/mdx": "v1",
18 | "@mdx-js/react": "v1",
19 | "gatsby": "^4.16.0",
20 | "gatsby-plugin-image": "^2.16.1",
21 | "gatsby-plugin-mdx": "^3.16.1",
22 | "gatsby-plugin-react-helmet-async": "^1.2.1",
23 | "gatsby-plugin-sharp": "^4.16.1",
24 | "gatsby-plugin-typegen": "portal:../../plugin",
25 | "gatsby-source-filesystem": "^4.16.0",
26 | "gatsby-transformer-sharp": "^4.16.0",
27 | "react": "^18.1.0",
28 | "react-dom": "^18.1.0",
29 | "react-helmet-async": "^1.3.0",
30 | "sharp": "^0.30.6"
31 | },
32 | "devDependencies": {
33 | "@types/react": "^18.0.12",
34 | "typescript": "^4.7.3"
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/examples/mdx/src/__generated__/gatsby-plugin-documents.graphql:
--------------------------------------------------------------------------------
1 | fragment GatsbyImageSharpFixed on ImageSharpFixed {
2 | base64
3 | width
4 | height
5 | src
6 | srcSet
7 | }
8 |
9 | fragment GatsbyImageSharpFixed_tracedSVG on ImageSharpFixed {
10 | tracedSVG
11 | width
12 | height
13 | src
14 | srcSet
15 | }
16 |
17 | fragment GatsbyImageSharpFixed_withWebp on ImageSharpFixed {
18 | base64
19 | width
20 | height
21 | src
22 | srcSet
23 | srcWebp
24 | srcSetWebp
25 | }
26 |
27 | fragment GatsbyImageSharpFixed_withWebp_tracedSVG on ImageSharpFixed {
28 | tracedSVG
29 | width
30 | height
31 | src
32 | srcSet
33 | srcWebp
34 | srcSetWebp
35 | }
36 |
37 | fragment GatsbyImageSharpFixed_noBase64 on ImageSharpFixed {
38 | width
39 | height
40 | src
41 | srcSet
42 | }
43 |
44 | fragment GatsbyImageSharpFixed_withWebp_noBase64 on ImageSharpFixed {
45 | width
46 | height
47 | src
48 | srcSet
49 | srcWebp
50 | srcSetWebp
51 | }
52 |
53 | fragment GatsbyImageSharpFluid on ImageSharpFluid {
54 | base64
55 | aspectRatio
56 | src
57 | srcSet
58 | sizes
59 | }
60 |
61 | fragment GatsbyImageSharpFluidLimitPresentationSize on ImageSharpFluid {
62 | maxHeight: presentationHeight
63 | maxWidth: presentationWidth
64 | }
65 |
66 | fragment GatsbyImageSharpFluid_tracedSVG on ImageSharpFluid {
67 | tracedSVG
68 | aspectRatio
69 | src
70 | srcSet
71 | sizes
72 | }
73 |
74 | fragment GatsbyImageSharpFluid_withWebp on ImageSharpFluid {
75 | base64
76 | aspectRatio
77 | src
78 | srcSet
79 | srcWebp
80 | srcSetWebp
81 | sizes
82 | }
83 |
84 | fragment GatsbyImageSharpFluid_withWebp_tracedSVG on ImageSharpFluid {
85 | tracedSVG
86 | aspectRatio
87 | src
88 | srcSet
89 | srcWebp
90 | srcSetWebp
91 | sizes
92 | }
93 |
94 | fragment GatsbyImageSharpFluid_noBase64 on ImageSharpFluid {
95 | aspectRatio
96 | src
97 | srcSet
98 | sizes
99 | }
100 |
101 | fragment GatsbyImageSharpFluid_withWebp_noBase64 on ImageSharpFluid {
102 | aspectRatio
103 | src
104 | srcSet
105 | srcWebp
106 | srcSetWebp
107 | sizes
108 | }
--------------------------------------------------------------------------------
/examples/mdx/src/components/header.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Link } from 'gatsby';
3 |
4 | type HeaderProps = {
5 | siteTitle: string,
6 | };
7 |
8 | const Header: React.FC = ({ siteTitle }) => (
9 |
35 | );
36 |
37 | export default Header;
38 |
--------------------------------------------------------------------------------
/examples/mdx/src/components/layout.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { useStaticQuery, graphql } from 'gatsby';
3 |
4 | import Header from './header';
5 | import './layout.css';
6 |
7 | type Props = {
8 | children: React.ReactNode,
9 | };
10 |
11 | const Layout: React.FC = ({ children }) => {
12 | const data = useStaticQuery(graphql`
13 | query Layout {
14 | site {
15 | siteMetadata {
16 | title
17 | }
18 | }
19 | }
20 | `);
21 |
22 | return (
23 | <>
24 |
25 |
32 |
{children}
33 |
42 |
43 | >
44 | );
45 | };
46 |
47 | export default Layout;
48 |
--------------------------------------------------------------------------------
/examples/mdx/src/components/seo.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Helmet } from 'react-helmet-async';
3 | import { useStaticQuery, graphql } from 'gatsby';
4 |
5 | type Props = {
6 | title?: string,
7 | description?: string,
8 | lang?: string,
9 | };
10 |
11 | const Seo: React.FC = ({ title, description, lang }) => {
12 | const { site } = useStaticQuery(
13 | graphql`
14 | query Seo {
15 | site {
16 | siteMetadata {
17 | title
18 | description
19 | }
20 | }
21 | }
22 | `,
23 | );
24 |
25 | const metaDescription = description || site?.siteMetadata?.description || '';
26 | const defaultTitle = site?.siteMetadata?.title;
27 |
28 | return (
29 |
67 | );
68 | };
69 |
70 | export default Seo;
71 |
--------------------------------------------------------------------------------
/examples/mdx/src/images/gatsby-astronaut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/examples/mdx/src/images/gatsby-astronaut.png
--------------------------------------------------------------------------------
/examples/mdx/src/images/gatsby-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/examples/mdx/src/images/gatsby-icon.png
--------------------------------------------------------------------------------
/examples/mdx/src/pages/404.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 |
3 | import Layout from '../components/layout';
4 | import Seo from '../components/seo';
5 |
6 | const NotFoundPage: React.FC = () => (
7 |
8 |
9 | 404: Not Found
10 | You just hit a route that doesn't exist... the sadness.
11 |
12 | );
13 |
14 | export default NotFoundPage;
15 |
--------------------------------------------------------------------------------
/examples/mdx/src/pages/index.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Link } from 'gatsby';
3 | import { StaticImage } from 'gatsby-plugin-image';
4 |
5 | import Layout from '../components/layout';
6 | import Seo from '../components/seo';
7 |
8 | const IndexPage: React.FC = () => (
9 |
10 |
11 | Hi people
12 | Welcome to your new Gatsby site.
13 | Now go build something great.
14 |
22 |
23 | -
24 | Go to page 2
25 |
26 | -
27 |
28 | {'Go to "Using MDX"'}
29 |
30 |
31 |
32 |
33 | );
34 |
35 | export default IndexPage;
36 |
--------------------------------------------------------------------------------
/examples/mdx/src/pages/page-2.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Link } from 'gatsby';
3 |
4 | import Layout from '../components/layout';
5 | import Seo from '../components/seo';
6 |
7 | const SecondPage: React.FC = () => (
8 |
9 |
10 | Hi from the second page
11 | Welcome to page 2
12 | Go back to the homepage
13 |
14 | );
15 |
16 | export default SecondPage;
17 |
--------------------------------------------------------------------------------
/examples/mdx/src/pages/using-mdx.mdx:
--------------------------------------------------------------------------------
1 | import { graphql } from 'gatsby';
2 |
3 | export const query = graphql`
4 | query UsingMdx {
5 | site {
6 | siteMetadata {
7 | title
8 | }
9 | }
10 | }
11 | `;
12 |
13 | # Hey MDX
14 |
15 | Some Content
16 |
17 | Title: {props.data.site.siteMetadata.title}
18 |
--------------------------------------------------------------------------------
/examples/mdx/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.json",
3 | "include": [
4 | "src",
5 | "gatsby-config.ts"
6 | ],
7 | "exclude": [
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/examples/typescript/.gitignore:
--------------------------------------------------------------------------------
1 | public/
2 | .cache/
3 |
--------------------------------------------------------------------------------
/examples/typescript/gatsby-config.ts:
--------------------------------------------------------------------------------
1 | import type { GatsbyConfig } from 'gatsby';
2 |
3 | const config: GatsbyConfig = {
4 | siteMetadata: {
5 | title: 'gatsby-plugin-typegen example',
6 | description: 'gatsby-plugin-typegen example with TypeScript',
7 | },
8 | plugins: [
9 | 'gatsby-plugin-react-helmet-async',
10 | 'gatsby-plugin-image',
11 | {
12 | resolve: 'gatsby-source-filesystem',
13 | options: {
14 | name: 'images',
15 | path: 'src/images',
16 | },
17 | },
18 | 'gatsby-transformer-sharp',
19 | 'gatsby-plugin-sharp',
20 | {
21 | resolve: 'gatsby-plugin-typegen',
22 | options: {
23 | outputPath: 'src/__generated__/gatsby-types.d.ts',
24 | emitSchema: {
25 | 'src/__generated__/gatsby-introspection.json': true,
26 | 'src/__generated__/gatsby-schema.graphql': true,
27 | },
28 | emitPluginDocument: {
29 | 'src/__generated__/gatsby-plugin-documents.graphql': true,
30 | },
31 | },
32 | },
33 | ],
34 | };
35 |
36 | export default config;
37 |
--------------------------------------------------------------------------------
/examples/typescript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example-typescript",
3 | "private": true,
4 | "description": "gatsby-plugin-typegen example with TypeScript",
5 | "version": "0.1.0",
6 | "author": {
7 | "name": "Hyeseong Kim",
8 | "email": "hey@hyeseong.kim"
9 | },
10 | "scripts": {
11 | "build": "gatsby build",
12 | "develop": "gatsby develop",
13 | "serve": "gatsby serve",
14 | "clean": "gatsby clean"
15 | },
16 | "dependencies": {
17 | "gatsby": "^4.16.0",
18 | "gatsby-plugin-image": "^2.16.1",
19 | "gatsby-plugin-react-helmet-async": "^1.2.1",
20 | "gatsby-plugin-sharp": "^4.16.1",
21 | "gatsby-plugin-typegen": "portal:../../plugin",
22 | "gatsby-source-filesystem": "^4.16.0",
23 | "gatsby-transformer-sharp": "^4.16.0",
24 | "react": "^18.1.0",
25 | "react-dom": "^18.1.0",
26 | "react-helmet-async": "^1.3.0",
27 | "sharp": "^0.30.6"
28 | },
29 | "devDependencies": {
30 | "@types/react": "^18.0.12",
31 | "typescript": "^4.7.3"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/typescript/src/__generated__/gatsby-plugin-documents.graphql:
--------------------------------------------------------------------------------
1 | fragment GatsbyImageSharpFixed on ImageSharpFixed {
2 | base64
3 | width
4 | height
5 | src
6 | srcSet
7 | }
8 |
9 | fragment GatsbyImageSharpFixed_tracedSVG on ImageSharpFixed {
10 | tracedSVG
11 | width
12 | height
13 | src
14 | srcSet
15 | }
16 |
17 | fragment GatsbyImageSharpFixed_withWebp on ImageSharpFixed {
18 | base64
19 | width
20 | height
21 | src
22 | srcSet
23 | srcWebp
24 | srcSetWebp
25 | }
26 |
27 | fragment GatsbyImageSharpFixed_withWebp_tracedSVG on ImageSharpFixed {
28 | tracedSVG
29 | width
30 | height
31 | src
32 | srcSet
33 | srcWebp
34 | srcSetWebp
35 | }
36 |
37 | fragment GatsbyImageSharpFixed_noBase64 on ImageSharpFixed {
38 | width
39 | height
40 | src
41 | srcSet
42 | }
43 |
44 | fragment GatsbyImageSharpFixed_withWebp_noBase64 on ImageSharpFixed {
45 | width
46 | height
47 | src
48 | srcSet
49 | srcWebp
50 | srcSetWebp
51 | }
52 |
53 | fragment GatsbyImageSharpFluid on ImageSharpFluid {
54 | base64
55 | aspectRatio
56 | src
57 | srcSet
58 | sizes
59 | }
60 |
61 | fragment GatsbyImageSharpFluidLimitPresentationSize on ImageSharpFluid {
62 | maxHeight: presentationHeight
63 | maxWidth: presentationWidth
64 | }
65 |
66 | fragment GatsbyImageSharpFluid_tracedSVG on ImageSharpFluid {
67 | tracedSVG
68 | aspectRatio
69 | src
70 | srcSet
71 | sizes
72 | }
73 |
74 | fragment GatsbyImageSharpFluid_withWebp on ImageSharpFluid {
75 | base64
76 | aspectRatio
77 | src
78 | srcSet
79 | srcWebp
80 | srcSetWebp
81 | sizes
82 | }
83 |
84 | fragment GatsbyImageSharpFluid_withWebp_tracedSVG on ImageSharpFluid {
85 | tracedSVG
86 | aspectRatio
87 | src
88 | srcSet
89 | srcWebp
90 | srcSetWebp
91 | sizes
92 | }
93 |
94 | fragment GatsbyImageSharpFluid_noBase64 on ImageSharpFluid {
95 | aspectRatio
96 | src
97 | srcSet
98 | sizes
99 | }
100 |
101 | fragment GatsbyImageSharpFluid_withWebp_noBase64 on ImageSharpFluid {
102 | aspectRatio
103 | src
104 | srcSet
105 | srcWebp
106 | srcSetWebp
107 | sizes
108 | }
--------------------------------------------------------------------------------
/examples/typescript/src/components/header.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Link } from 'gatsby';
3 |
4 | type HeaderProps = {
5 | siteTitle: string,
6 | };
7 |
8 | const Header: React.FC = ({ siteTitle }) => (
9 |
35 | );
36 |
37 | export default Header;
38 |
--------------------------------------------------------------------------------
/examples/typescript/src/components/layout.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { useStaticQuery, graphql } from 'gatsby';
3 |
4 | import Header from './header';
5 | import './layout.css';
6 |
7 | type Props = {
8 | children: React.ReactNode,
9 | };
10 |
11 | const Layout: React.FC = ({ children }) => {
12 | const data = useStaticQuery(graphql`
13 | query Layout {
14 | site {
15 | siteMetadata {
16 | title
17 | }
18 | }
19 | }
20 | `);
21 |
22 | return (
23 | <>
24 |
25 |
32 |
{children}
33 |
42 |
43 | >
44 | );
45 | };
46 |
47 | export default Layout;
48 |
--------------------------------------------------------------------------------
/examples/typescript/src/components/seo.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Helmet } from 'react-helmet-async';
3 | import { useStaticQuery, graphql } from 'gatsby';
4 |
5 | type SeoProps = {
6 | title?: string,
7 | description?: string,
8 | lang?: string,
9 | };
10 |
11 | const Seo: React.FC = ({ title, description, lang }) => {
12 | const { site } = useStaticQuery(
13 | graphql`
14 | query Seo {
15 | site {
16 | siteMetadata {
17 | title
18 | description
19 | }
20 | }
21 | }
22 | `,
23 | );
24 |
25 | const metaDescription = description || site?.siteMetadata?.description || '';
26 | const defaultTitle = site?.siteMetadata?.title;
27 |
28 | return (
29 |
67 | );
68 | };
69 |
70 | export default Seo;
71 |
--------------------------------------------------------------------------------
/examples/typescript/src/images/gatsby-astronaut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/examples/typescript/src/images/gatsby-astronaut.png
--------------------------------------------------------------------------------
/examples/typescript/src/images/gatsby-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/examples/typescript/src/images/gatsby-icon.png
--------------------------------------------------------------------------------
/examples/typescript/src/pages/404.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 |
3 | import Layout from '../components/layout';
4 | import Seo from '../components/seo';
5 |
6 | const NotFoundPage: React.FC = () => (
7 |
8 |
9 | 404: Not Found
10 | You just hit a route that doesn't exist... the sadness.
11 |
12 | );
13 |
14 | export default NotFoundPage;
15 |
--------------------------------------------------------------------------------
/examples/typescript/src/pages/index.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Link } from 'gatsby';
3 | import { StaticImage } from 'gatsby-plugin-image';
4 |
5 | import Layout from '../components/layout';
6 | import Seo from '../components/seo';
7 |
8 | const IndexPage: React.FC = () => (
9 |
10 |
11 | Hi people
12 | Welcome to your new Gatsby site.
13 | Now go build something great.
14 |
22 |
23 | -
24 | Go to page 2
25 |
26 | -
27 |
28 | {'Go to "Using TypeScript"'}
29 |
30 |
31 |
32 |
33 | );
34 |
35 | export default IndexPage;
36 |
--------------------------------------------------------------------------------
/examples/typescript/src/pages/page-2.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { Link } from 'gatsby';
3 |
4 | import Layout from '../components/layout';
5 | import Seo from '../components/seo';
6 |
7 | const SecondPage: React.FC = () => (
8 |
9 |
10 | Hi from the second page
11 | Welcome to page 2
12 | Go back to the homepage
13 |
14 | );
15 |
16 | export default SecondPage;
17 |
--------------------------------------------------------------------------------
/examples/typescript/src/pages/using-typescript.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import type { PageProps } from 'gatsby';
3 | import { Link, graphql } from 'gatsby';
4 |
5 | import Layout from '../components/layout';
6 | import Seo from '../components/seo';
7 |
8 | type Props = PageProps;
9 |
10 | const UsingTypescriptPage: React.FC = ({ data, path }) => (
11 |
12 |
13 | Gatsby supports TypeScript by default!
14 |
15 | This means that you can create and write .ts/.tsx files for your
16 | pages, components etc. Please note that the gatsby-*.js files
17 | (like gatsby-node.js) currently don't support TypeScript yet.
18 |
19 |
20 | For type checking you'll want to install typescript via npm and
21 | run tsc --init to create a tsconfig file.
22 |
23 |
24 | You're currently on the page "{path}" which was built on{' '}
25 | {data.site?.buildTime}.
26 |
27 |
28 | To learn more, head over to our{' '}
29 |
30 | documentation about TypeScript
31 |
32 | .
33 |
34 | Go back to the homepage
35 |
36 | );
37 |
38 | export default UsingTypescriptPage;
39 |
40 | export const query = graphql`
41 | query UsingTypescriptPage {
42 | site {
43 | buildTime(formatString: "YYYY-MM-DD hh:mm a z")
44 | }
45 | }
46 | `;
47 |
--------------------------------------------------------------------------------
/examples/typescript/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.json",
3 | "include": [
4 | "src",
5 | "gatsby-config.ts"
6 | ],
7 | "exclude": [
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@gatsby-plugin-typegen/monorepo",
3 | "description": "Monorepo for gatsby-plugin-typegen",
4 | "private": true,
5 | "license": "MIT",
6 | "workspaces": [
7 | "plugin",
8 | "examples/**"
9 | ],
10 | "scripts": {
11 | "tsc:check": "tsc --noEmit",
12 | "lint": "eslint . --ext ts --ext tsx",
13 | "contributors:add": "all-contributors add",
14 | "contributors:generate": "all-contributors generate"
15 | },
16 | "devDependencies": {
17 | "@cometjs/eslint-plugin": "^2.0.0",
18 | "@rushstack/eslint-patch": "^1.1.3",
19 | "all-contributors-cli": "^6.20.0",
20 | "eslint": "^8.17.0",
21 | "typescript": "^4.7.3"
22 | },
23 | "packageManager": "yarn@3.2.1"
24 | }
25 |
--------------------------------------------------------------------------------
/plugin/.gitignore:
--------------------------------------------------------------------------------
1 | # JS artifacts
2 | /*.js
3 | /*.d.ts
4 | /internal
5 | /typing
6 | /services
7 | !/babel.config.js
8 | !/jest.config.js
9 | !/.eslintrc.js
10 | !/index.js
11 | !/.pnp.js
12 | !/.all-contributorsrc
13 |
14 | # Hack for flow
15 | /src/types.js
16 |
--------------------------------------------------------------------------------
/plugin/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Hyeseong Kim
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/plugin/__tests__/schema.test.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import * as fs from 'fs';
3 | import { buildSchema, printSchema } from 'gatsby/graphql';
4 |
5 | import {
6 | filterDevOnlySchema,
7 | filterPluginSchema,
8 | } from '../src/internal/utils';
9 |
10 | describe('stable schema', () => {
11 | it('should not containt dev only fields/values, and derived from plugin metadata', async () => {
12 | const inputSchemaFile = path.resolve(__dirname, './__fixtures__/gatsby-schema.graphql');
13 | const inputSchema = buildSchema(await fs.promises.readFile(inputSchemaFile, 'utf-8'));
14 | const outputSchema = filterPluginSchema(filterDevOnlySchema(inputSchema));
15 | expect(printSchema(outputSchema)).toMatchSnapshot();
16 | });
17 | });
18 |
--------------------------------------------------------------------------------
/plugin/__tests__/service-autofix.test.ts:
--------------------------------------------------------------------------------
1 | import { when } from 'jest-when';
2 | import { stripIndent } from 'common-tags';
3 |
4 | import { makeAutofixService } from '../src/services/autofix';
5 | import { testReporter } from '../test/reporter';
6 |
7 | describe('autofix service', () => {
8 | it('should insert type argument automatically for TypeScript files', async () => {
9 | const readFileContent = jest.fn, [string]>();
10 | const writeFileContent = jest.fn, [string, string]>();
11 |
12 | const autofix = makeAutofixService({
13 | language: 'typescript',
14 | namespace: 'GatsbyTypes',
15 | reporter: testReporter,
16 | readFileContent,
17 | writeFileContent,
18 | });
19 |
20 | when(readFileContent)
21 | .calledWith('use-static-query.ts')
22 | .mockResolvedValue(stripIndent`
23 | const data = useStaticQuery(graphql\`
24 | query Test {
25 | test
26 | }
27 | \`);
28 | `);
29 |
30 | when(readFileContent)
31 | .calledWith('static-query-component.tsx')
32 | .mockResolvedValue(stripIndent`
33 | return (
34 | (
41 |
42 | )}
43 | />
44 | );
45 | `);
46 |
47 | await autofix([
48 | 'use-static-query.ts',
49 | 'static-query-component.tsx',
50 | ]);
51 |
52 | expect(writeFileContent).toBeCalledWith('use-static-query.ts', stripIndent`
53 | const data = useStaticQuery(graphql\`
54 | query Test {
55 | test
56 | }
57 | \`);
58 | `);
59 |
60 | expect(writeFileContent).toBeCalledWith('static-query-component.tsx', stripIndent`
61 | return (
62 |
63 | query={graphql\`
64 | query Test {
65 | test
66 | }
67 | \`}
68 | render={data => (
69 |
70 | )}
71 | />
72 | );
73 | `);
74 | });
75 | });
76 |
--------------------------------------------------------------------------------
/plugin/__tests__/service-codegen-flow.test.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import * as fs from 'fs';
3 | import { buildSchema, parse } from 'gatsby/graphql';
4 |
5 | import { filterDevOnlySchema, filterPluginSchema } from '../src/internal/utils';
6 | import { testReporter } from '../test/reporter';
7 | import { makeCodegenService } from '../src/services/codegen';
8 |
9 | describe('codegen service', () => {
10 | test('flow', async () => {
11 | const writeFileContent = jest.fn, [string, string]>();
12 |
13 | const codegen = makeCodegenService({
14 | outputPath: 'codegen.flow.js',
15 | namespace: 'GatsbyTypes',
16 | language: 'flow',
17 | reporter: testReporter,
18 | includeResolvers: true,
19 | customScalars: {},
20 | writeFileContent,
21 | });
22 |
23 | const inputSchemaFile = path.resolve(__dirname, './__fixtures__/gatsby-schema.graphql');
24 | const inputSchema = buildSchema(await fs.promises.readFile(inputSchemaFile, 'utf-8'));
25 | const schema = filterPluginSchema(filterDevOnlySchema(inputSchema));
26 |
27 | const document = parse(`
28 | query Test {
29 | site {
30 | siteMetadata {
31 | title
32 | }
33 | }
34 | }
35 | `);
36 |
37 | await codegen({ schema, documents: [{ document }] });
38 |
39 | const [outputPath, content] = writeFileContent.mock.calls[0];
40 | expect(content).toMatchSnapshot(outputPath);
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/plugin/__tests__/service-codegen-typescript.test.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import * as fs from 'fs';
3 | import { buildSchema, parse } from 'gatsby/graphql';
4 |
5 | import { filterDevOnlySchema, filterPluginSchema } from '../src/internal/utils';
6 | import { testReporter } from '../test/reporter';
7 | import { makeCodegenService } from '../src/services/codegen';
8 |
9 | describe('codegen service', () => {
10 | test('typescript', async () => {
11 | const writeFileContent = jest.fn, [string, string]>();
12 |
13 | const codegen = makeCodegenService({
14 | outputPath: 'codegen.d.ts',
15 | namespace: 'GatsbyTypes',
16 | language: 'typescript',
17 | reporter: testReporter,
18 | includeResolvers: true,
19 | customScalars: {},
20 | writeFileContent,
21 | });
22 |
23 | const inputSchemaFile = path.resolve(__dirname, './__fixtures__/gatsby-schema.graphql');
24 | const inputSchema = buildSchema(await fs.promises.readFile(inputSchemaFile, 'utf-8'));
25 | const schema = filterPluginSchema(filterDevOnlySchema(inputSchema));
26 |
27 | const document = parse(`
28 | query Test {
29 | site {
30 | siteMetadata {
31 | title
32 | }
33 | }
34 | }
35 | `);
36 |
37 | await codegen({ schema, documents: [{ document }] });
38 |
39 | const [outputPath, content] = writeFileContent.mock.calls[0];
40 | expect(content).toMatchSnapshot(outputPath);
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/plugin/__tests__/service-emitSchema-0.test.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import * as fs from 'fs';
3 | import { buildSchema } from 'gatsby/graphql';
4 |
5 | import { stabilizeSchema } from '../src/internal/utils';
6 | import { testReporter } from '../test/reporter';
7 | import { makeEmitSchemaService } from '../src/services/emitSchema';
8 |
9 | describe('emitSchema service', () => {
10 | it('should emits nothing for empty config map', async () => {
11 | const writeFileContent = jest.fn, [string, string]>();
12 |
13 | const emitSchema = makeEmitSchemaService({
14 | configMap: {},
15 | reporter: testReporter,
16 | writeFileContent,
17 | });
18 |
19 | const inputSchemaFile = path.resolve(__dirname, './__fixtures__/gatsby-schema.graphql');
20 | const inputSchema = buildSchema(await fs.promises.readFile(inputSchemaFile, 'utf-8'));
21 | const stableSchema = stabilizeSchema(inputSchema);
22 |
23 | await emitSchema(stableSchema);
24 |
25 | expect(writeFileContent).not.toHaveBeenCalled();
26 | });
27 | });
28 |
--------------------------------------------------------------------------------
/plugin/__tests__/service-emitSchema-introspection.test.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import * as fs from 'fs';
3 | import { buildSchema } from 'gatsby/graphql';
4 |
5 | import { testReporter } from '../test/reporter';
6 | import { stabilizeSchema } from '../src/internal/utils';
7 | import { makeEmitSchemaService } from '../src/services/emitSchema';
8 |
9 | describe('emitSchema service', () => {
10 | it('should emits schema to configured paths in configuired formats', async () => {
11 | const writeFileContent = jest.fn, [string, string]>();
12 |
13 | const emitSchema = makeEmitSchemaService({
14 | configMap: {
15 | 'schema.json': {
16 | format: 'introspection',
17 | commentDescriptions: true,
18 | omitPluginMetadata: true,
19 | },
20 | },
21 | reporter: testReporter,
22 | writeFileContent,
23 | });
24 |
25 | const inputSchemaFile = path.resolve(__dirname, './__fixtures__/gatsby-schema.graphql');
26 | const inputSchema = buildSchema(await fs.promises.readFile(inputSchemaFile, 'utf-8'));
27 | const stableSchema = stabilizeSchema(inputSchema);
28 |
29 | await emitSchema(stableSchema);
30 |
31 | for (const [filePath, content] of writeFileContent.mock.calls) {
32 | expect(content).toMatchSnapshot(filePath);
33 | }
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/plugin/__tests__/service-emitSchema-sdl.test.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import * as fs from 'fs';
3 | import { buildSchema } from 'gatsby/graphql';
4 |
5 | import { testReporter } from '../test/reporter';
6 | import { stabilizeSchema } from '../src/internal/utils';
7 | import { makeEmitSchemaService } from '../src/services/emitSchema';
8 |
9 | describe('emitSchema service', () => {
10 | it('should emits schema to configured paths in configuired formats', async () => {
11 | const writeFileContent = jest.fn, [string, string]>();
12 |
13 | const emitSchema = makeEmitSchemaService({
14 | configMap: {
15 | 'schema.graphql': {
16 | format: 'sdl',
17 | commentDescriptions: true,
18 | omitPluginMetadata: true,
19 | },
20 | },
21 | reporter: testReporter,
22 | writeFileContent,
23 | });
24 |
25 | const inputSchemaFile = path.resolve(__dirname, './__fixtures__/gatsby-schema.graphql');
26 | const inputSchema = buildSchema(await fs.promises.readFile(inputSchemaFile, 'utf-8'));
27 | const stableSchema = stabilizeSchema(inputSchema);
28 |
29 | await emitSchema(stableSchema);
30 |
31 | for (const [filePath, content] of writeFileContent.mock.calls) {
32 | expect(content).toMatchSnapshot(filePath);
33 | }
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/plugin/babel.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "babel-preset-gatsby-package"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/plugin/images/auto-fixing-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/plugin/images/auto-fixing-demo.gif
--------------------------------------------------------------------------------
/plugin/images/gatsby-schema-visualized.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/plugin/images/gatsby-schema-visualized.png
--------------------------------------------------------------------------------
/plugin/images/ts-graphql-plugin-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/plugin/images/ts-graphql-plugin-demo.gif
--------------------------------------------------------------------------------
/plugin/images/vscode-extension-preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/plugin/images/vscode-extension-preview.png
--------------------------------------------------------------------------------
/plugin/images/vscode-graphql-extension-preview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometkim/gatsby-plugin-typegen/b452c4274e35d3e0eebcad930696eb7131d8be8b/plugin/images/vscode-graphql-extension-preview.gif
--------------------------------------------------------------------------------
/plugin/index.js:
--------------------------------------------------------------------------------
1 | // noop
2 |
--------------------------------------------------------------------------------
/plugin/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "gatsby-plugin-typegen",
3 | "description": "Gatsby plugin to play with extream type-safety",
4 | "version": "3.1.0",
5 | "main": "index.js",
6 | "license": "MIT",
7 | "author": {
8 | "name": "Hyeseong Kim",
9 | "email": "hey@hyeseong.kim",
10 | "url": "https://github.com/cometkim"
11 | },
12 | "homepage": "https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/",
13 | "repository": {
14 | "type": "git",
15 | "url": "git+https://github.com/cometkim/gatsby-plugin-typegen.git"
16 | },
17 | "bugs": {
18 | "url": "https://github.com/cometkim/gatsby-plugin-typegen/issues",
19 | "email": "hey@hyeseong.kim"
20 | },
21 | "keywords": [
22 | "gatsby",
23 | "gatsby-plugin",
24 | "graphql",
25 | "codegen",
26 | "typescript",
27 | "flow"
28 | ],
29 | "scripts": {
30 | "test": "jest",
31 | "codegen": "xstate typegen src/internal/machine.ts",
32 | "build": "concurrently \"yarn:build:*\"",
33 | "build:js": "babel src -d . --extensions .ts,.tsx",
34 | "build:dts": "tsc -p tsconfig.build.json --emitDeclarationOnly",
35 | "build:flow": "babel src/types.flow.js -d . --plugins module:@babel/plugin-transform-flow-comments",
36 | "develop": "babel src -d . --extensions .ts,.tsx --watch",
37 | "prepack": "yarn build"
38 | },
39 | "files": [
40 | "index.js",
41 | "gatsby-node.js",
42 | "types.js",
43 | "types.d.ts",
44 | "types.js.flow",
45 | "utils.js",
46 | "internal",
47 | "services"
48 | ],
49 | "peerDependencies": {
50 | "gatsby": "^4.0.0 || ^5.0.0",
51 | "graphql": "^15.0.0 || ^16.0.0"
52 | },
53 | "dependencies": {
54 | "@graphql-codegen/add": "^3.1.1",
55 | "@graphql-codegen/core": "^2.5.1",
56 | "@graphql-codegen/flow": "^2.2.13",
57 | "@graphql-codegen/flow-operations": "^2.2.13",
58 | "@graphql-codegen/flow-resolvers": "^2.2.14",
59 | "@graphql-codegen/plugin-helpers": "^2.4.2",
60 | "@graphql-codegen/typescript": "^2.5.1",
61 | "@graphql-codegen/typescript-operations": "^2.4.2",
62 | "@graphql-codegen/typescript-resolvers": "^2.6.6",
63 | "@graphql-codegen/visitor-plugin-common": "^2.9.1",
64 | "@graphql-tools/utils": "^8.6.13",
65 | "lodash": "^4.17.21",
66 | "slugify": "^1.6.5",
67 | "xstate": "^4.32.1"
68 | },
69 | "devDependencies": {
70 | "@babel/cli": "^7.17.10",
71 | "@babel/core": "^7.18.2",
72 | "@babel/plugin-transform-flow-comments": "^7.17.12",
73 | "@babel/plugin-transform-typescript": "^7.18.4",
74 | "@babel/runtime": "^7.18.3",
75 | "@types/common-tags": "^1.8.1",
76 | "@types/graphql": "^14.5.0",
77 | "@types/jest": "^28.1.1",
78 | "@types/jest-when": "^3.5.0",
79 | "@types/lodash": "^4.14.182",
80 | "@types/node": "^17.0.42",
81 | "@xstate/cli": "^0.2.1",
82 | "babel-preset-gatsby-package": "^2.16.0",
83 | "common-tags": "^1.8.2",
84 | "concurrently": "^7.2.1",
85 | "gatsby": "^5.0.1",
86 | "graphql": "^16.6.0",
87 | "jest": "^28.1.1",
88 | "jest-when": "^3.5.1",
89 | "typescript": "^4.7.3"
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/plugin/src/gatsby-node.ts:
--------------------------------------------------------------------------------
1 | import type { GatsbyNode, Reporter } from 'gatsby';
2 | import { interpret } from 'xstate';
3 | import { Kind } from 'gatsby/graphql';
4 |
5 | import type { TypegenReporter } from './internal/reporter';
6 | import { validateConfig } from './internal/config';
7 | import { typegenMachine } from './internal/machine';
8 | import { sortDefinitions } from './internal/utils';
9 |
10 | import { makeEmitSchemaService } from './services/emitSchema';
11 | import { makeEmitPluginDocumentService } from './services/emitPluginDocument';
12 | import { makeAutofixService } from './services/autofix';
13 | import { makeCodegenService } from './services/codegen';
14 |
15 | import type { PluginOptions } from './types';
16 | import {
17 | readFileContent,
18 | writeFileContent,
19 | isCloudBuild,
20 | } from './utils';
21 |
22 | export const pluginOptionsSchema: GatsbyNode['pluginOptionsSchema'] = ({
23 | Joi,
24 | }) => {
25 | const documentOutputOptionsSchema = Joi.object({
26 | format: Joi.string()
27 | .valid('introspection', 'sdl')
28 | .default('sdl')
29 | .required(),
30 | commentDescriptions: Joi.boolean()
31 | .default(true),
32 | }).required();
33 |
34 | return Joi.object({
35 | language: Joi.string()
36 | .valid('typescript', 'flow')
37 | .default('typescript'),
38 | namespace: Joi.string()
39 | .default('GatsbyTypes'),
40 | outputPath: Joi.string()
41 | .default('src/__generated__/gatsby-types.d.ts'),
42 | includeResolvers: Joi.boolean()
43 | .default(false),
44 | autoFix: Joi.boolean(),
45 | autofix: Joi.boolean()
46 | .default(true),
47 | scalars: Joi.object()
48 | .pattern(/\w[\w\d\-_]+/, Joi.string().required())
49 | .default({}),
50 | emitSchema: Joi.object()
51 | .pattern(/.+/, [
52 | Joi.boolean().required(),
53 | documentOutputOptionsSchema,
54 | ]),
55 | emitPluginDocuments: Joi.object()
56 | .pattern(/.+/, [
57 | Joi.boolean().required(),
58 | documentOutputOptionsSchema,
59 | ]),
60 | emitPluginDocument: Joi.object()
61 | .pattern(/.+/, [
62 | Joi.boolean().required(),
63 | documentOutputOptionsSchema,
64 | ]),
65 | });
66 | };
67 |
68 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
69 | let spawnedMachine: any = null;
70 |
71 | export const onPreBootstrap: GatsbyNode['onPreBootstrap'] = ({
72 | store,
73 | emitter,
74 | reporter,
75 | }, options) => {
76 | const typegenReporter = makeTypegenReporter(reporter);
77 | const pluginOptions = options as unknown as PluginOptions;
78 |
79 | const { program } = store.getState();
80 | const basePath = program.directory;
81 |
82 | const config = validateConfig({
83 | basePath,
84 | options: pluginOptions,
85 | reporter: typegenReporter,
86 | });
87 |
88 | typegenReporter.verbose(reporter.stripIndent`
89 | loaded configuration
90 | ${JSON.stringify(pluginOptions, null, 2)}
91 | `);
92 |
93 | if (isCloudBuild(process.env)) {
94 | typegenReporter.verbose(reporter.stripIndent`
95 | skip running on cloud build
96 | `);
97 | return;
98 | }
99 |
100 | const emitSchema = makeEmitSchemaService({
101 | configMap: config.emitSchema,
102 | reporter: typegenReporter,
103 | writeFileContent,
104 | });
105 |
106 | const emitPluginDocument = makeEmitPluginDocumentService({
107 | configMap: config.emitPluginDocument,
108 | reporter: typegenReporter,
109 | writeFileContent,
110 | });
111 |
112 | const autofix = makeAutofixService({
113 | ...config,
114 | readFileContent,
115 | writeFileContent,
116 | reporter: typegenReporter,
117 | });
118 |
119 | const codegen = makeCodegenService({
120 | ...config,
121 | customScalars: config.scalars,
122 | reporter: typegenReporter,
123 | writeFileContent,
124 | });
125 |
126 | const typegenService = interpret(
127 | typegenMachine
128 | .withContext({
129 | config,
130 | debouncingDelay: 500,
131 | devMode: false,
132 | reporter: typegenReporter,
133 | })
134 | .withConfig({
135 | actions: {
136 | reportEmitSchemaError: (context, event) => {
137 | context.reporter.error('error occurred while running emitSchema service', event.data as Error);
138 | },
139 | reportEmitPluginDocumentError: (context, event) => {
140 | context.reporter.error('error occurred while running emitPluginDocument service', event.data as Error);
141 | },
142 | reportCodegenError: (context, event) => {
143 | context.reporter.error('error occurred while running codegen service', event.data as Error);
144 | },
145 | reportAutofixError: (context, event) => {
146 | context.reporter.error('error occurred while running autofix service', event.data as Error);
147 | },
148 | },
149 | services: {
150 | emitSchema: context => {
151 | if (!context.schema) {
152 | return Promise.reject(
153 | new Error('schema is not initilaized'),
154 | );
155 | }
156 | return emitSchema(context.schema);
157 | },
158 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment
159 | // @ts-ignore for typegen bug
160 | emitPluginDocument: context => emitPluginDocument(context.thirdpartyFragments || []),
161 | codegen: context => {
162 | if (!context.schema) {
163 | return Promise.reject(
164 | new Error('schema is not initilaized'),
165 | );
166 | }
167 | return codegen({
168 | schema: context.schema,
169 | documents: [...context.trackedDefinitions?.values() || []]
170 | .sort(sortDefinitions)
171 | .map(definitionMeta => ({
172 | document: {
173 | kind: Kind.DOCUMENT,
174 | definitions: [definitionMeta.def],
175 | },
176 | hash: definitionMeta.hash.toString(),
177 | })),
178 | });
179 | },
180 | autofix: (context, event) => {
181 | if (!context.config.autofix) {
182 | const files = event.files ??
183 | [...context.trackedDefinitions?.values() || []].map(def => def.filePath);
184 | return autofix(files);
185 | }
186 | return Promise.resolve();
187 | },
188 | },
189 | }),
190 | );
191 |
192 | typegenService.start();
193 |
194 | typegenService.onTransition(({ event, value, changed }) => {
195 | typegenReporter.verbose(`on ${event.type}`);
196 | if (changed) {
197 | typegenReporter.verbose(` ⤷ transition to ${JSON.stringify(value)}`);
198 | } else {
199 | typegenReporter.verbose(' ⤷ skipped');
200 | }
201 | });
202 |
203 | spawnedMachine = typegenService;
204 |
205 | emitter.on('SET_SCHEMA', () => {
206 | typegenService.send({ type: 'SET_SCHEMA', schema: store.getState().schema });
207 | });
208 |
209 | emitter.on('SET_GRAPHQL_DEFINITIONS', () => {
210 | typegenService.send({ type: 'SET_GRAPHQL_DEFINITIONS', definitions: store.getState().definitions });
211 | });
212 | };
213 |
214 | export const onCreateDevServer: GatsbyNode['onCreateDevServer'] = () => {
215 | spawnedMachine?.send('CREATE_DEV_SERVER');
216 | };
217 |
218 | function makeTypegenReporter(reporter: Reporter): TypegenReporter {
219 | const formatMessage = (message: string) => `[typegen] ${message}`;
220 | return {
221 | stripIndent: reporter.stripIndent,
222 | log: message => reporter.log(formatMessage(message)),
223 | info: message => reporter.info(formatMessage(message)),
224 | warn: message => reporter.warn(formatMessage(message)),
225 | verbose: message => reporter.verbose(formatMessage(message)),
226 | error: (message, e) => reporter.error(formatMessage(message), e, 'gatsby-plugin-typegen'),
227 | panic: (message, e) => reporter.panic(formatMessage(message), e, 'gatsby-plugin-typegen'),
228 | panicOnBuild: (message, e) => reporter.panicOnBuild(formatMessage(message), e, 'gatsby-plugin-typegen'),
229 | activity: message => reporter.activityTimer(formatMessage(message)),
230 | progress: (message, total) => reporter.createProgress(formatMessage(message), total),
231 | };
232 | }
233 |
--------------------------------------------------------------------------------
/plugin/src/internal/config.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 |
3 | import type {
4 | PluginOptions,
5 | SchemaOutputOptions,
6 | DocumentOutputOptions,
7 | } from './pluginOptions';
8 | import type { TypegenReporter } from './reporter';
9 | import type { OverrideProps } from './utils';
10 | import { formatLanguage, gatsbyInternalScalars } from './utils';
11 |
12 | const defaultSchemaOutputOption = Object.freeze({
13 | format: 'introspection',
14 | commentDescriptions: true,
15 | omitPluginMetadata: true,
16 | } as const);
17 |
18 | const defaultDocumentOutputOption = Object.freeze({
19 | format: 'graphql',
20 | } as const);
21 |
22 | type EmitSchemaConfig = {
23 | [filePath: string]: Required,
24 | };
25 |
26 | type EmitPluginDocumentConfig = {
27 | [filePath: string]: Required,
28 | };
29 |
30 | export type Config = OverrideProps<
31 | Required, {
32 | emitSchema: EmitSchemaConfig,
33 | emitPluginDocument: EmitPluginDocumentConfig,
34 |
35 | // deprecated options
36 | autoFix?: void,
37 | emitPluginDocuments?: void,
38 | }
39 | >;
40 |
41 | interface ValidateConfig {
42 | (
43 | props: {
44 | options: PluginOptions,
45 | basePath: string,
46 | reporter: TypegenReporter,
47 | },
48 | ): Readonly;
49 | }
50 |
51 | export const validateConfig: ValidateConfig = ({
52 | options,
53 | basePath,
54 | reporter,
55 | }) => {
56 | // There are no required properties (yet), so must be compatible.
57 | const pluginOptions = options;
58 |
59 | const {
60 | language = 'typescript',
61 | namespace = 'GatsbyTypes',
62 | includeResolvers = false,
63 | autoFix,
64 | autofix,
65 | emitSchema: emitSchemaOptionMap = {},
66 | emitPluginDocuments: legacyEmitPluginDocumentsOptionMap = {},
67 | emitPluginDocument: emitPluginDocumentsOptionMap = {},
68 | scalars = {},
69 | } = pluginOptions;
70 |
71 | if (autoFix != null) {
72 | reporter.warn('The `autoFix` option is deprecated. Use `autofix` instead.');
73 | }
74 |
75 | if (includeResolvers) {
76 | reporter.warn('The `includeResolvers` option is deprecated. It will be removed in v4');
77 | }
78 |
79 | const emitSchema: EmitSchemaConfig = {};
80 | for (const [key, options] of Object.entries(emitSchemaOptionMap)) {
81 | if (!options) continue;
82 | if (options === true) {
83 | emitSchema[key] = {
84 | ...defaultSchemaOutputOption,
85 | // Infer format option based on filename.
86 | format: /\.(graphql|graphqls|gql)$/.test(key)
87 | ? 'sdl'
88 | : 'introspection',
89 | };
90 | } else {
91 | emitSchema[key] = {
92 | ...defaultSchemaOutputOption,
93 | ...options,
94 | };
95 | }
96 | }
97 |
98 | const emitPluginDocument: EmitPluginDocumentConfig = {};
99 |
100 | // TBD: remove next major release
101 | for (const [key, options] of Object.entries(legacyEmitPluginDocumentsOptionMap)) {
102 | if (!options) continue;
103 | if (options === true) {
104 | emitPluginDocument[key] = {
105 | ...defaultDocumentOutputOption,
106 | format: /\.json$/.test(key)
107 | ? 'json'
108 | : 'graphql',
109 | };
110 | } else {
111 | emitPluginDocument[key] = {
112 | ...defaultDocumentOutputOption,
113 | ...options,
114 | };
115 | }
116 | }
117 | for (const [key, options] of Object.entries(emitPluginDocumentsOptionMap)) {
118 | if (!options) continue;
119 | if (options === true) {
120 | emitPluginDocument[key] = {
121 | ...defaultDocumentOutputOption,
122 | // Infer format option based on filename.
123 | format: /\.json$/.test(key)
124 | ? 'json'
125 | : 'graphql',
126 | };
127 | } else {
128 | emitPluginDocument[key] = {
129 | ...defaultDocumentOutputOption,
130 | ...options,
131 | };
132 | }
133 | }
134 |
135 | const outputPath = pluginOptions.outputPath || (
136 | language === 'typescript'
137 | ? path.resolve(basePath, 'src/__generated__/gatsby-types.d.ts')
138 | : path.resolve(basePath, 'src/__generated__/gatsby-types.js.flow')
139 | );
140 |
141 | if ((language === 'typescript') !== /\.tsx?$/.test(outputPath)) {
142 | reporter.warn(
143 | reporter.stripIndent`
144 | The language you specified is not match to file extension.
145 | - language: ${formatLanguage(language)}
146 | - outputPath: ${outputPath}
147 | `,
148 | );
149 | }
150 |
151 | for (const type of gatsbyInternalScalars) {
152 | if (scalars[type]) {
153 | reporter.warn(
154 | `You couldn't override type for \`${type}\` scalar because it is reserved by Gatsby internal.`,
155 | );
156 | delete scalars[type];
157 | }
158 | }
159 |
160 | return Object.freeze({
161 | language,
162 | namespace,
163 | outputPath,
164 | includeResolvers,
165 | autofix: (autofix === true) || (autoFix === true) || (autofix !== false),
166 | emitSchema,
167 | emitPluginDocument,
168 | scalars,
169 | });
170 | };
171 |
--------------------------------------------------------------------------------
/plugin/src/internal/machine.typegen.ts:
--------------------------------------------------------------------------------
1 | // This file was automatically generated. Edits will be overwritten
2 |
3 | export interface Typegen0 {
4 | "@@xstate/typegen": true;
5 | eventsCausingActions: {
6 | assignDevMode: "CREATE_DEV_SERVER";
7 | assignSchema: "SET_SCHEMA" | "CHANGE_SCHEMA";
8 | assignThirdpartyDefinitions: "SET_GRAPHQL_DEFINITIONS";
9 | assignDefinitions: "SET_GRAPHQL_DEFINITIONS" | "CHANGE_GRAPHQL_DEFINITIONS";
10 | reportEmitSchemaError:
11 | | "error.platform.(machine).runningOnce.running.emitSchema.running:invocation[0]"
12 | | "error.platform.(machine).watching.jobs.emitSchema.running:invocation[0]";
13 | reportEmitPluginDocumentError: "error.platform.(machine).runningOnce.running.emitPluginDocument.running:invocation[0]";
14 | reportCodegenError:
15 | | "error.platform.(machine).runningOnce.running.codegen.running:invocation[0]"
16 | | "error.platform.(machine).watching.jobs.codegen.running:invocation[0]";
17 | reportAutofixError:
18 | | "error.platform.(machine).runningOnce.running.autofix.running:invocation[0]"
19 | | "error.platform.(machine).watching.jobs.autofix.running:invocation[0]";
20 | onSchemaChange: "SET_SCHEMA";
21 | onDefinitionsChange: "SET_GRAPHQL_DEFINITIONS";
22 | };
23 | internalEvents: {
24 | "error.platform.(machine).runningOnce.running.emitSchema.running:invocation[0]": {
25 | type: "error.platform.(machine).runningOnce.running.emitSchema.running:invocation[0]";
26 | data: unknown;
27 | };
28 | "error.platform.(machine).watching.jobs.emitSchema.running:invocation[0]": {
29 | type: "error.platform.(machine).watching.jobs.emitSchema.running:invocation[0]";
30 | data: unknown;
31 | };
32 | "error.platform.(machine).runningOnce.running.emitPluginDocument.running:invocation[0]": {
33 | type: "error.platform.(machine).runningOnce.running.emitPluginDocument.running:invocation[0]";
34 | data: unknown;
35 | };
36 | "error.platform.(machine).runningOnce.running.codegen.running:invocation[0]": {
37 | type: "error.platform.(machine).runningOnce.running.codegen.running:invocation[0]";
38 | data: unknown;
39 | };
40 | "error.platform.(machine).watching.jobs.codegen.running:invocation[0]": {
41 | type: "error.platform.(machine).watching.jobs.codegen.running:invocation[0]";
42 | data: unknown;
43 | };
44 | "error.platform.(machine).runningOnce.running.autofix.running:invocation[0]": {
45 | type: "error.platform.(machine).runningOnce.running.autofix.running:invocation[0]";
46 | data: unknown;
47 | };
48 | "error.platform.(machine).watching.jobs.autofix.running:invocation[0]": {
49 | type: "error.platform.(machine).watching.jobs.autofix.running:invocation[0]";
50 | data: unknown;
51 | };
52 | "done.invoke.(machine).watching.jobs.emitSchema.running:invocation[0]": {
53 | type: "done.invoke.(machine).watching.jobs.emitSchema.running:invocation[0]";
54 | data: unknown;
55 | __tip: "See the XState TS docs to learn how to strongly type this.";
56 | };
57 | "done.invoke.(machine).watching.jobs.codegen.running:invocation[0]": {
58 | type: "done.invoke.(machine).watching.jobs.codegen.running:invocation[0]";
59 | data: unknown;
60 | __tip: "See the XState TS docs to learn how to strongly type this.";
61 | };
62 | "done.invoke.(machine).watching.jobs.autofix.running:invocation[0]": {
63 | type: "done.invoke.(machine).watching.jobs.autofix.running:invocation[0]";
64 | data: unknown;
65 | __tip: "See the XState TS docs to learn how to strongly type this.";
66 | };
67 | "xstate.init": { type: "xstate.init" };
68 | };
69 | invokeSrcNameMap: {
70 | emitSchema:
71 | | "done.invoke.(machine).runningOnce.running.emitSchema.running:invocation[0]"
72 | | "done.invoke.(machine).watching.jobs.emitSchema.running:invocation[0]";
73 | emitPluginDocument: "done.invoke.(machine).runningOnce.running.emitPluginDocument.running:invocation[0]";
74 | codegen:
75 | | "done.invoke.(machine).runningOnce.running.codegen.running:invocation[0]"
76 | | "done.invoke.(machine).watching.jobs.codegen.running:invocation[0]";
77 | autofix:
78 | | "done.invoke.(machine).runningOnce.running.autofix.running:invocation[0]"
79 | | "done.invoke.(machine).watching.jobs.autofix.running:invocation[0]";
80 | };
81 | missingImplementations: {
82 | actions:
83 | | "reportEmitSchemaError"
84 | | "reportEmitPluginDocumentError"
85 | | "reportCodegenError"
86 | | "reportAutofixError";
87 | services: "emitSchema" | "emitPluginDocument" | "codegen" | "autofix";
88 | guards: never;
89 | delays: never;
90 | };
91 | eventsCausingServices: {
92 | emitSchema: "START_emitSchema";
93 | emitPluginDocument: "xstate.init";
94 | codegen: "START_codegen";
95 | autofix: "START_autofix";
96 | };
97 | eventsCausingGuards: {
98 | "ready?": "CHECK_IF_READY";
99 | "devMode?": "done.state.(machine).runningOnce.running";
100 | "hasSchemaChanged?": "SET_SCHEMA";
101 | "hasDefinitionsChanged?": "SET_GRAPHQL_DEFINITIONS";
102 | };
103 | eventsCausingDelays: {};
104 | matchesStates:
105 | | "initializing"
106 | | "runningOnce"
107 | | "runningOnce.running"
108 | | "runningOnce.running.emitSchema"
109 | | "runningOnce.running.emitSchema.running"
110 | | "runningOnce.running.emitSchema.done"
111 | | "runningOnce.running.emitPluginDocument"
112 | | "runningOnce.running.emitPluginDocument.running"
113 | | "runningOnce.running.emitPluginDocument.done"
114 | | "runningOnce.running.codegen"
115 | | "runningOnce.running.codegen.running"
116 | | "runningOnce.running.codegen.done"
117 | | "runningOnce.running.autofix"
118 | | "runningOnce.running.autofix.running"
119 | | "runningOnce.running.autofix.done"
120 | | "runningOnce.idle"
121 | | "watching"
122 | | "watching.schedulers"
123 | | "watching.jobs"
124 | | "watching.jobs.emitSchema"
125 | | "watching.jobs.emitSchema.idle"
126 | | "watching.jobs.emitSchema.running"
127 | | "watching.jobs.codegen"
128 | | "watching.jobs.codegen.idle"
129 | | "watching.jobs.codegen.running"
130 | | "watching.jobs.autofix"
131 | | "watching.jobs.autofix.idle"
132 | | "watching.jobs.autofix.running"
133 | | {
134 | runningOnce?:
135 | | "running"
136 | | "idle"
137 | | {
138 | running?:
139 | | "emitSchema"
140 | | "emitPluginDocument"
141 | | "codegen"
142 | | "autofix"
143 | | {
144 | emitSchema?: "running" | "done";
145 | emitPluginDocument?: "running" | "done";
146 | codegen?: "running" | "done";
147 | autofix?: "running" | "done";
148 | };
149 | };
150 | watching?:
151 | | "schedulers"
152 | | "jobs"
153 | | {
154 | jobs?:
155 | | "emitSchema"
156 | | "codegen"
157 | | "autofix"
158 | | {
159 | emitSchema?: "idle" | "running";
160 | codegen?: "idle" | "running";
161 | autofix?: "idle" | "running";
162 | };
163 | };
164 | };
165 | tags: never;
166 | }
167 |
--------------------------------------------------------------------------------
/plugin/src/internal/pluginOptions.ts:
--------------------------------------------------------------------------------
1 | export type SupportedLanguage = 'typescript' | 'flow';
2 |
3 | export type PluginOptions = {
4 |
5 | /**
6 | * Prefer TypeScript by default, but you can switch to flow.
7 | *
8 | * @default 'typescript'
9 | */
10 | language?: SupportedLanguage,
11 |
12 | /**
13 | * Namespace is required to avoid conflict on generated types and other global declarations.
14 | *
15 | * Flow will use $ prefix as fallback.
16 | * e.g) `type GatsbyTypes$MySiteQuery = ...`
17 | *
18 | * @default 'GatsbyTypes'
19 | */
20 | namespace?: string,
21 |
22 | /**
23 | * Path to save generated typeDefs file.
24 | *
25 | * Strongly recommend to commit this file to your version control.
26 | *
27 | * @default 'src/__generated__/gatsby-types.d.ts'
28 | *
29 | * or (if you use flow)
30 | * @default 'src/__generated__/gatsby-types.js.flow'
31 | */
32 | outputPath?: string,
33 |
34 | /**
35 | * @deprecated The plugin does not generate useful types for the interface of GatsbyJS schema builder. Will be removed from v4.
36 | *
37 | * If you use [schema customization](https://www.gatsbyjs.org/docs/schema-customization/),
38 | * you might want types for custom resolvers.
39 | *
40 | * By default, the plugin only generate types for query data for your components.
41 | *
42 | * If set this true, the plugin also generate types for all possible resolver signatures.
43 | *
44 | * @default false
45 | *
46 | * @see https://graphql-code-generator.com/docs/plugins/typescript-resolvers
47 | * @see https://graphql-code-generator.com/docs/plugins/flow-resolvers
48 | */
49 | includeResolvers?: boolean,
50 |
51 | /**
52 | * @deprecated Renamed to `autofix`. Will be removed from v4.
53 | */
54 | autoFix?: boolean,
55 |
56 | /**
57 | * Enable auto-fixing `useStaticQuery()` & `` with generated type names.
58 | *
59 | * @default true
60 | */
61 | autofix?: boolean,
62 |
63 | /**
64 | * Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
65 | *
66 | * @example
67 | * ```js
68 | * {
69 | * scalars: {
70 | * EmailAddress: 'string',
71 | * DateTime: 'number',
72 | * URL: 'string',
73 | * },
74 | * }
75 | * ```
76 | *
77 | * @note You cannot override a few GraphQL/GatsbyJS internal scalars.
78 | * - `Boolean`,
79 | * - `Buffer`,
80 | * - `Date`,
81 | * - `Float`,
82 | * - `ID`,
83 | * - `Int`,
84 | * - `Internal`,
85 | * - `InternalInput`,
86 | * - `JSON`,
87 | * - `Json`,
88 | * - `Node`,
89 | * - `NodeInput`,
90 | * - `Query`,
91 | * - `String`,
92 | *
93 | * @see https://github.com/gatsbyjs/gatsby/blob/6b4b7f81ec/packages/gatsby/src/schema/print.js#L33-L48
94 | */
95 | scalars?: { [typename: string]: string },
96 |
97 | /**
98 | * Emit the Gatsby's schema into the filesystem.
99 | *
100 | * Set value as `true` and use default options.
101 | *
102 | * @see SchemaOutputOptions
103 | */
104 | emitSchema?: {
105 | [outputPath: string]: boolean | SchemaOutputOptions,
106 | },
107 |
108 | /**
109 | * @deprecated Renamed to `emitPluginDocument`. Will be removed from v4.
110 | *
111 | * Emit the GraphQL fragments declared by other plugins into the filesystem.
112 | */
113 | emitPluginDocuments?: {
114 | [outputPath: string]: boolean | DocumentOutputOptions,
115 | },
116 |
117 | /**
118 | * Emit the GraphQL fragments declared by other plugins into the filesystem.
119 | */
120 | emitPluginDocument?: {
121 | [outputPath: string]: boolean | DocumentOutputOptions,
122 | },
123 | };
124 |
125 | export type DocumentOutputOptions = {
126 | /**
127 | * Output file format.
128 | *
129 | * By default, the AST will be parsed and printed as GraphQL.
130 | * If set `json`, the AST will be emitted as JSON.
131 | *
132 | * @default 'graphql'
133 | */
134 | format: 'graphql' | 'json',
135 | };
136 |
137 | export type SchemaOutputOptions = {
138 | /**
139 | * Output file format.
140 | *
141 | * By default, the introspeciton result will be emitted as JSON
142 | * If set `sdl`, the AST will be parsed and printed, aka GraphQL SDL.
143 | *
144 | * @default 'sdl'
145 | */
146 | format: 'introspection' | 'sdl',
147 |
148 | /**
149 | * Use preceding comments as the description.
150 | *
151 | * @default true
152 | * @deprecated since GraphQL-JS v16
153 | */
154 | commentDescriptions?: boolean,
155 |
156 | /**
157 | * Omit the plugin metadata from the schema output
158 | *
159 | * @default true
160 | */
161 | omitPluginMetadata?: boolean,
162 | };
163 |
--------------------------------------------------------------------------------
/plugin/src/internal/reporter.ts:
--------------------------------------------------------------------------------
1 | interface TypegenActivity {
2 | start(): void;
3 | panic(arg: unknown): void;
4 | panicOnBuild(arg: unknown): void;
5 | end(): void;
6 | }
7 |
8 | interface TypegenProgressActivity extends TypegenActivity {
9 | tick(): void;
10 | done(): void;
11 | }
12 |
13 | export interface TypegenReporter {
14 | stripIndent(template: TemplateStringsArray, ...substitutions: unknown[]): string;
15 | log(message: string): void;
16 | info(message: string): void;
17 | warn(message: string): void;
18 | verbose(message: string): void;
19 | error(message: string, e?: Error | Error[]): void;
20 | panic(message: string, e: Error | Error[]): void;
21 | panicOnBuild(message: string, e: Error | Error[]): void;
22 | activity(message: string): TypegenActivity;
23 | progress(message: string, total: number): TypegenProgressActivity;
24 | }
25 |
--------------------------------------------------------------------------------
/plugin/src/internal/utils.ts:
--------------------------------------------------------------------------------
1 | import slugify from 'slugify';
2 | import _ from 'lodash';
3 | import type { GraphQLSchema, SourceLocation } from 'gatsby/graphql';
4 | import { GraphQLEnumType, lexicographicSortSchema } from 'gatsby/graphql';
5 | import type { IDefinitionMeta as _IDefinitionMeta } from 'gatsby/dist/redux/types';
6 | import {
7 | filterSchema,
8 | mapSchema,
9 | MapperKind,
10 | } from '@graphql-tools/utils';
11 |
12 | import type { SupportedLanguage } from './pluginOptions';
13 |
14 | export type OverrideProps = Omit & TNewProps;
15 |
16 | export type Brand = T & { __TAG__: TAG };
17 |
18 | export const formatLanguage = (lang: SupportedLanguage): string => (
19 | (lang === 'typescript') ? 'TypeScript' : 'Flow'
20 | );
21 |
22 | export type IDefinitionMeta = OverrideProps<_IDefinitionMeta, {
23 | templateLoc: SourceLocation,
24 |
25 | // Trust me, this is more accurate.
26 | printedAst: string | null,
27 |
28 | // https://github.com/gatsbyjs/gatsby/blob/d163724/packages/gatsby/src/query/file-parser.js#L429
29 | isConfigQuery: boolean,
30 |
31 | hash: number,
32 | }>;
33 |
34 | export function definitionIsEqual(a: IDefinitionMeta, b: IDefinitionMeta): boolean {
35 | return a.name === b.name && a.hash === b.hash;
36 | }
37 |
38 | export type FragmentDefinition = Brand<
39 | 'FragmentDefinition',
40 | OverrideProps
43 | >;
44 |
45 | export type QueryDefinition = Brand<
46 | 'QueryDefinition',
47 | OverrideProps
50 | >;
51 |
52 | export function isFragmentDefinition(def: IDefinitionMeta): def is FragmentDefinition {
53 | return def.isFragment;
54 | }
55 |
56 | export function isQueryDefinition(def: IDefinitionMeta): def is QueryDefinition {
57 | return !def.isFragment;
58 | }
59 |
60 | /**
61 | * return `true` if the given definition is assumed to be generated from unnamed query.
62 | */
63 | function guessIfUnnnamedQuery({ isStaticQuery, name, filePath }: IDefinitionMeta): boolean {
64 | const queryType = isStaticQuery ? 'static' : 'page';
65 | // See https://github.com/gatsbyjs/gatsby/blob/d163724/packages/gatsby/src/query/file-parser.js#L33
66 | const generatedQueryName = slugify(filePath, { replacement: ' ', lower: false });
67 | const pattern = _.camelCase(`${queryType}-${generatedQueryName}`);
68 | return name.startsWith(pattern);
69 | }
70 |
71 | /**
72 | * return `true` if the given definition is assumed to be included by third-party plugins or gatsby internal.
73 | */
74 | function guessIfThirdpartyDefinition({ filePath }: IDefinitionMeta): boolean {
75 | return /(node_modules|\.yarn|\.cache)/.test(filePath);
76 | }
77 |
78 | export function isThirdpartyFragment(def: IDefinitionMeta): def is FragmentDefinition {
79 | return isFragmentDefinition(def) && guessIfThirdpartyDefinition(def);
80 | }
81 |
82 | export function isTargetDefinition(def: IDefinitionMeta): boolean {
83 | return !(guessIfThirdpartyDefinition(def) || guessIfUnnnamedQuery(def));
84 | }
85 |
86 | // from https://github.com/gatsbyjs/gatsby/blob/6365768/packages/gatsby/src/schema/print.js#L33-L48
87 | export const gatsbyInternalScalars = [
88 | 'Boolean',
89 | 'Buffer',
90 | 'Date',
91 | 'Float',
92 | 'ID',
93 | 'Int',
94 | 'Internal',
95 | 'InternalInput',
96 | 'JSON',
97 | 'Json',
98 | 'Node',
99 | 'NodeInput',
100 | 'Query',
101 | 'String',
102 | ];
103 |
104 | const fieldFilterFromCoordinates = (
105 | (coords: string[]) =>
106 | (coord: { typeName?: string, fieldName?: string, argName?: string }) =>
107 | {
108 | const target = [coord.typeName, coord.fieldName, coord.argName]
109 | .filter(Boolean)
110 | .join('.');
111 | return !coords.includes(target);
112 | }
113 | );
114 |
115 | /**
116 | * Remove fields and args used only at development time from schema output.
117 | */
118 | export function filterDevOnlySchema(schema: GraphQLSchema): GraphQLSchema {
119 | return mapSchema(filterSchema({
120 | schema,
121 | fieldFilter: (typeName, fieldName) => (
122 | fieldFilterFromCoordinates([
123 | 'Site.host',
124 | 'Site.port',
125 | 'SiteFilterInput.host',
126 | 'SiteFilterInput.port',
127 | ])({ typeName, fieldName })
128 | ),
129 | argumentFilter: (typeName, fieldName, argName) => (
130 | fieldFilterFromCoordinates([
131 | 'Query.site.host',
132 | 'Query.site.port',
133 | ])({ typeName, fieldName, argName })
134 | ),
135 | }), {
136 | [MapperKind.ENUM_TYPE]: type => {
137 | if (type.name === 'SiteFieldsEnum') {
138 | const config = type.toConfig();
139 | delete config.values['host'];
140 | delete config.values['port'];
141 | return new GraphQLEnumType(config);
142 | }
143 | return undefined;
144 | },
145 | });
146 | }
147 |
148 | /**
149 | * Remove the plugin options schema.
150 | * Almost all users do not use it, but it unnecessarily increases the schema output size.
151 | */
152 | export function filterPluginSchema(schema: GraphQLSchema): GraphQLSchema {
153 | return mapSchema(filterSchema({
154 | schema,
155 | typeFilter: typeName => !typeName.startsWith('SitePlugin'),
156 | fieldFilter: (typeName, fieldName) => (
157 | fieldFilterFromCoordinates([
158 | 'Query.allSitePlugin',
159 | 'Query.sitePlugin',
160 | 'SitePage.pluginCreatorId',
161 | ])({ typeName, fieldName })
162 | ),
163 | inputObjectFieldFilter: (typeName, fieldName) => (
164 | fieldFilterFromCoordinates([
165 | 'SitePageFilterInput.pluginCreator',
166 | 'SitePageFilterInput.pluginCreatorId',
167 | ])({ typeName, fieldName })
168 | ),
169 | argumentFilter: (typeName, fieldName, argName) => (
170 | fieldFilterFromCoordinates([
171 | 'Query.sitePage.pluginCreator',
172 | 'Query.sitePage.pluginCreatorId',
173 | ])({ typeName, fieldName, argName })
174 | ),
175 | }), {
176 | [MapperKind.ENUM_TYPE]: type => {
177 | if (type.name === 'SitePageFieldsEnum') {
178 | const config = type.toConfig();
179 | for (const key of Object.keys(config.values)) {
180 | if (key.startsWith('pluginCreator')) {
181 | delete config.values[key];
182 | }
183 | }
184 | return new GraphQLEnumType(config);
185 | }
186 | return undefined;
187 | },
188 | });
189 | }
190 |
191 | export function stabilizeSchema(schema: GraphQLSchema): GraphQLSchema {
192 | return lexicographicSortSchema(filterDevOnlySchema(schema));
193 | }
194 |
195 | export function sortDefinitions(a: IDefinitionMeta, b: IDefinitionMeta): number {
196 | const aKey = a.name;
197 | const bKey = b.name;
198 | if (aKey < bKey) {
199 | return -1;
200 | }
201 | if (aKey > bKey) {
202 | return 1;
203 | }
204 | return 0;
205 | }
206 |
--------------------------------------------------------------------------------
/plugin/src/services/autofix.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 |
3 | import type { Config } from '../internal/config';
4 | import type { TypegenReporter } from '../internal/reporter';
5 | import { formatLanguage } from '../internal/utils';
6 |
7 | interface AutofixService {
8 | (files: string[]): Promise;
9 | }
10 |
11 | interface MakeAutofixService {
12 | (deps: {
13 | readFileContent: (path: string) => Promise,
14 | writeFileContent: (path: string, content: string) => Promise,
15 | language: Config['language'],
16 | namespace: Config['namespace'],
17 | reporter: TypegenReporter,
18 | }): AutofixService;
19 | }
20 |
21 | export { makeAutofixService };
22 |
23 | /**
24 | * (?useStaticQuery
25 | * (?<
26 | * (?\S*)
27 | * >)?
28 | * )
29 | * \([\s\S]*?
30 | * graphql
31 | * (?`\s*?
32 | * (?query
33 | * (?\S*)
34 | * [^{]?\{
35 | * )
36 | * [^`]*?
37 | * `)
38 | */
39 | const STATIC_QUERY_HOOK_REGEXP = /(?useStaticQuery(?<(?\S*)>)?)\([\s\S]*?graphql(?`\s*?(?query (?\S*)[^{]{)[^`]*?`)/g;
40 |
41 | /**
42 | * (?<
44 | * (?\S+)
45 | * >)?
46 | * )
47 | * [\s\S]+?
48 | * query={
49 | * [\s\S]*?
50 | * graphql
51 | * (?`\s*?
52 | * (?query
53 | * (?\S*)
54 | * [^{]?\{
55 | * )
56 | * [^`]*?
57 | * `)
58 | */
59 | const STATIC_QUERY_COMPONENT_REGEXP = /(?<(?\S+)>)?)[\s\S]+?query={[\s\S]*?graphql(?`\s*?(?query (?\S*)[^{]?\{)[^`]*`)/g;
60 |
61 | interface FixCodeFn {
62 | (args: {
63 | code: string,
64 | namespace: string,
65 | }): string;
66 | }
67 |
68 | const fixTypeScript: FixCodeFn = ({ code, namespace }) => {
69 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
70 | return code
71 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
72 | .replace(STATIC_QUERY_HOOK_REGEXP, (substring: string, ...args: any[]) => {
73 | const { length: l, [l - 1]: groups } = args;
74 | return substring.replace(
75 | groups['CallExpressionName'],
76 | // eslint-disable-next-line
77 | `useStaticQuery<${namespace}.${groups['QueryName']}Query>`,
78 | );
79 | })
80 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
81 | .replace(STATIC_QUERY_COMPONENT_REGEXP, (substring: string, ...args: any[]) => {
82 | const { length: l, [l - 1]: groups } = args;
83 | return substring.replace(
84 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
85 | groups['JsxTagOpening'],
86 | // eslint-disable-next-line
87 | ``,
88 | );
89 | });
90 | };
91 |
92 | const fixFlow: FixCodeFn = ({ code, namespace }) => {
93 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
94 | return code
95 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
96 | .replace(STATIC_QUERY_HOOK_REGEXP, (substring: string, ...args: any[]) => {
97 | const { length: l, [l - 1]: groups } = args;
98 | return substring.replace(
99 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
100 | groups['CallExpressionName'],
101 | // eslint-disable-next-line
102 | `useStaticQuery<${namespace}$${groups['QueryName']}Query>`,
103 | );
104 | })
105 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
106 | .replace(STATIC_QUERY_COMPONENT_REGEXP, (substring: string, ...args: any[]) => {
107 | const { length: l, [l - 1]: groups } = args;
108 | return substring.replace(
109 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
110 | groups['JsxTagOpening'],
111 | // eslint-disable-next-line
112 | ``,
113 | );
114 | });
115 | };
116 |
117 | const lookupFirstComment = (code: string) => {
118 | const result = /(\/\/(.*)|\/\*([\s\S]*)\*\/)/.exec(code);
119 | return result?.[0];
120 | };
121 |
122 | const hasFlowComment = (code: string) => {
123 | const firstComment = lookupFirstComment(code);
124 | return Boolean(firstComment);
125 | };
126 |
127 | const isJavaScriptFile = (file: string): boolean => {
128 | const ext = path.extname(file);
129 | return /jsx?/.test(ext);
130 | };
131 |
132 | const isTypeScriptFile = (file: string): boolean => {
133 | const ext = path.extname(file);
134 | return /tsx?/.test(ext);
135 | };
136 |
137 | interface AutofixFn {
138 | (args: {
139 | namespace: string,
140 | filePath: string,
141 | readFileContent: (path: string) => Promise,
142 | writeFileContent: (path: string, content: string) => Promise,
143 | }): Promise;
144 | }
145 |
146 | const autofixTypeScriptFile: AutofixFn = async ({
147 | namespace,
148 | filePath,
149 | readFileContent,
150 | writeFileContent,
151 | }) => {
152 | const code = await readFileContent(filePath);
153 | const fixed = fixTypeScript({ code, namespace });
154 | if (code !== fixed) {
155 | await writeFileContent(filePath, fixed);
156 | return filePath;
157 | }
158 | return null;
159 | };
160 |
161 | const autofixFlowFile: AutofixFn = async ({
162 | namespace,
163 | filePath,
164 | readFileContent,
165 | writeFileContent,
166 | }) => {
167 | const code = await readFileContent(filePath);
168 | if (!hasFlowComment(code)) {
169 | return null;
170 | }
171 |
172 | const fixed = fixFlow({ code, namespace });
173 | if (code !== fixed) {
174 | await writeFileContent(filePath, fixed);
175 | return filePath;
176 | }
177 | return null;
178 | };
179 |
180 | const makeAutofixService: MakeAutofixService = ({
181 | namespace,
182 | language,
183 | readFileContent,
184 | writeFileContent,
185 | reporter,
186 | }) => async files => {
187 | const progress = reporter.progress(
188 | `autofix ${files.length} files (language: ${formatLanguage(language)})`,
189 | files.length,
190 | );
191 |
192 | if (language === 'typescript') {
193 | await Promise.allSettled(
194 | files
195 | .filter(isTypeScriptFile)
196 | .map(async filePath => {
197 | try {
198 | await autofixTypeScriptFile({
199 | filePath,
200 | namespace,
201 | readFileContent,
202 | writeFileContent,
203 | });
204 | } catch (e) {
205 | reporter.error(`failed to autofix ${filePath}`, e as Error);
206 | } finally {
207 | progress.tick();
208 | }
209 | }),
210 | );
211 | } else {
212 | await Promise.allSettled(
213 | files
214 | .filter(isJavaScriptFile)
215 | .map(async filePath => {
216 | try {
217 | await autofixFlowFile({
218 | filePath,
219 | namespace,
220 | readFileContent,
221 | writeFileContent,
222 | });
223 | } catch (e) {
224 | reporter.error(`failed to autofix ${filePath}`, e as Error);
225 | } finally {
226 | progress.tick();
227 | }
228 | }),
229 | );
230 | }
231 |
232 | progress.done();
233 | };
234 |
--------------------------------------------------------------------------------
/plugin/src/services/codegen.ts:
--------------------------------------------------------------------------------
1 | import { GraphQLSchema, DocumentNode } from 'gatsby/graphql';
2 | import { codegen } from '@graphql-codegen/core';
3 | import type { Types } from '@graphql-codegen/plugin-helpers';
4 | import type { TypeScriptPluginConfig } from '@graphql-codegen/typescript/config';
5 | import type { TypeScriptDocumentsPluginConfig } from '@graphql-codegen/typescript-operations/config';
6 | import type { TypeScriptResolversPluginConfig } from '@graphql-codegen/typescript-resolvers/config';
7 | import type { FlowPluginConfig } from '@graphql-codegen/flow/config';
8 | import type { FlowDocumentsPluginConfig } from '@graphql-codegen/flow-operations/config';
9 | import type { RawResolversConfig } from '@graphql-codegen/visitor-plugin-common';
10 |
11 | type FlowResolversPluginConfig = RawResolversConfig;
12 |
13 | import type { Config } from '../internal/config';
14 | import type { TypegenReporter } from '../internal/reporter';
15 | import { formatLanguage } from '../internal/utils';
16 |
17 | type Source = {
18 | document: DocumentNode,
19 | hash?: string,
20 | };
21 |
22 | interface CodegenService {
23 | (props: {
24 | schema: GraphQLSchema,
25 | documents: Source[],
26 | }): Promise;
27 | }
28 |
29 | interface MakeCodegenService {
30 | (deps: {
31 | outputPath: Config['outputPath'],
32 | namespace: Config['namespace'],
33 | language: Config['language'],
34 | includeResolvers: Config['includeResolvers'],
35 | customScalars: Config['scalars'],
36 | reporter: TypegenReporter,
37 | writeFileContent: (path: string, content: string) => Promise,
38 | }): CodegenService;
39 | }
40 |
41 | export { makeCodegenService };
42 |
43 | // Preset configurations to ensure compatibility with Gatsby.
44 | const DEFAULT_CONFIG = Object.freeze({
45 | namingConvention: {
46 | typeNames: 'keep',
47 | enumValues: 'keep',
48 | transformUnderscore: false,
49 | },
50 | addUnderscoreToArgsType: true,
51 | skipTypename: true,
52 | flattenGeneratedTypes: true,
53 | flattenGeneratedTypesIncludeFragments: true,
54 | });
55 |
56 | const DEFAULT_TYPESCRIPT_SCALARS = Object.freeze({
57 | // A date string, such as 2007-12-03, compliant with the ISO 8601 standard for
58 | // representation of dates and times using the Gregorian calendar.
59 | Date: 'string',
60 |
61 | // The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
62 | // Note: This will never be used since this is reserved by GatsbyJS internal
63 | JSON: 'any',
64 |
65 | // https://github.com/gatsbyjs/gatsby/pull/35683
66 | GatsbyImageData: 'import(\'gatsby-plugin-image\').IGatsbyImageData',
67 | });
68 |
69 | const DEFAULT_TYPESCRIPT_CONFIG: Readonly = (
70 | Object.freeze({
71 | avoidOptionals: true,
72 | immutableTypes: true,
73 | maybeValue: 'T | null',
74 | noExport: true,
75 | enumsAsTypes: true,
76 | scalars: DEFAULT_TYPESCRIPT_SCALARS,
77 | useTypeImports: true,
78 | })
79 | );
80 |
81 | const DEFAULT_TYPESCRIPT_OPERATIONS_CONFIG: Readonly = (
82 | Object.freeze({
83 | ...DEFAULT_TYPESCRIPT_CONFIG,
84 | exportFragmentSpreadSubTypes: true,
85 | })
86 | );
87 |
88 | const DEFAULT_TYPESCRIPT_RESOLVERS_CONFIG: TypeScriptResolversPluginConfig = (
89 | Object.freeze({
90 | ...DEFAULT_TYPESCRIPT_CONFIG,
91 | contextType: 'gatsby-plugin-typegen/types#GatsbyResolverContext',
92 | })
93 | );
94 |
95 | const DEFAULT_FLOW_SCALARS = Object.freeze({
96 | // A date string, such as 2007-12-03, compliant with the ISO 8601 standard for
97 | // representation of dates and times using the Gregorian calendar.
98 | Date: 'string',
99 |
100 | // The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
101 | // Note: This will never be used since this is reserved by GatsbyJS internal
102 | JSON: 'any',
103 |
104 | // FIXME: support library type for this
105 | GatsbyImageData: 'any',
106 | });
107 |
108 | const DEFAULT_FLOW_CONFIG: Readonly = (
109 | Object.freeze({
110 | useFlowExactObjects: true,
111 | useFlowReadOnlyTypes: true,
112 | scalars: DEFAULT_FLOW_SCALARS,
113 | })
114 | );
115 |
116 | const DEFAULT_FLOW_OPERATIONS_CONFIG: Readonly = (
117 | Object.freeze({
118 | ...DEFAULT_FLOW_CONFIG,
119 | exportFragmentSpreadSubTypes: true,
120 | })
121 | );
122 |
123 | const DEFAULT_FLOW_RESOLVERS_CONFIG: Readonly = (
124 | Object.freeze({
125 | ...DEFAULT_FLOW_CONFIG,
126 | contextType: 'gatsby-plugin-typegen/types.flow#type GatsbyResolverContext',
127 | })
128 | );
129 |
130 | const makeCodegenService: MakeCodegenService = ({
131 | outputPath,
132 | language,
133 | namespace,
134 | includeResolvers,
135 | customScalars,
136 | reporter,
137 | writeFileContent,
138 | }) => {
139 | const pluginConfig: Pick = {
140 | pluginMap: {
141 | add: require('@graphql-codegen/add'),
142 | },
143 | plugins: [
144 | {
145 | add: {
146 | placement: 'prepend',
147 | content: '/* eslint-disable */\n',
148 | },
149 | },
150 | ],
151 | };
152 |
153 | switch (language) {
154 | case 'typescript': {
155 | pluginConfig.pluginMap = {
156 | ...pluginConfig.pluginMap,
157 | typescript: require('@graphql-codegen/typescript'),
158 | typescriptOperations: require('@graphql-codegen/typescript-operations'),
159 | };
160 |
161 | pluginConfig.plugins.push({
162 | add: {
163 | placement: 'prepend',
164 | content: `\ndeclare namespace ${namespace} {\n`,
165 | },
166 | });
167 | pluginConfig.plugins.push({
168 | typescript: DEFAULT_TYPESCRIPT_CONFIG,
169 | });
170 | pluginConfig.plugins.push({
171 | typescriptOperations: DEFAULT_TYPESCRIPT_OPERATIONS_CONFIG,
172 | });
173 | pluginConfig.plugins.push({
174 | add: {
175 | placement: 'append',
176 | content: '\n}\n',
177 | },
178 | });
179 |
180 | if (includeResolvers) {
181 | pluginConfig.pluginMap = {
182 | ...pluginConfig.pluginMap,
183 | typescriptResolvers: require('@graphql-codegen/typescript-resolvers'),
184 | };
185 | pluginConfig.plugins.push({
186 | typescriptResolvers: DEFAULT_TYPESCRIPT_RESOLVERS_CONFIG,
187 | });
188 | }
189 |
190 | break;
191 | }
192 |
193 | case 'flow': {
194 | pluginConfig.pluginMap = {
195 | ...pluginConfig.pluginMap,
196 | flow: require('@graphql-codegen/flow'),
197 | flowOperations: require('@graphql-codegen/flow-operations'),
198 | };
199 |
200 | pluginConfig.plugins.push({
201 | flow: {
202 | ...DEFAULT_FLOW_CONFIG,
203 | typesPrefix: `${namespace}$`,
204 | },
205 | });
206 | pluginConfig.plugins.push({
207 | flowOperations: {
208 | ...DEFAULT_FLOW_OPERATIONS_CONFIG,
209 | typesPrefix: `${namespace}$`,
210 | },
211 | });
212 |
213 | if (includeResolvers) {
214 | pluginConfig.pluginMap = {
215 | ...pluginConfig.pluginMap,
216 | flowResolvers: require('@graphql-codegen/flow-resolvers'),
217 | };
218 | pluginConfig.plugins.push({
219 | flowResolvers: {
220 | ...DEFAULT_FLOW_RESOLVERS_CONFIG,
221 | typesPrefix: `${namespace}$`,
222 | },
223 | });
224 | }
225 |
226 | break;
227 | }
228 | }
229 |
230 | return async ({
231 | schema,
232 | documents,
233 | }) => {
234 | const codegenOptions: Omit = {
235 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment
236 | // @ts-ignore for inaccurate type definitions
237 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
238 | schema: undefined as any,
239 | schemaAst: schema,
240 | documents,
241 | filename: outputPath,
242 | config: {
243 | ...DEFAULT_CONFIG,
244 | scalars: customScalars,
245 | },
246 | };
247 |
248 | const activity = reporter.activity(reporter.stripIndent`
249 | generate type definitions to ${outputPath}. (language: ${formatLanguage(language)})
250 | `);
251 | activity.start();
252 |
253 | try {
254 | let result = await codegen({
255 | ...pluginConfig,
256 | ...codegenOptions,
257 | });
258 |
259 | // FIXME: find more accurate way
260 | if (language === 'flow') {
261 | const FLOW_FILE_TOP = '/* @flow */\n\n';
262 | const FLOW_FILE_TOP_REGEXP = /\/\*\s*@flow\s*\*\/\s*/;
263 | result = result.replace(FLOW_FILE_TOP_REGEXP, FLOW_FILE_TOP + 'opaque type never = mixed;\n\n');
264 |
265 | const TYPEDEF_EXPORT_NODE_REGEXP = /export type ((.*)(\{\|?|;)($|\s))/g;
266 | result = result.replace(TYPEDEF_EXPORT_NODE_REGEXP, 'declare type $1');
267 | }
268 |
269 | await writeFileContent(outputPath, result);
270 | } catch (e) {
271 | activity.panic(e);
272 | } finally {
273 | activity.end();
274 | }
275 | };
276 | };
277 |
--------------------------------------------------------------------------------
/plugin/src/services/emitPluginDocument.ts:
--------------------------------------------------------------------------------
1 | import type { DocumentNode } from 'gatsby/graphql';
2 | import { Kind } from 'gatsby/graphql';
3 |
4 | import type { Config } from '../internal/config';
5 | import type { TypegenReporter } from '../internal/reporter';
6 | import type { IDefinitionMeta } from '../internal/utils';
7 |
8 | interface EmitPluginDocumentService {
9 | (definitions: IDefinitionMeta[]): Promise;
10 | }
11 |
12 | interface MakeEmitPluginDocumentService {
13 | (deps: {
14 | configMap: Config['emitPluginDocument'],
15 | reporter: TypegenReporter,
16 | writeFileContent: (path: string, content: string) => Promise,
17 | }): EmitPluginDocumentService;
18 | }
19 |
20 | export const makeEmitPluginDocumentService: MakeEmitPluginDocumentService = ({
21 | configMap,
22 | reporter,
23 | writeFileContent,
24 | }) => {
25 | return async definitions => {
26 | const entries = Object.entries(configMap);
27 | if (entries.length === 0) {
28 | return;
29 | }
30 |
31 | definitions = definitions.filter(def => def.printedAst);
32 |
33 | if (definitions.length === 0) {
34 | return;
35 | }
36 |
37 | await Promise.all(
38 | entries.map(async ([filePath, config]) => {
39 | const activity = reporter.activity(`emit 3rd-party documents into ${filePath}`);
40 | activity.start();
41 |
42 | try {
43 | switch (config.format) {
44 | case 'graphql': {
45 | const printedDocument = definitions
46 | .map(def => def.printedAst || '')
47 | .filter(Boolean)
48 | .join('\n\n');
49 | await writeFileContent(filePath, printedDocument);
50 | break;
51 | }
52 | case 'json': {
53 | const document: DocumentNode = {
54 | kind: Kind.DOCUMENT,
55 | definitions: definitions.map(meta => meta.def),
56 | };
57 | await writeFileContent(filePath, JSON.stringify(document, null, 2));
58 | break;
59 | }
60 | }
61 | } catch (e) {
62 | activity.panic(e);
63 | } finally {
64 | activity.end();
65 | }
66 | }),
67 | );
68 | };
69 | };
70 |
--------------------------------------------------------------------------------
/plugin/src/services/emitSchema.ts:
--------------------------------------------------------------------------------
1 | import type { GraphQLSchema } from 'gatsby/graphql';
2 | import {
3 | printSchema,
4 | introspectionFromSchema,
5 | } from 'gatsby/graphql';
6 |
7 | import type { Config } from '../internal/config';
8 | import type { TypegenReporter } from '../internal/reporter';
9 | import { filterPluginSchema } from '../internal/utils';
10 |
11 | interface EmitSchemaService {
12 | (schema: GraphQLSchema): Promise;
13 | }
14 |
15 | interface MakeEmitSchemaService {
16 | (deps: {
17 | configMap: Config['emitSchema'],
18 | reporter: TypegenReporter,
19 | writeFileContent: (path: string, content: string) => Promise,
20 | }): EmitSchemaService;
21 | }
22 |
23 | export const makeEmitSchemaService: MakeEmitSchemaService = ({
24 | configMap,
25 | reporter,
26 | writeFileContent,
27 | }) => {
28 | return async schema => {
29 | const entries = Object.entries(configMap);
30 | if (entries.length === 0) {
31 | return;
32 | }
33 |
34 | await Promise.all(
35 | entries.map(async ([filePath, config]) => {
36 | const activity = reporter.activity(`emit schema into ${filePath}`);
37 | activity.start();
38 |
39 | const {
40 | format,
41 | omitPluginMetadata,
42 | } = config;
43 |
44 | try {
45 | let outputSchema = schema;
46 | if (omitPluginMetadata) {
47 | outputSchema = filterPluginSchema(outputSchema);
48 | }
49 | switch (format) {
50 | case 'sdl': {
51 | await writeFileContent(
52 | filePath,
53 | printSchema(outputSchema),
54 | );
55 | break;
56 | }
57 | case 'introspection': {
58 | await writeFileContent(
59 | filePath,
60 | JSON.stringify(
61 | introspectionFromSchema(outputSchema, {
62 | descriptions: true,
63 | schemaDescription: true,
64 | directiveIsRepeatable: true,
65 | inputValueDeprecation: true,
66 | specifiedByUrl: true,
67 | }),
68 | null,
69 | 2,
70 | ),
71 | );
72 | break;
73 | }
74 | }
75 | } catch (e) {
76 | activity.panic(e);
77 | } finally {
78 | activity.end();
79 | }
80 | }),
81 | );
82 | };
83 | };
84 |
--------------------------------------------------------------------------------
/plugin/src/types.flow.js:
--------------------------------------------------------------------------------
1 | /* @flow */
2 |
3 | export type PluginOptions = {
4 |
5 | /**
6 | * Prefer TypeScript by default, but you can switch to flow.
7 | *
8 | * @default 'typescript'
9 | */
10 | language?: 'typescript' | 'flow',
11 |
12 | /**
13 | * Namespace is required to avoid conflict on generated types and other global declarations.
14 | *
15 | * Flow will use $ prefix as fallback.
16 | * e.g) `type GatsbyTypes$MySiteQuery = ...`
17 | *
18 | * @default 'GatsbyTypes'
19 | */
20 | namespace?: string,
21 |
22 | /**
23 | * Path to save generated typeDefs file.
24 | *
25 | * Strongly recommend to commit this file to your version control.
26 | *
27 | * @default 'src/__generated__/gatsby-types.ts'
28 | *
29 | * or (if you use flow)
30 | * @default 'src/__generated__/gatsby-types.js'
31 | */
32 | outputPath?: string,
33 |
34 | /**
35 | * @deprecated The plugin does not generate useful types for the interface of GatsbyJS schema builder. Will be removed from v4.
36 | *
37 | * If you use [schema customization](https://www.gatsbyjs.org/docs/schema-customization/),
38 | * you might want types for custom resolvers.
39 | *
40 | * By default, the plugin only generate types for query data for your components.
41 | *
42 | * If set this true, the plugin also generate types for all possible resolver signatures.
43 | *
44 | * @default false
45 | *
46 | * @see https://graphql-code-generator.com/docs/plugins/typescript-resolvers
47 | * @see https://graphql-code-generator.com/docs/plugins/flow-resolvers
48 | */
49 | includeResolvers?: boolean,
50 |
51 | /**
52 | * @deprecated Renamed to `autofix`. Will be removed from v4.
53 | */
54 | autoFix?: boolean,
55 |
56 | /**
57 | * Enable auto-fixing `useStaticQuery()` & `` with generated type names.
58 | *
59 | * @default true
60 | */
61 | autofix?: boolean,
62 |
63 | /**
64 | * Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
65 | *
66 | * @example
67 | * ```js
68 | * {
69 | * scalars: {
70 | * EmailAddress: 'string',
71 | * DateTime: 'number',
72 | * URL: 'string',
73 | * },
74 | * }
75 | * ```
76 | *
77 | * @note You cannot override a few GraphQL/GatsbyJS internal scalars.
78 | * - `Boolean`,
79 | * - `Buffer`,
80 | * - `Date`,
81 | * - `Float`,
82 | * - `ID`,
83 | * - `Int`,
84 | * - `Internal`,
85 | * - `InternalInput`,
86 | * - `JSON`,
87 | * - `Json`,
88 | * - `Node`,
89 | * - `NodeInput`,
90 | * - `Query`,
91 | * - `String`,
92 | *
93 | * @see https://github.com/gatsbyjs/gatsby/blob/6b4b7f81ec/packages/gatsby/src/schema/print.js#L33-L48
94 | */
95 | scalars?: { [typename: string]: string },
96 |
97 | /**
98 | * Emit the Gatsby's schema into the filesystem.
99 | *
100 | * Set value as `true` and use default options.
101 | *
102 | * @see SchemaOutputOptions
103 | */
104 | emitSchema?: {
105 | [outputPath: string]: boolean | SchemaOutputOptions,
106 | },
107 |
108 | /**
109 | * @deprecated Renamed to `emitPluginDocument`. Will be removed from v4.
110 | *
111 | * Emit the GraphQL fragments declared by other plugins into the filesystem.
112 | */
113 | emitPluginDocuments?: {
114 | [outputPath: string]: boolean | DocumentOutputOptions,
115 | },
116 |
117 | /**
118 | * Emit the GraphQL fragments declared by other plugins into the filesystem.
119 | */
120 | emitPluginDocument?: {
121 | [outputPath: string]: boolean | DocumentOutputOptions,
122 | },
123 | };
124 |
125 | export type DocumentOutputOptions = {
126 | /**
127 | * Output file format.
128 | *
129 | * By default, the AST will be parsed and printed as GraphQL.
130 | * If set `json`, the AST will be emitted as JSON.
131 | *
132 | * @default 'graphql'
133 | */
134 | format: 'graphql' | 'json',
135 | };
136 |
137 | export type SchemaOutputOptions = {
138 | /**
139 | * Output file format.
140 | *
141 | * By default, the introspection result is emitted as JSON.
142 | * If set `sdl`, introspection will be parsed and printed to GraphQL SDL.
143 | *
144 | * @default 'introspection'
145 | */
146 | format: 'introspection' | 'sdl',
147 |
148 | /**
149 | * Include comment descriptions
150 | *
151 | * @default true
152 | */
153 | commentDescriptions?: boolean,
154 | };
155 |
156 | /**
157 | * Copy of the `IGatsbyResolverContext`
158 | * @see https://github.com/gatsbyjs/gatsby/blob/f10eb58/packages/gatsby/src/schema/type-definitions.ts
159 | *
160 | * @todo Provide more accurate type definition.
161 | */
162 | export type GatsbyResolverContext = {
163 | nodeModel: any,
164 | };
165 |
--------------------------------------------------------------------------------
/plugin/src/types.ts:
--------------------------------------------------------------------------------
1 | export type { PluginOptions } from './internal/pluginOptions';
2 |
3 | /**
4 | * Copy of the `IGatsbyResolverContext`
5 | * @see https://github.com/gatsbyjs/gatsby/blob/f10eb58/packages/gatsby/src/schema/type-definitions.ts
6 | *
7 | * @todo Provide more accurate type definition.
8 | */
9 | export interface GatsbyResolverContext {
10 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
11 | nodeModel: any;
12 | }
13 |
--------------------------------------------------------------------------------
/plugin/src/typing/gatsby.d.ts:
--------------------------------------------------------------------------------
1 | declare module 'gatsby/graphql' {
2 | export * from 'graphql';
3 | }
4 |
--------------------------------------------------------------------------------
/plugin/src/utils.ts:
--------------------------------------------------------------------------------
1 | import { dirname } from 'path';
2 | import * as fs from 'fs';
3 |
4 | export const readFileContent = async (path: string): Promise => {
5 | return fs.promises.readFile(path, 'utf-8');
6 | };
7 |
8 | export const writeFileContent = async (path: string, content: string): Promise => {
9 | await fs.promises.mkdir(dirname(path), { recursive: true });
10 | await fs.promises.writeFile(path, content, 'utf-8');
11 | };
12 |
13 | export const isCloudBuild = (env: NodeJS.ProcessEnv) => {
14 | return env.NODE_ENV === 'production' && env.CI === 'true';
15 | };
16 |
--------------------------------------------------------------------------------
/plugin/test/reporter.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-console */
2 |
3 | import { stripIndent } from 'common-tags';
4 |
5 | import type { TypegenReporter } from '../src/internal/reporter';
6 |
7 | export const testReporter: TypegenReporter = {
8 | stripIndent,
9 | log: console.log,
10 | info: console.info,
11 | warn: console.warn,
12 | verbose: console.debug,
13 | error: console.error,
14 | panic(msg, e) {
15 | console.error(msg);
16 | throw e;
17 | },
18 | panicOnBuild(msg, e) {
19 | console.error(msg);
20 | throw e;
21 | },
22 | activity(msg) {
23 | return {
24 | start: () => {
25 | console.group(msg);
26 | },
27 | end: () => {
28 | console.groupEnd();
29 | },
30 | panic(e) {
31 | console.error(msg);
32 | throw e;
33 | },
34 | panicOnBuild(e) {
35 | console.error(msg);
36 | throw e;
37 | },
38 | };
39 | },
40 | progress(msg, total) {
41 | let count = 0;
42 | return {
43 | start: () => {
44 | console.group(msg);
45 | },
46 | end: () => {
47 | console.groupEnd();
48 | },
49 | tick: () => {
50 | console.log(`tick (${count++}/${total})`);
51 | },
52 | done: () => {
53 | console.groupEnd();
54 | },
55 | panic(e) {
56 | console.error(msg);
57 | throw e;
58 | },
59 | panicOnBuild(e) {
60 | console.error(msg);
61 | throw e;
62 | },
63 | };
64 | },
65 | };
66 |
--------------------------------------------------------------------------------
/plugin/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/tsconfig",
3 | "extends": "../tsconfig.json",
4 | "compilerOptions": {
5 | "rootDir": "src",
6 | "declaration": true,
7 | "declarationDir": "."
8 | },
9 | "include": [
10 | "src"
11 | ],
12 | "exclude": [
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/plugin/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "include": [
4 | "src"
5 | ],
6 | "exclude": [
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ESNext",
4 | "module": "ESNext",
5 | "moduleResolution": "Node",
6 | "strict": true,
7 | "allowSyntheticDefaultImports": true,
8 | "esModuleInterop": true,
9 | "downlevelIteration": true,
10 | "skipLibCheck": true,
11 | "jsx": "preserve"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------