Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,60 @@ It's a package with some (currently two to be exact) tools to use when building

```
yarn add @entria/graphql-mongo-helpers

or

npm i @entria/graphql-mongo-helpers
```

### Usage

The most updated source of documentation are the test files, check the files in `src/__tests__/`.
#### MATCH_1_TO_1
The example below includes use with or without regex, e sub field.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"e sub field" should be "and subfield"

```
const stringToRegexQuery = val => ({ $regex: new RegExp(val) })

const mapping = {
code: {
type: FILTER_CONDITION_TYPE.MATCH_1_TO_1,
},
city: {
type: FILTER_CONDITION_TYPE.MATCH_1_TO_1,
format: stringToRegexQuery
},
stateuf: {
type: FILTER_CONDITION_TYPE.MATCH_1_TO_1,
key: 'state.uf'
},
statename: {
type: FILTER_CONDITION_TYPE.MATCH_1_TO_1,
key: 'state.name'
},
}
```

#### CUSTOM_CONDITION
The custom condition can be used to filter posts that include a list of tag as in the example below:

```
const mapping = {
tags: {
type: FILTER_CONDITION_TYPE.CUSTOM_CONDITION,
format: tags => {
if (!tags) return []
return { tags: { $in: tags } };
},
},
};
```

The following posts are going to have more info on both helpers currently exported by this library:
#### AGGREGATE_PIPELINE
Soon documentation will be included, As a complement to the documentation see all the tests, in `src/__tests__/`.

[Introduction to GraphQL Mongo Helpers
][post-a]
### Posts:
The following posts are going to have more info about use of this library:

[Introduction to GraphQL Mongo Helpers][post-a]
[Client-Supplied Custom Sorting Using GraphQL][post-b]

[graphql]: https://github.com/graphql/graphql-js
Expand Down