Skip to content

Commit 12760a0

Browse files
piglovesyoulangpavel
authored andcommitted
Add features to feature/apollo-pure (#1714)
* Upgrade all dependencies 1. ncu --upgradeAll 4. Leave "graphql" to be "^13.2.0" that apollo packages depend on 2. Apply patch of "npx babel-upgrade" output 3. Leave only necessary babel plugins 4. Pass "yarn fix" by disabling stricter rules * Pass "req" through GraphQL resolver context * Through rootValue it cannot be passed from browser GraphQL access * rm unnecessary code * Add "Timestamp" scalar type for convinience * rm unnecessary files * fix: Timestamp didn't work * npm graphql requires to be update vercel/next.js#5238 (comment) * Feature: Codegen from GraphQL schema and use more Flow types (#2) * install apllo * add apollo.config.js * apollo codegen succeeded * fix: updateNetworkStatus signature * rm @flow from files not ready * add flow-typed files * done: Using auto-generated types works * [email protected]+ has regression. Use ^0.88.0. * fix: invalid GraphQL primitive types * Add codegen script * done: import auto-generated file * refac: move impl for apollo-link-state to graphql dir as same as server side resolvers * codegen and ignore eslint these files * refactor: "networkStatus" * feat: codegen:standalone * refac: "OnMemoryState" is what I meant * Improve codegen (#3) * delete existing auto-generated types * change script name * ignore __generated__ folder * wip: disallow absolute path resolving under `src` dir * It causes disregard .js type checking under src * fix all flow error * modify: prevent `withStyles` drops component type * Modify targe Node versions * Fix build failure: Codegen before lint * Add Node v10 LTS for build target
1 parent b1b784d commit 12760a0

File tree

163 files changed

+33670
-2374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+33670
-2374
lines changed

.eslintrc.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ module.exports = {
9696
// ESLint plugin for prettier formatting
9797
// https://github.com/prettier/eslint-plugin-prettier
9898
'prettier/prettier': 'error',
99-
},
10099

101-
settings: {
102-
// Allow absolute paths in imports, e.g. import Button from 'components/Button'
103-
// https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers
104-
'import/resolver': {
105-
node: {
106-
moduleDirectory: ['node_modules', 'src'],
107-
},
108-
},
100+
'react/forbid-prop-types': 'off',
101+
'react/destructuring-assignment': 'off',
102+
103+
// PropTypes and states are typed by Flow basically, but Flow cannot type defaultProps.
104+
'react/require-default-props': 'off',
109105
},
110106
};

.flowconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
[include]
88

99
[options]
10-
module.system.node.resolve_dirname=node_modules
11-
module.system.node.resolve_dirname=src
10+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectError

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ node_modules/
66
# Compiled output
77
build
88

9+
# Generate Types
10+
__generated__
11+
912
# Runtime data
1013
database.sqlite
1114

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: node_js
22
node_js:
33
- 'stable'
4+
- '10'
45
- '8'
5-
- '6'
66
env:
77
- CXX=g++-4.8
88
addons:
@@ -13,6 +13,7 @@ addons:
1313
- g++-4.8
1414
cache: yarn
1515
script:
16+
- yarn codegen
1617
- yarn lint
1718
- yarn test
1819
- yarn build --release

apollo.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
client: {
3+
service: {
4+
name: 'react-starter-kit',
5+
url: 'http://localhost:3000/graphql',
6+
// optional headers
7+
headers: {
8+
// authorization: 'Bearer lkjfalkfjadkfjeopknavadf',
9+
},
10+
// optional disable SSL validation check
11+
skipSSLValidation: true,
12+
},
13+
},
14+
};

babel.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ module.exports = {
1919
},
2020
},
2121
],
22-
['@babel/preset-stage-2', { decoratorsLegacy: true }],
2322
'@babel/preset-flow',
2423
'@babel/preset-react',
2524
],
25+
plugins: [
26+
'@babel/plugin-proposal-class-properties',
27+
'@babel/plugin-syntax-dynamic-import',
28+
],
2629
ignore: ['node_modules', 'build'],
2730
};

docs/react-style-guide.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
77
### Table of Contents
88

