Skip to content

Commit ddd41df

Browse files
committed
Implement cra example
1 parent fdfb3e9 commit ddd41df

27 files changed

+432
-303
lines changed

.eslintignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
examples/docs/apolloMock.js
2-
examples/docs/codegenTypedDocuments.d.ts
3-
examples/docs/codegenTypes.ts
1+
examples/**/apolloMock.js
2+
examples/**/codegenTypedDocuments.d.ts
3+
examples/**/codegenTypes.ts

.prettierignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
examples/docs/apolloMock.js
2-
examples/docs/codegenTypedDocuments.d.ts
3-
examples/docs/codegenTypes.ts
1+
examples/**/apolloMock.js
2+
examples/**/codegenTypedDocuments.d.ts
3+
examples/**/codegenTypes.ts

examples/cra/.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["react-app"],
3+
"plugins": ["babel-plugin-import-graphql"]
4+
}

examples/cra/codegen.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
schema: ../docs/schema.graphql
2+
documents: src/**/*.graphql
3+
generates:
4+
./codegenTypedDocuments.d.ts:
5+
plugins:
6+
- apollo-typed-documents/lib/codegenTypedDocuments
7+
config:
8+
typesModule: "@codegen-types"
9+
./codegenTypes.ts:
10+
plugins:
11+
- typescript
12+
- typescript-operations
13+
./src/apolloMock.js:
14+
plugins:
15+
- add: "/* eslint-disable */"
16+
- apollo-typed-documents/lib/codegenApolloMock
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
declare module "*/authors.graphql" {
2+
import { TypedDocumentNode } from "apollo-typed-documents";
3+
import { AuthorsQuery, AuthorsQueryVariables } from "@codegen-types";
4+
export const authors: TypedDocumentNode<AuthorsQueryVariables, AuthorsQuery>;
5+
export default authors;
6+
}
7+
8+
declare module "*/createAuthor.graphql" {
9+
import { TypedDocumentNode } from "apollo-typed-documents";
10+
import { CreateAuthorMutation, CreateAuthorMutationVariables } from "@codegen-types";
11+
export const createAuthor: TypedDocumentNode<CreateAuthorMutationVariables, CreateAuthorMutation>;
12+
export default createAuthor;
13+
}

examples/cra/codegenTypes.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
export type Maybe<T> = T | null;
2+
/** All built-in and custom scalars, mapped to their actual values */
3+
export type Scalars = {
4+
ID: string;
5+
String: string;
6+
Boolean: boolean;
7+
Int: number;
8+
Float: number;
9+
};
10+
11+
export type Author = {
12+
__typename?: 'Author';
13+
id: Scalars['ID'];
14+
name: Scalars['String'];
15+
description?: Maybe<Scalars['String']>;
16+
books: Array<Book>;
17+
};
18+
19+
export type AuthorInput = {
20+
name: Scalars['String'];
21+
description?: Maybe<Scalars['String']>;
22+
books: Array<BookInput>;
23+
};
24+
25+
export type Book = {
26+
__typename?: 'Book';
27+
id: Scalars['ID'];
28+
title: Scalars['String'];
29+
};
30+
31+
export type BookInput = {
32+
title: Scalars['String'];
33+
};
34+
35+
export type Mutation = {
36+
__typename?: 'Mutation';
37+
createAuthor: Author;
38+
};
39+
40+
41+
export type MutationCreateAuthorArgs = {
42+
input: AuthorInput;
43+
};
44+
45+
export type Query = {
46+
__typename?: 'Query';
47+
authors: Array<Author>;
48+
};
49+
50+
export type AuthorsQueryVariables = {};
51+
52+
53+
export type AuthorsQuery = (
54+
{ __typename?: 'Query' }
55+
& { authors: Array<(
56+
{ __typename?: 'Author' }
57+
& Pick<Author, 'id' | 'name' | 'description'>
58+
& { books: Array<(
59+
{ __typename?: 'Book' }
60+
& Pick<Book, 'id' | 'title'>
61+
)> }
62+
)> }
63+
);
64+
65+
export type CreateAuthorMutationVariables = {
66+
input: AuthorInput;
67+
};
68+
69+
70+
export type CreateAuthorMutation = (
71+
{ __typename?: 'Mutation' }
72+
& { createAuthor: (
73+
{ __typename?: 'Author' }
74+
& Pick<Author, 'id' | 'name' | 'description'>
75+
& { books: Array<(
76+
{ __typename?: 'Book' }
77+
& Pick<Book, 'id' | 'title'>
78+
)> }
79+
) }
80+
);

examples/cra/config-overrides.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { override, useBabelRc } = require("customize-cra");
2+
3+
module.exports = override(useBabelRc());

examples/cra/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@apollo/react-hooks": "^3.1.5",
7+
"@apollo/react-testing": "^3.1.4",
68
"@testing-library/jest-dom": "^4.2.4",
79
"@testing-library/react": "^9.3.2",
810
"@testing-library/user-event": "^7.1.2",
11+
"babel-plugin-import-graphql": "^2.7.0",
12+
"customize-cra": "^0.9.1",
913
"react": "^16.13.1",
14+
"react-app-rewired": "^2.1.5",
1015
"react-dom": "^16.13.1",
1116
"react-scripts": "3.4.1"
1217
},
1318
"scripts": {
14-
"start": "react-scripts start",
15-
"build": "react-scripts build",
16-
"test": "react-scripts test",
17-
"eject": "react-scripts eject"
19+
"start": "react-app-rewired start",
20+
"build": "react-app-rewired build",
21+
"test": "react-app-rewired test",
22+
"eject": "react-scripts eject",
23+
"generate": "../../node_modules/@graphql-codegen/cli/bin.js"
1824
},
1925
"eslintConfig": {
2026
"extends": "react-app"

examples/cra/public/index.html

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,10 @@
99
name="description"
1010
content="Web site created using create-react-app"
1111
/>
12-
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13-
<!--
14-
manifest.json provides metadata used when your web app is installed on a
15-
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16-
-->
17-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18-
<!--
19-
Notice the use of %PUBLIC_URL% in the tags above.
20-
It will be replaced with the URL of the `public` folder during the build.
21-
Only files inside the `public` folder can be referenced from the HTML.
22-
23-
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24-
work correctly both with client-side routing and a non-root public URL.
25-
Learn how to configure a non-root public URL by running `npm run build`.
26-
-->
2712
<title>React App</title>
2813
</head>
2914
<body>
3015
<noscript>You need to enable JavaScript to run this app.</noscript>
3116
<div id="root"></div>
32-
<!--
33-
This HTML file is a template.
34-
If you open it directly in the browser, you will see an empty page.
35-
36-
You can add webfonts, meta tags, or analytics to this file.
37-
The build step will place the bundled scripts into the <body> tag.
38-
39-
To begin the development, run `npm start` or `yarn start`.
40-
To create a production bundle, use `npm run build` or `yarn build`.
41-
-->
4217
</body>
4318
</html>

examples/cra/public/logo192.png

-5.22 KB
Binary file not shown.

0 commit comments

Comments
 (0)