Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
aed19f5
lerna init & move graphql-hooks to packages
jackdclark Feb 28, 2019
0abf896
update root scripts
jackdclark Feb 28, 2019
6eff413
update circleci
jackdclark Feb 28, 2019
1a5f696
first
bmullan91 Feb 14, 2019
840f02e
update quickstart guide
bmullan91 Feb 14, 2019
83fab50
v1.0.1
bmullan91 Feb 14, 2019
a7a3c1b
Add renovate.json (#2)
renovate[bot] Feb 18, 2019
8b2a9ab
Pin dependencies (#3)
renovate[bot] Feb 20, 2019
b27f14e
Update react monorepo to v16.8.3 (#4)
renovate[bot] Feb 21, 2019
d9ec381
first
bmullan91 Feb 11, 2019
2fd2a36
use prettier
bmullan91 Feb 11, 2019
1811112
v1.0.1
bmullan91 Feb 11, 2019
719108a
reademe -> readme... doh
bmullan91 Feb 11, 2019
d35c85b
v1.0.2
bmullan91 Feb 11, 2019
1c0ecbb
use fnv1a algo for object hashing
bmullan91 Feb 12, 2019
e12e0fc
v1.0.3
bmullan91 Feb 12, 2019
0ed80c9
update package.json repo, bugs and homepage links
bmullan91 Feb 14, 2019
2ccf40b
v1.0.4
bmullan91 Feb 14, 2019
bc33c5b
Add renovate.json (#2)
renovate[bot] Feb 18, 2019
fd4843c
Pin dependencies (#3)
renovate[bot] Feb 21, 2019
3fd8fa8
exit 0 for new packages
jackdclark Mar 1, 2019
b170b87
Create jest config for packages
Joezo Mar 1, 2019
61889ed
move coveralls reporting to root
jackdclark Mar 1, 2019
382a830
run root coveralls in ci
jackdclark Mar 1, 2019
8385170
Remove duplicate files from packages
Joezo Mar 1, 2019
3dedb53
update README
jackdclark Mar 4, 2019
59fc827
Merge branch 'master' into lerna
jackdclark Mar 4, 2019
405140e
update eslint & prettier paths
jackdclark Mar 4, 2019
f37f848
add npm release & update CONTRIBUTING.md
jackdclark Mar 4, 2019
56133e8
Merge branch 'master' into lerna
jackdclark Mar 4, 2019
8be86cc
relative packages in README
jackdclark Mar 4, 2019
58666aa
Merge branch 'master' into lerna
jackdclark Mar 4, 2019
280553f
tidy package.json for packages
jackdclark Mar 4, 2019
b4418c4
update issue templates
jackdclark Mar 4, 2019
eea43c9
prettier babel config
jackdclark Mar 4, 2019
56d5b1d
remove test test
jackdclark Mar 4, 2019
8ff00cb
Update lint-staged config
Joezo Mar 4, 2019
e287b2e
Merge branch 'master' into lerna
Joezo Mar 4, 2019
6b76c92
Update eslint command
Joezo Mar 4, 2019
dc3f1f5
Add note to CONTRIBUTING about lerna
Joezo Mar 4, 2019
bfe3fb3
remove jest from package dir
jackdclark Mar 5, 2019
e047a50
update graphql-hooks-memcache to latest
jackdclark Mar 5, 2019
c2d9f9f
Update eslint/prettier paths
Joezo Mar 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ jobs:
- store_artifacts:
path: reports/junit

- run: |
npm install coveralls
cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- run: npm run coveralls
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
### Package

<!-- Which package is this for? -->

- [ ] `graphql-hooks`
- [ ] `graphql-hooks-ssr`
- [ ] `graphql-hooks-memcache`

### Environment

- `graphql-hooks` version:
<!-- Remove the following two lines if they are not applicable -->
- `graphql-hooks-ssr` version:
- `graphql-hooks-memcache` version:
- `react` version:
- Browser:

Expand Down
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/Bug_Report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ about: Bugs or any unexpected issues.
labels: bug
---

### Package

<!-- Which package is this for? -->

- [ ] `graphql-hooks`
- [ ] `graphql-hooks-ssr`
- [ ] `graphql-hooks-memcache`

### Environment

- `graphql-hooks` version:
<!-- Remove the following two lines if they are not applicable -->
- `graphql-hooks-ssr` version:
- `graphql-hooks-memcache` version:
- `react` version:
- Browser:

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules
graphql-hooks-*.*.*.tgz
package-lock.json
/coverage
coverage
.DS_Store
lib
dist
Expand Down
14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ We would like to avoid issues that require a follow up questions to identify the

## For Developers

### Packages

We use [Lerna](https://lernajs.io) to manage this monorepo, you will find the different `graphql-hooks-*` modules in the `packages` directory.

### Getting started

Clone the repository and run `npm install`. This will install the root dependencies and all of the dependencies required by each package, using `lerna bootstrap`.

All contributions should use the [prettier](https://prettier.io/) formatter, pass linting and pass tests.
You can do this by running:

Expand Down Expand Up @@ -52,9 +60,9 @@ For more information on `@all-contributors` see it's [usage docs](https://allcon
### Release process:

- `npm test`
- `npm version <major|minor|patch>`
- `git push && git push --tags`
- `npm publish`
- `npm run release`

Follow the prompts from [`lerna publish`](https://lernajs.io/#command-publish)

---

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
![](https://img.shields.io/bundlephobia/minzip/graphql-hooks.svg?style=flat)
[![npm version](https://badge.fury.io/js/graphql-hooks.svg)](https://badge.fury.io/js/graphql-hooks)
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lernajs.io/)

🎣 Minimal hooks-first GraphQL client.

## Features

- 🥇 First-class hooks API
- ⚖️ _Tiny_ bundle: only 5.1kB (1.9 gzipped)
- 📄 Full SSR support: see [graphql-hooks-ssr](https://github.com/nearform/graphql-hooks-ssr)
- 🔌 Plugin Caching: see [graphql-hooks-memcache](https://github.com/nearform/graphql-hooks-memcache)
- 📄 Full SSR support: see [graphql-hooks-ssr](packages/graphql-hooks-ssr)
- 🔌 Plugin Caching: see [graphql-hooks-memcache](packages/graphql-hooks-memcache)
- 🔥 No more render props hell
- ⏳ Handle loading and error states with ease

Expand Down Expand Up @@ -124,7 +125,7 @@ const client = new GraphQLClient(config);
- `cache.clear()`
- `cache.keys()`
- `getInitialState()`
- See [graphql-hooks-memcache](https://github.com/nearform/graphql-hooks-memcache) as a reference implementation
- See [graphql-hooks-memcache](packages/graphql-hooks-memcache) as a reference implementation
- `fetch(url, options)`: Fetch implementation - defaults to the global `fetch` API
- `fetchOptions`: See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) for info on what options can be passed
- `headers`: Object, e.g. `{ 'My-Header': 'hello' }`
Expand Down Expand Up @@ -323,7 +324,7 @@ The `options` object that can be passed either to `useMutation(mutation, options

### SSR

See [graphql-hooks-ssr](https://github.com/nearform/graphql-hooks-ssr) for an in depth guide.
See [graphql-hooks-ssr](packages/graphql-hooks-ssr) for an in depth guide.

### Pagination

Expand Down Expand Up @@ -467,6 +468,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore -->
| [<img src="https://avatars1.githubusercontent.com/u/1939483?v=4" width="100px;" alt="Brian Mullan"/><br /><sub><b>Brian Mullan</b></sub>](https://twitter.com/bmullan91)<br />[💬](#question-bmullan91 "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Abmullan91 "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Code") [🖋](#content-bmullan91 "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Documentation") [💡](#example-bmullan91 "Examples") [🤔](#ideas-bmullan91 "Ideas, Planning, & Feedback") [🚧](#maintenance-bmullan91 "Maintenance") [👀](#review-bmullan91 "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Tests") | [<img src="https://avatars0.githubusercontent.com/u/1485654?v=4" width="100px;" alt="Jack Clark"/><br /><sub><b>Jack Clark</b></sub>](https://jackdc.com)<br />[💬](#question-jackdclark "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Ajackdclark "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Code") [🖋](#content-jackdclark "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Documentation") [💡](#example-jackdclark "Examples") [🤔](#ideas-jackdclark "Ideas, Planning, & Feedback") [🚧](#maintenance-jackdclark "Maintenance") [👀](#review-jackdclark "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Tests") | [<img src="https://avatars1.githubusercontent.com/u/2870255?v=4" width="100px;" alt="Joe Warren"/><br /><sub><b>Joe Warren</b></sub>](http://twitter.com/joezo)<br />[💬](#question-Joezo "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3AJoezo "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Code") [🖋](#content-Joezo "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Documentation") [💡](#example-Joezo "Examples") [🤔](#ideas-Joezo "Ideas, Planning, & Feedback") [🚧](#maintenance-Joezo "Maintenance") [👀](#review-Joezo "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Tests") | [<img src="https://avatars1.githubusercontent.com/u/20181?v=4" width="100px;" alt="Simone Busoli"/><br /><sub><b>Simone Busoli</b></sub>](http://simoneb.github.io)<br />[💬](#question-simoneb "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Asimoneb "Bug reports") [📖](https://github.com/nearform/graphql-hooks/commits?author=simoneb "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/842246?v=4" width="100px;" alt="jhey tompkins"/><br /><sub><b>jhey tompkins</b></sub>](https://jheytompkins.com)<br />[⚠️](https://github.com/nearform/graphql-hooks/commits?author=jh3y "Tests") [💬](#question-jh3y "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Ajh3y "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=jh3y "Code") [🖋](#content-jh3y "Content") | [<img src="https://avatars3.githubusercontent.com/u/6270048?v=4" width="100px;" alt="Haroen Viaene"/><br /><sub><b>Haroen Viaene</b></sub>](https://haroen.me)<br />[🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3AHaroenv "Bug reports") |
| :---: | :---: | :---: | :---: | :---: | :---: |

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// this is used by jest only
module.exports = {
presets: [
[
Expand Down
25 changes: 25 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const projects = [
{
displayName: 'graphql-hooks',
roots: ['./packages/graphql-hooks'],
testMatch: ['<rootDir>/packages/graphql-hooks/**/*.test.js'],
setupFiles: ['<rootDir>/packages/graphql-hooks/test/setup.js'],
setupFilesAfterEnv: [
'<rootDir>/packages/graphql-hooks/test/setupAfterEnv.js'
],
automock: false
},
{
roots: ['./packages/graphql-hooks-memcache'],
displayName: 'graphql-hooks-memcache',
testMatch: ['<rootDir>/packages/graphql-hooks-memcache/**/*.test.js']
},
{
roots: ['./packages/graphql-hooks-ssr'],
displayName: 'graphql-hooks-ssr',
testMatch: ['<rootDir>/packages/graphql-hooks-ssr/**/*.test.js']
}
];
module.exports = {
projects
};
4 changes: 4 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packages": ["packages/*"],
"version": "independent"
}
91 changes: 26 additions & 65 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,91 +1,52 @@
{
"name": "graphql-hooks",
"version": "3.2.2",
"description": "Graphql Hooks",
"main": "lib/graphql-hooks.js",
"module": "es/graphql-hooks.js",
"unpkg": "dist/graphql-hooks.min.js",
"name": "root",
"private": true,
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"eslint": "eslint src test",
"prettier": "prettier src/**/*.js test/**/*.js --write",
"build": "rollup -c",
"prepublishOnly": "npm run build"
},
"files": [
"dist",
"es",
"lib"
],
"keywords": [
"graphql",
"hooks",
"graphql-hooks",
"gql",
"gql-hooks",
"react-graphql-hooks",
"react",
"apollo"
],
"author": "Brian Mullan <[email protected]>",
"license": "Apache-2.0",
"peerDependencies": {
"react": "^16.8.3"
"postinstall": "lerna bootstrap --no-ci",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"eslint": "eslint *.js packages/*/*.js packages/*/{src,test}/**/*.js",
"prettier": "prettier *.js *.md packages/*/*.{js,md} packages/*/{src,test}/**/*.{js,md} --write",
"release": "lerna publish"
},
"devDependencies": {
"@babel/preset-env": "7.3.4",
"@babel/preset-react": "7.0.0",
"babel-eslint": "10.0.1",
"babel-jest": "24.1.0",
"eslint": "5.15.0",
"coveralls": "3.0.3",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-react": "7.12.4",
"eslint-plugin-react-hooks": "1.4.0",
"eslint-plugin-react": "7.12.4",
"eslint": "5.15.0",
"husky": "1.3.1",
"jest": "24.1.0",
"jest-fetch-mock": "2.1.1",
"lerna": "3.13.1",
"lint-staged": "8.1.5",
"prettier": "1.16.4",
"react": "16.8.3",
"react-dom": "16.8.3",
"react-hooks-testing-library": "0.3.6",
"react-testing-library": "6.0.0",
"rollup": "1.4.1",
"rollup-plugin-babel": "4.3.2",
"rollup-plugin-node-resolve": "4.0.1",
"rollup-plugin-size-snapshot": "0.8.0",
"rollup-plugin-terser": "4.0.4"
"prettier": "1.16.4"
},
"lint-staged": {
"./src/**/*.js": [
"eslint src test",
"prettier src/**/*.js test/**/*.js --write",
"./packages/*/{src,test}/**/*.js": [
"eslint",
"prettier --write",
"git add"
],
"./packages/*/*.js": [
"eslint",
"prettier --write",
"git add"
],
"*.js": [
"eslint",
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"jest": {
"automock": false,
"setupFiles": [
"./test/setup.js"
],
"setupFilesAfterEnv": [
"react-testing-library/cleanup-after-each"
]
},
"repository": {
"type": "git",
"url": "git://github.com/nearform/graphql-hooks.git"
},
"bugs": {
"url": "https://github.com/nearform/graphql-hooks"
},
"homepage": "https://github.com/nearform/graphql-hooks#readme"
}
}
42 changes: 42 additions & 0 deletions packages/graphql-hooks-memcache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# graphql-hooks-memcache

In-memory caching implementation for graphql-hooks

## Install

`npm install graphql-hooks-memcache`

or

`yarn add graphql-hooks-memcache`

## Quick Start

This is intended to be used as the `cache` option when calling `createClient` from `graphql-hooks`.

```js
import { GraphQLClient } from 'graphql-hooks';
import memCache from 'graphql-hooks-memcache';

const client = new GraphQLClient({
endpoint: '/graphql',
cache: memCache()
});
```

### Options

`memCache(options)`: Option object properties

- `size`: The number of items to store in the cache
- `ttl`: Milliseconds an item will remain in cache. Default behaviour will only evict items when `size` limit has been reached
- `initialState`: The value from `cache.getInitialState()` used for rehydrating the cache after SSR

### API

- `cache.get(key)`: Find item in cache that matches `key`
- `cache.set(key, value)`: Set an item in the cache
- `cache.delete(key)`: Delete an item from the cache
- `cache.clear()`: Clear all items from the cache
- `cache.keys()`: Returns an array of keys, useful when you need to iterate over the cache items
- `cache.getInitialState()`: A serialisable version of the cache - used during SSR
32 changes: 32 additions & 0 deletions packages/graphql-hooks-memcache/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const LRU = require('tiny-lru');
const fnv1a = require('@sindresorhus/fnv1a');

function generateKey(keyObj) {
return fnv1a(JSON.stringify(keyObj)).toString(36);
}

module.exports = function memCache({ size = 100, ttl = 0, initialState } = {}) {
const lru = LRU(size, ttl);

if (initialState) {
Object.keys(initialState).map(k => {
lru.set(k, initialState[k]);
});
}

return {
get: keyObj => lru.get(generateKey(keyObj)),
set: (keyObj, data) => lru.set(generateKey(keyObj), data),
delete: keyObj => lru.delete(generateKey(keyObj)),
clear: () => lru.clear(),
keys: () => lru.keys(),
getInitialState: () =>
lru.keys().reduce(
(initialState, key) => ({
...initialState,
[key]: lru.get(key)
}),
{}
)
};
};
32 changes: 32 additions & 0 deletions packages/graphql-hooks-memcache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "graphql-hooks-memcache",
"version": "1.0.5",
"description": "In memory cache for graphql-hooks",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"graphql",
"hooks",
"react",
"graphql-hooks",
"cache",
"ssr",
"server-side rendering"
],
"author": "Brian Mullan <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"@sindresorhus/fnv1a": "^1.0.0",
"tiny-lru": "^6.0.1"
},
"repository": {
"type": "git",
"url": "git://github.com/nearform/graphql-hooks.git"
},
"bugs": {
"url": "https://github.com/nearform/graphql-hooks/issues"
},
"homepage": "https://github.com/nearform/graphql-hooks/blob/master/packages/graphql-hooks-memcache#readme"
}
Loading