9-
* [Separate folder per UI component](#separate-folder-per-ui-component)
10-
* [Prefer using functional components](#prefer-using-functional-components)
11-
* [Use CSS Modules](#use-css-modules)
12-
* [Use higher-order components](#use-higher-order-components)
9+
- [Separate folder per UI component](#separate-folder-per-ui-component)
10+
- [Prefer using functional components](#prefer-using-functional-components)
11+
- [Use CSS Modules](#use-css-modules)
12+
- [Use higher-order components](#use-higher-order-components)
1313

1414
### Separate folder per UI component
1515

16-
* Place each major UI component along with its resources in a separate folder\
16+
- Place each major UI component along with its resources in a separate folder\
1717
This will make it easier to find related resources for any particular UI element
1818
(CSS, images, unit tests, localization files etc.). Removing such components during
1919
refactorings should also be easy.
20-
* Avoid having CSS, images and other resource files shared between multiple
20+
- Avoid having CSS, images and other resource files shared between multiple
2121
components.\
2222
This will make your code more maintainable, easy to refactor.
23-
* Add `package.json` file into each component's folder.\
23+
- Add `package.json` file into each component's folder.\
2424
This will allow to easily reference such components from other places in your code.\
2525
Use `import Nav from '../Navigation'` instead of `import Nav from '../Navigation/Navigation.js'`
2626

@@ -46,7 +46,7 @@ For more information google for
4646

4747
### Prefer using functional components
4848

49-
* Prefer using stateless functional components whenever possible.\
49+
- Prefer using stateless functional components whenever possible.\
5050
Components that don't use state are better to be written as simple pure functions.
5151

5252
```jsx
@@ -69,16 +69,16 @@ Navigation.propTypes = { items: PropTypes.array.isRequired };
6969

7070
### Use CSS Modules
7171

72-
* Use CSS Modules\
72+
- Use CSS Modules\
7373
This will allow using short CSS class names and at the same time avoid conflicts.
74-
* Keep CSS simple and declarative. Avoid loops, mixins etc.
75-
* Feel free to use variables in CSS via
74+
- Keep CSS simple and declarative. Avoid loops, mixins etc.
75+
- Feel free to use variables in CSS via
7676
[precss](https://github.com/jonathantneal/precss) plugin for
7777
[PostCSS](https://github.com/postcss/postcss)
78-
* Prefer CSS class selectors instead of element and `id` selectors (see
78+
- Prefer CSS class selectors instead of element and `id` selectors (see
7979
[BEM](https://bem.info/))
80-
* Avoid nested CSS selectors (see [BEM](https://bem.info/))
81-
* When in doubt, use `.root { }` class name for the root elements of your
80+
- Avoid nested CSS selectors (see [BEM](https://bem.info/))
81+
- When in doubt, use `.root { }` class name for the root elements of your
8282
components
8383

8484
```scss
@@ -125,14 +125,18 @@ Navigation.propTypes = { items: PropTypes.array.isRequired };
125125

126126
```jsx
127127
// Navigation.js
128+
// @flow
128129
import React from 'react';
129-
import PropTypes from 'prop-types';
130130
import withStyles from 'isomorphic-style-loader/lib/withStyles';
131131
import s from './Navigation.scss';
132132

133-
function Navigation() {
133+
type PropTypes = {|
134+
className: string,
135+
|};
136+
137+
function Navigation(props: PropTypes) {
134138
return (
135-
<nav className={`${s.root} ${this.props.className}`}>
139+
<nav className={`${s.root} ${props.className}`}>
136140
<ul className={s.items}>
137141
<li className={`${s.item} ${s.selected}`}>
138142
<a className={s.link} href="/products">
@@ -149,14 +153,12 @@ function Navigation() {
149153
);
150154
}
151155

152-
Navigation.propTypes = { className: PropTypes.string };
153-
154156
export default withStyles(Navigation, s);
155157
```
156158

157159
### Use higher-order components
158160

159-
* Use higher-order components (HOC) to extend existing React components.\
161+
- Use higher-order components (HOC) to extend existing React components.\
160162
Here is an example:
161163

162164
```js

docs/recipes/how-to-integrate-disqus.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ https://disqus.com/admin/create/
55
#### `DisqusThread.js`
66

77
```js
8+
// @flow
89
import React from 'react';
9-
import PropTypes from 'prop-types';
1010

1111
const SHORTNAME = 'example';
1212
const WEBSITE_URL = 'http://www.example.com';
@@ -22,13 +22,11 @@ function renderDisqus() {
2222
}
2323
}
2424

25-
class DisqusThread extends React.Component {
26-
static propTypes = {
27-
id: PropTypes.string.isRequired,
28-
title: PropTypes.string.isRequired,
29-
path: PropTypes.string.isRequired,
30-
};
31-
25+
class DisqusThread extends React.Component<{|
26+
id: string,
27+
title: string,
28+
path: string,
29+
|}> {
3230
shouldComponentUpdate(nextProps) {
3331
return (
3432
this.props.id !== nextProps.id ||

flow-typed/global.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @flow
2+
3+
declare type __DEV__ = boolean;

0 commit comments

Comments
 (0)