-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from thematters/develop
Release: v1.0.0
- Loading branch information
Showing
18 changed files
with
4,338 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true, | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
], | ||
rules: { | ||
camelcase: 'off', | ||
'@typescript-eslint/camelcase': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
'@typescript-eslint/no-unused-vars': "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off" | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Smartphone (please complete the following information):** | ||
- Device: [e.g. iPhone6] | ||
- OS: [e.g. iOS8.1] | ||
- Browser [e.g. stock browser, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exclude: | ||
- develop | ||
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Build & Publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} | ||
|
||
jobs: | ||
build_and_publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@master | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v2-beta | ||
with: | ||
node-version: '12.16' | ||
registry-url: 'https://registry.npmjs.org' | ||
always-auth: true | ||
|
||
- name: Cache Dependencies | ||
id: cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Install Dependencies | ||
run: npm ci | ||
|
||
- name: Test | ||
run: npm run lint | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
# === `master` branch === | ||
- name: Publish to NPM | ||
if: github.ref == 'refs/heads/master' | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | ||
|
||
- name: Slack Notification | ||
if: always() | ||
uses: 8398a7/action-slack@v3 | ||
with: | ||
status: ${{ job.status }} | ||
author_name: apollo-response-cache | ||
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Create Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@master | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get Version | ||
id: version | ||
uses: martinbeentjes/npm-get-version-action@master | ||
|
||
- name: Generate CHANGELOG | ||
uses: scottbrenner/generate-changelog-action@master | ||
id: changelog | ||
env: | ||
REPO: ${{ github.repository }} | ||
|
||
- name: Create Release | ||
uses: actions/create-release@v1 | ||
with: | ||
tag_name: v${{ steps.version.outputs.current-version}} | ||
release_name: v${{ steps.version.outputs.current-version}} | ||
body: | | ||
${{ steps.changelog.outputs.changelog }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Slack Notification | ||
if: always() | ||
uses: 8398a7/action-slack@v3 | ||
with: | ||
status: ${{ job.status }} | ||
author_name: apollo-response-cache | ||
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,92 @@ | ||
# matters-server-cache | ||
Cache mechanisms (plugins, directives) of Apollo GraphQL used by `matters-server` | ||
# apollo-response-cache | ||
|
||
![Deploy Status](https://github.com/thematters/apollo-response-cache/workflows/Build%20&%20Publish/badge.svg) ![Release Status](https://github.com/thematters/apollo-response-cache/workflows/Create%20Release/badge.svg) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) | ||
|
||
Caching and invalidation mechanisms (plugins, directives) of Apollo GraphQL, used by [`matters-server`](https://github.com/thematters/matters-server). | ||
|
||
[`responseCachePlugin`](./src/plugins/responseCachePlugin.ts) is forked from [`apollo-server-plugin-response-cache`](https://github.com/apollographql/apollo-server/tree/main/packages/apollo-server-plugin-response-cache). | ||
|
||
### How it works? | ||
|
||
![Cache Mechanisms](./assets/cache-mechanisms.svg) | ||
|
||
On each query request, | ||
|
||
1. `responseCachePlugin` creates an empty key set, and injects it to the context. | ||
2. `@logCache` collects node on its field, then add to the key set. | ||
3. `responseCachePlugin` writes query response cache (`fqc`) and node-fqc key mapping to in-memory data store. | ||
|
||
Once a mutation updates this node, `@purgeCache` will purge related `fqc`. | ||
|
||
### Usage | ||
|
||
Add plugin and directives to the constructor: | ||
|
||
```ts | ||
import { | ||
responseCachePlugin, | ||
LogCacheDirective, | ||
PurgeCacheDirective, | ||
} from '@matters/apollo-response-cache' | ||
|
||
const server = new ApolloServer({ | ||
plugins: [responseCachePlugin()], | ||
}) | ||
|
||
const schema = makeExecutableSchema({ | ||
schemaDirectives: { | ||
logCache: LogCacheDirective(), | ||
purgeCache: PurgeCacheDirective(), | ||
}, | ||
}) | ||
``` | ||
|
||
Add definitions to your schema: | ||
|
||
```graphql | ||
directive @logCache( | ||
type: String! | ||
identifier: String = "id" | ||
) on FIELD_DEFINITION | ||
|
||
directive @purgeCache( | ||
type: String! | ||
identifier: String = "id" | ||
) on FIELD_DEFINITION | ||
``` | ||
|
||
Use in the schema: | ||
|
||
```graphql | ||
type Query { | ||
article(id: ID!): Article! @logCache(type: "Article") | ||
} | ||
|
||
type Mutation { | ||
archiveArticle(id: ID!): Article! @purgeCache(type: "Article") | ||
} | ||
``` | ||
|
||
You can also purge cache in the resolver: | ||
|
||
```ts | ||
const resolvers = { | ||
Mutation: { | ||
archiveArticle: (parent, args, context) => { | ||
// ... | ||
article[CACHE_KEYWORD] = [ | ||
{ | ||
id: article.id, | ||
type: 'Article', | ||
}, | ||
{ | ||
id: comment.id, | ||
type: 'Comment', | ||
}, | ||
] | ||
|
||
return article | ||
}, | ||
}, | ||
} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.