Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3c195f7
Showing
16 changed files
with
5,866 additions
and
0 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,32 @@ | ||
# Javascript Node CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | ||
# | ||
version: 2 | ||
jobs: | ||
test: | ||
docker: | ||
- image: circleci/node:15 | ||
working_directory: ~/repo | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- v2-dependencies-{{ checksum "yarn.lock" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v2-dependencies- | ||
- run: yarn install --frozen-lockfile | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
- ~/.cache/yarn | ||
key: v2-dependencies-{{ checksum "yarn.lock" }} | ||
- run: yarn build-es5 | ||
- run: yarn test | ||
- run: yarn lint | ||
- run: yarn validate-prettiness | ||
workflows: | ||
version: 2 | ||
test: | ||
jobs: | ||
- test |
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,73 @@ | ||
--- | ||
settings: | ||
react: | ||
version: 'detect' | ||
parser: '@typescript-eslint/parser' | ||
plugins: | ||
- '@typescript-eslint' | ||
- 'react' | ||
- 'react-hooks' | ||
extends: | ||
- 'plugin:@typescript-eslint/recommended' | ||
- 'plugin:react/recommended' | ||
- eslint-config-prettier | ||
- plugin:import/errors | ||
- plugin:import/warnings | ||
- plugin:import/typescript | ||
rules: | ||
no-use-before-define: | ||
- warn | ||
'@typescript-eslint/naming-convention': | ||
- error | ||
- selector: interface | ||
format: | ||
- PascalCase | ||
custom: | ||
regex: "^[A-Z][a-z]" | ||
match: true | ||
'@typescript-eslint/no-use-before-define': | ||
- warn | ||
'@typescript-eslint/explicit-function-return-type': | ||
- warn | ||
- allowExpressions: true | ||
'@typescript-eslint/no-unused-vars': | ||
- warn | ||
- argsIgnorePattern: '^_' | ||
no-unused-expressions: | ||
- error | ||
no-underscore-dangle: | ||
- warn | ||
- enforceInMethodNames: true | ||
allow: | ||
- _id | ||
- __typename | ||
react/display-name: | ||
- warn | ||
react/prop-types: | ||
- off | ||
'@typescript-eslint/no-non-null-assertion': | ||
- off | ||
class-methods-use-this: | ||
- error | ||
import/order: | ||
- error | ||
- newlines-between: always | ||
alphabetize: | ||
order: asc | ||
groups: | ||
- - builtin | ||
- external | ||
- - parent | ||
- sibling | ||
- index | ||
react-hooks/rules-of-hooks: | ||
- error | ||
react-hooks/exhaustive-deps: | ||
- error | ||
# conflicts with allowSyntheticDefaultImports tsconfig option | ||
import/default: | ||
- off | ||
'@typescript-eslint/member-delimiter-style': | ||
- error | ||
- multiline: | ||
delimiter: none |
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 @@ | ||
/node_modules | ||
/dist* | ||
/package-lock.json |
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 @@ | ||
hooks: | ||
pre-commit: pretty-quick --staged | ||
pre-push: yarn build-es5 && yarn validate |
Empty file.
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 @@ | ||
semi: false | ||
singleQuote: true | ||
trailingComma: all |
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 @@ | ||
{ | ||
"extends": ["config:base"] | ||
} |
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,5 @@ | ||
Copyright 2021 James Pike | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
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,4 @@ | ||
# Changelog | ||
|
||
- 2020/05/18 - 1.0.0-beta.1 | ||
- Initial release. |
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,4 @@ | ||
module.exports = { | ||
testRegex: 'spec\\.js$', | ||
roots: ['<rootDir>/dist.es5'], | ||
} |
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": "graphql-filter-object", | ||
"version": "1.0.0-beta.1", | ||
"description": "filter objects and arrays according to a graphql-tag", | ||
"author": "insidewhy <github@chilon.net>", | ||
"license": "ISC", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/insidewhy/graphql-filter-object.git" | ||
}, | ||
"keywords": [ | ||
"graphql", | ||
"filter" | ||
], | ||
"main": "dist.es5/index.js", | ||
"module": "dist.es5m/index.js", | ||
"es2015": "dist.es2015/index.js", | ||
"typings": "dist.es2015/index", | ||
"sideEffects": false, | ||
"scripts": { | ||
"prepublishOnly": "yarn build", | ||
"build": "yarn build-modern && yarn build-es5 && yarn build-es5m", | ||
"build-modern": "tsc -p src", | ||
"build-es5": "tsc -p src --target es5 --outDir dist.es5", | ||
"build-es5m": "yarn build-es5 -m es2015 --outDir dist.es5m", | ||
"build-watch": "yarn build-es5 -w", | ||
"clean": "rimraf 'dist*'", | ||
"lint": "eslint 'src/*.ts'", | ||
"lint-fix": "yarn lint --fix", | ||
"run-prettier": "prettier 'src/*.ts' '*.md'", | ||
"typecheck": "tsc -p src --noEmit", | ||
"validate-prettiness": "yarn run-prettier -c", | ||
"make-prettier": "yarn run-prettier --write", | ||
"test": "yarn jest", | ||
"test-watch": "yarn test --watchAll", | ||
"watch": "yarn build-es5 && concurrently 'yarn build-watch' 'yarn test-watch'", | ||
"validate": "yarn test && yarn lint && yarn validate-prettiness" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "26.0.23", | ||
"@typescript-eslint/eslint-plugin": "4.24.0", | ||
"@typescript-eslint/parser": "4.24.0", | ||
"concurrently": "6.1.0", | ||
"eslint": "7.26.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-import": "2.23.2", | ||
"eslint-plugin-react": "7.23.2", | ||
"eslint-plugin-react-hooks": "4.2.0", | ||
"graphql": "15.5.0", | ||
"graphql-tag": "2.12.4", | ||
"husky": "6.0.0", | ||
"jest": "26.6.3", | ||
"prettier": "2.3.0", | ||
"pretty-quick": "3.1.0", | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"react-test-renderer": "17.0.2", | ||
"rimraf": "3.0.2", | ||
"typescript": "4.2.4" | ||
} | ||
} |
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,163 @@ | ||
# graphql-filter-object | ||
|
||
[![build status](https://circleci.com/gh/insidewhy/graphql-filter-object.png?style=shield)](https://circleci.com/gh/insidewhy/graphql-filter-object) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/insidewhy/graphql-filter-object/badge.svg)](https://snyk.io/test/github/insidewhy/graphql-filter-object) | ||
[![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com) | ||
|
||
`graphql-filter-object` is a library that can be used to filter objects and arrays according to a query, subscription or mutation specified via a `gql` object. | ||
|
||
## Documentation | ||
|
||
```typescript | ||
import buildGraphqlFilter from 'graphql-filter-object' | ||
|
||
const objectFilter = buildGraphqlFilter(gql` | ||
query GetCat($catName: String!) { | ||
getCat(cats: $catName) { | ||
name | ||
qualities { | ||
qualityName | ||
loveliness | ||
} | ||
} | ||
} | ||
`) | ||
|
||
const filtered = objectFilter.filter({ | ||
getCat: { | ||
name: 'Mr Onions', | ||
breed: 'Major Springer', | ||
qualities: [ | ||
{ | ||
qualityName: 'Cuddliness', | ||
loveliness: 4_000, | ||
usefulness: -10, | ||
}, | ||
{ | ||
qualityName: 'Fighting', | ||
loveliness: -10, | ||
usefulness: 20, | ||
}, | ||
], | ||
}, | ||
}) | ||
``` | ||
|
||
After running this, `filtered` will equal: | ||
|
||
```typescript | ||
const filtered = { | ||
getCat: { | ||
name: 'Mr Onions', | ||
qualities: [ | ||
{ | ||
qualityName: 'Cuddliness', | ||
loveliness: 4_000, | ||
}, | ||
{ | ||
qualityName: 'Fighting', | ||
loveliness: -10, | ||
}, | ||
], | ||
}, | ||
} | ||
``` | ||
|
||
Also supports fragments: | ||
|
||
```typescript | ||
import buildGraphqlFilter from 'graphql-filter-object' | ||
|
||
const objectFilter = buildGraphqlFilter( | ||
gql` | ||
fragment QualitiesFragment on CatQualities { | ||
qualityName | ||
loveliness | ||
} | ||
fragment BigCatQualitiesFragment on BigCatQualities { | ||
qualityName | ||
fierceness | ||
} | ||
query GetCat($catName: String!) { | ||
getCat(cats: $catName) { | ||
name | ||
qualities { | ||
...QualitiesFragment | ||
...BigCatQualitiesFragment | ||
} | ||
} | ||
} | ||
`, | ||
) | ||
|
||
const filtered = filter.filter({ | ||
getCat: [ | ||
{ | ||
name: 'Turback', | ||
weight: 9_000, | ||
qualities: [ | ||
{ | ||
__typename: 'BigCatQualities', | ||
qualityName: 'furry', | ||
loveliness: 60, | ||
fierceness: 100, | ||
annoying: 10, | ||
}, | ||
{ | ||
__typename: 'BigCatQualities', | ||
qualityName: 'cuddly', | ||
loveliness: 100, | ||
fierceness: 19, | ||
annoying: 0, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'Fluff-hunter', | ||
weight: 0.1, | ||
qualities: [ | ||
{ | ||
__typename: 'CatQualities', | ||
qualityName: 'furry', | ||
loveliness: 60, | ||
fierceness: 27, | ||
annoying: 10, | ||
}, | ||
], | ||
}, | ||
], | ||
}) | ||
``` | ||
|
||
After running this, `filtered` will equal: | ||
|
||
```typescript | ||
const filtered = { | ||
getCat: [ | ||
{ | ||
name: 'Turback', | ||
qualities: [ | ||
{ | ||
qualityName: 'furry', | ||
fierceness: 100, | ||
}, | ||
{ | ||
qualityName: 'cuddly', | ||
fierceness: 19, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'Fluff-hunter', | ||
qualities: [ | ||
{ | ||
qualityName: 'furry', | ||
loveliness: 60, | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
``` |
Oops, something went wrong.