You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add `node_modules/apollo-typed-documents/lib/reactHooks.d.ts` in `include` to override the typings for `@apollo/react-hooks`, so that types can be inferred from typed documents.
<!-- The below code snippet is automatically added from ./examples/docs/src/AuthorList.js -->
133
138
```js
134
139
import { useMutation, useQuery } from "@apollo/react-hooks";
135
140
import React from "react";
136
141
137
-
import authorsQuery from "./documents/authors.graphql";
138
-
import createAuthorMutation from "./documents/createAuthor.graphql";
142
+
import authorsQuery from "./authors.graphql";
143
+
import createAuthorMutation from "./createAuthor.graphql";
139
144
140
145
const AuthorList = () => {
141
146
// Type of `data` is inferred (AuthorsQuery)
@@ -169,24 +174,26 @@ export default AuthorList;
169
174
170
175
### Notes for `create-react-app` users
171
176
172
-
`create-react-app`uses`graphql.macro` for loading of`.graphql` files (https://create-react-app.dev/docs/loading-graphql-files/).
177
+
`create-react-app`supports`graphql.macro` for loading `.graphql` files (https://create-react-app.dev/docs/loading-graphql-files/).
173
178
174
-
Because the `codegenTypedDocuments` plugin generates ambient module declarations for those `.graphql` files, they must be imported as regular modules (`commonjs`), otherwise TypeScript can't know its type.
179
+
The `codegenTypedDocuments` plugin generates ambient module declarations for `.graphql` files, which means that `.graphql` files must be imported as regular modules (`import` syntax) so that TypeScript knows about the types.
175
180
176
-
You can use the babel plugin `babel-plugin-import-graphql`, but then you need to either `eject` or use `react-app-rewired`/`customize-cra`.
181
+
You can use the babel plugin `babel-plugin-import-graphql` (https://github.com/detrohutt/babel-plugin-import-graphql), but then you need to use `react-app-rewired` (https://github.com/timarney/react-app-rewired/) and `customize-cra` (https://github.com/arackaf/customize-cra) so that you can define custom babel plugins.
177
182
178
-
Follow install instructions for `react-app-rewired`/`customize-cra`:
Also, if you have a `create-react-app` project without TypeScript, the `tsconfig.json` must not be placed in your app root folder, because `create-react-app` uses this file to detect a TypeScript project: [reference](https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js#L49).
205
+
`package.json`
206
+
207
+
```js
208
+
"scripts": {
209
+
"start":"react-app-rewired start",
210
+
"build":"react-app-rewired build",
211
+
"test":"react-app-rewired test",
212
+
...
213
+
}
214
+
```
199
215
200
-
All `.ts`/`.d.ts` files must be outside of your `src` folder: [reference](https://github.com/facebook/create-react-app/blob/v3.4.1/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js#L50)
216
+
If you have a TypeScript app, you need to override the `@apollo/react-hooks` types in `tsconfig.json`:
201
217
202
-
A solution is to put the `tsconfig.json` in the parent folder:
If you don't have a TypeScript app (you just want TypeScript support within your IDE) you can't create a `tsconfig.json` in your app folder, because `create-react-app` uses that file to detect if this is a TypeScript project.
217
230
231
+
Instead, you have to create the `tsconfig.json` in your `src` folder:
0 commit comments