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

New graphql schema #785

Merged
merged 23 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
99b27c1
Revert "Revert "feat: New GraphQL schema""
adriangmweb Mar 29, 2021
b0824e2
refactor non compatible cases to be JSONObjects
adriangmweb Apr 5, 2021
35d4e07
handle typescript classes
adriangmweb Apr 6, 2021
efef591
fix operations for nested properties
adriangmweb Apr 6, 2021
30ba05a
update subscriptions filters
adriangmweb Apr 12, 2021
c0a6cba
add properties to test the graphql filters
adriangmweb Apr 13, 2021
94e127f
fix unit tests
adriangmweb Apr 13, 2021
6701444
Add graphql query filters integration tests
adriangmweb Apr 13, 2021
de6006d
add filter method doc
adriangmweb Apr 14, 2021
d67b3fa
move subscriptions integration tests to end-to-end
adriangmweb Apr 14, 2021
e72eb1f
improve array includes method on subscriptions
adriangmweb Apr 14, 2021
adfaf78
add subscription filters integration tests
adriangmweb Apr 14, 2021
fb147eb
fix documentation format
adriangmweb Apr 15, 2021
39cced0
remove unnecessary tsconfig lib
adriangmweb Apr 21, 2021
cfd3f48
apply suggestions on documentation
adriangmweb Apr 29, 2021
98dc3d1
small refactors to improve the code
adriangmweb Apr 29, 2021
fcd4a4c
improve searcher filter method doc
adriangmweb Apr 29, 2021
6abbbe3
use ttsc and upgrade node and npm versions
adriangmweb Apr 29, 2021
90a463f
fix dependencies issues
adriangmweb May 3, 2021
f750365
fix e2e tests
adriangmweb May 3, 2021
899f588
refactor graphql-generator
adriangmweb May 3, 2021
24a67f1
remove npx from npm scripts
adriangmweb May 3, 2021
802cecb
fix graphql api unit tests
adriangmweb May 3, 2021
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: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ A clear and concise description of what you expected to happen (or code).

### Environment

- Booster version: [e.g. 0.8.2] <!--- You can check this with `boost version` -->
- Node/npm version: [e.g. Node 8/npm 5]
- Booster version: [e.g. 0.15.1] <!--- You can check this with `boost version` -->
- Node/npm version: [e.g. Node 14/npm 7]
- OS: [e.g. OSX 10.13.4, Windows 10]
8 changes: 4 additions & 4 deletions docs/chapters/02_getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Verify that it was installed properly by checking so from your terminal:

```shell
$ node -v
v13.12.0
v14.2.0

$ npm -v
6.14.4
7.0.0
```

As soon as you have a Node.js version higher than `v12`, and an `npm` version higher than
`6`, you are good to go. Just note that `npm` comes with node, you don't have to install
As soon as you have a Node.js version higher than `v14`, and an `npm` version higher than
`7`, you are good to go. Just note that `npm` comes with node, you don't have to install
it apart.

Alternatively, we recommend you to use a version manager for dealing with different Node.js
Expand Down
141 changes: 139 additions & 2 deletions docs/chapters/03_booster-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,144 @@ For more information about queries and how to use them, please check the [GraphQ

Booster GraphQL API also provides support for real-time updates using subscriptions and a web-socket. To get more information about it go to the [GraphQL API](chapters/04_features#subscribing-to-read-models) section.

## Getting and filtering read models data at code level
#### Filtering a read model

The Booster GraphQL API provides support for filtering Read Models on `queries` and `subscriptions`.

Using the GraphQL API endpoint you can retrieve the schema of your application so you can see what are the filters for every Read Model and its properties. You can filter like this:

Searching for a specific Read Model by `id`

```graphql
query {
ProductReadModels(filter: { id: { eq: "test-id" } }) {
id
sku
availability
price
}
}
```

#### Supported filters

The currently supported filters are the following ones:

##### Boolean filters

| Filter | Value | Description |
| :----- | :--------: | -----------: |
| eq | true/false | Equal to |
| ne | true/false | Not equal to |

Example:

```graphql
query {
ProductReadModels(filter: { availability: { eq: true } }) {
id
sku
availability
price
}
}
```

##### Number filters

| Filter | Value | Description |
| :----- | :-----: | --------------------: |
| eq | Float | Equal to |
| ne | Float | Not equal to |
| gt | Float | Greater than |
| gte | Float | Greater or equal than |
| lt | Float | Lower than |
| lte | Float | Lower or equal than |
| in | [Float] | Exists in given array |

Example:

```graphql
query {
ProductReadModels(filter: { price: { gt: 200 } }) {
id
sku
availability
price
}
}
```

##### String filters

| Filter | Value | Description |
| :--------- | :------: | -------------------------: |
| eq | String | Equal to |
| ne | String | Not equal to |
| gt | String | Greater than |
| gte | String | Greater or equal than |
| lt | String | Lower than |
| lte | String | Lower or equal than |
| in | [String] | Exists in given array |
| beginsWith | String | Starts with a given substr |
| contains | String | Contains a given substr |

Example:

```graphql
query {
ProductReadModels(filter: { sku: { begingsWith: "jewelry" } }) {
id
sku
availability
price
}
}
```

##### Array filters

| Filter | Value | Description |
| :------- | :----: | ----------------------: |
| includes | Object | Includes a given object |

Example:

```graphql
query {
CartReadModels(filter: { itemsIds: { includes: "test-item" } }) {
id
price
itemsIds
}
}
```

_Note: Right now, with complex properties in Arrays, you just can filter them if you know the exact value of an element but is not possible to filter from a property of the element. As a workaround, you can use an array of ids of the complex property and filter for that property as in the example above._

##### Filter combinators

All the filters can be combined to create a more complex search on the same properties of the ReadModel.

| Filter | Value | Description |
| :----- | :-----------: | -----------------------------------------------: |
| and | [Filters] | AND - all filters on the list have a match |
| or | [Filters] | OR - At least one filter of the list has a match |
| not | Filter/and/or | The element does not match the filter |

Example:

```graphql
query {
CartReadModels(filter: { or: [{ id: { contains: "a" } }, { id: { contains: "b" } }] }) {
id
price
itemsIds
}
}
```

### Getting and filtering read models data at code level
adriangmweb marked this conversation as resolved.
Show resolved Hide resolved

Booster allows you to get your read models data in your commands handlers and event handlers using the `Booster.readModel` method.

Expand Down Expand Up @@ -746,4 +883,4 @@ export class GetProductsCount {
}
```

> **Warning**: Notice that `ReadModel`s are eventually consistent objects that are calculated as all events in all entities that affect the read model are settled. You should not assume that a read model is a proper source of truth, so you shouldn't use this feature for data validations. If you need to query the most up-to-date current state, consider fetching your Entities, instead of ReadModels, with `Booster.fetchEntitySnapshot`
> **Warning**: Notice that `ReadModel`s are eventually consistent objects that are calculated as all events in all entities that affect the read model are settled. You should not assume that a read model is a proper source of truth, so you shouldn't use this feature for data validations. If you need to query the most up-to-date current state, consider fetching your Entities, instead of ReadModels, with `Booster.entity`
Loading