-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
14 changed files
with
797 additions
and
405 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
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
--- | ||
title: Aggregation | ||
description: Execute aggregation queries | ||
--- | ||
|
||
import {TabItem, Tabs} from '@astrojs/starlight/components'; | ||
|
||
FastGQL auto extends the schema using the `@generate` directive to add aggregation queries to the extended types. Aggregation results can be accessed using the `_[fieldName]Aggregate` field in the GraphQL query.  | ||
|
||
FastGQL supports the following aggregation operations: `count`, `sum`, `avg`, `min`, `max`. | ||
|
||
## Count Aggregate | ||
|
||
```graphql | ||
query { | ||
_postsAggregate { | ||
count | ||
} | ||
} | ||
``` | ||
|
||
## Aggregate Filter | ||
|
||
Similar to [filter ](filtering.mdx)queries we can filter our aggregate queries to returned different results. The following example will count all posts that have a category with the `id == 1` . | ||
|
||
```graphql | ||
query { | ||
_postsAggregate(filter: {categories: {id:{eq: 1}}}) { | ||
count | ||
} | ||
} | ||
``` | ||
|
||
## Group By | ||
|
||
Group by is used to group the results based on the given field. The following example will group all posts based on the `NAME` and return the count of posts in each group. | ||
We can GroupBy multiple fields by providing an array of fields, or a single field. The group field will be an object with the grouped fields as keys. | ||
|
||
|
||
|
||
|
||
<Tabs> | ||
<TabItem label="Single"> | ||
```graphql | ||
query { | ||
_postsAggregate(groupBy: [NAME]) { | ||
group | ||
count | ||
} | ||
} | ||
``` | ||
</TabItem> | ||
<TabItem label="Multiple"> | ||
```graphql | ||
query { | ||
_postsAggregate(groupBy: [USER_ID, NAME]) { | ||
group | ||
count | ||
} | ||
} | ||
``` | ||
</TabItem> | ||
</Tabs> |
86 changes: 43 additions & 43 deletions
86
docs/src/content/docs/queries/ordering.md → docs/src/content/docs/queries/ordering.mdx
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,43 +1,43 @@ | ||
--- | ||
title: Ordering | ||
description: Sort query results | ||
--- | ||
|
||
We can sort query results using the `orderBy` argument that is added when extending the schema with fastGQL. The value of the sort argument should be an array containing the name of fields to sort the result by. | ||
|
||
{% hint style="info" %} | ||
Ordering is ALPHA so it API might change in future versions | ||
{% endhint %} | ||
|
||
## Simple Sort | ||
|
||
```graphql | ||
query { | ||
posts(orderBy: {name: ASC}) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
## Multiple fields | ||
|
||
```graphql | ||
query { | ||
posts(orderBy: [{name: ASC}, {id: DESC}]) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
## Sorting Nested Queries | ||
|
||
```graphql | ||
query { | ||
posts(orderBy: {name: DESC}) { | ||
name | ||
categories(orderBy: {name: ASC_NULL_FIRST}) { | ||
name | ||
} | ||
} | ||
} | ||
``` | ||
--- | ||
title: Ordering | ||
description: Sort query results | ||
--- | ||
|
||
:::note[Experimental API] | ||
Ordering API is experimental and may change in the future. | ||
::: | ||
|
||
We can sort query results using the `orderBy` argument that is added when extending the schema with fastGQL. The value of the sort argument should be an array containing the name of fields to sort the result by. | ||
|
||
## Simple Sort | ||
|
||
```graphql | ||
query { | ||
posts(orderBy: {name: ASC}) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
## Multiple fields | ||
|
||
```graphql | ||
query { | ||
posts(orderBy: [{name: ASC}, {id: DESC}]) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
## Sorting Nested Queries | ||
|
||
```graphql | ||
query { | ||
posts(orderBy: {name: DESC}) { | ||
name | ||
categories(orderBy: {name: ASC_NULL_FIRST}) { | ||
name | ||
} | ||
} | ||
} | ||
``` |
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
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,82 @@ | ||
--- | ||
title: Custom Operators | ||
description: fastGQL custom operators type | ||
--- | ||
|
||
FastGQL defines a set of operators that can be used to extend the schema. These operators are defined in the `fastgql.graphql` file. | ||
These operators are used to run filters and queries on the database. By default, FastGQL supports common operators: | ||
|
||
- `eq` - equals | ||
- `ne` - not equals | ||
- `gt` - greater than | ||
- `lt` - less than | ||
- `gte` - greater than or equal | ||
- `lte` - less than or equal | ||
- `in` - in | ||
- `nin` - not in | ||
- `like` - like | ||
- `ilike` - ilike | ||
- `isNull` - is null | ||
- `contains` - contains | ||
- `notContains` - not contains | ||
- `overlap` - overlap | ||
- `containedBy` - contained by | ||
- `suffix` - suffix | ||
- `prefix` - prefix | ||
|
||
## Adding Custom Operators | ||
|
||
FastGQL allows you to add custom operators to the schema. This can be done by defining a new input type in the `fastgql.graphql` file, | ||
or by adding a new operator to an existing input type, by extending the input type. | ||
|
||
```graphql | ||
|
||
# extend our input type to include a custom operator | ||
extend input StringComparator { | ||
# The custom operator to use for the comparison. | ||
myCustomOperator: String | ||
} | ||
``` | ||
|
||
We will define our custom operator to always do "1 = 1" | ||
|
||
```go | ||
func MyCustomOperator(table exp.AliasedExpression, key string, value interface{}) goqu.Expression { | ||
return goqu.L("1 = 1") | ||
} | ||
``` | ||
|
||
In our `serve.go` where we define our schema, we will add a resolver for the custom operator. | ||
|
||
```go | ||
cfg := &builders.Config{ | ||
Schema: executableSchema.Schema(), | ||
Logger: adapters.NewZerologAdapter(log.Logger), | ||
CustomOperators: map[string]builders.Operator{ | ||
"myCustomOperator": MyCustomOperator, | ||
}, | ||
} | ||
``` | ||
|
||
|
||
|
||
An example of a custom operator can be found [here](https://github.com/roneli/fastgql/tree/master/examples/custom_operator). | ||
|
||
|
||
## Adding FilterInputs for Custom Scalar Types | ||
|
||
Similar to how StringComparator is used to filter strings, you can define a custom input type to filter custom scalar types. | ||
|
||
```graphql | ||
|
||
# Define a custom scalar type | ||
scalar MyCustomScalar | ||
|
||
# Define a custom input type to filter the custom scalar type | ||
input MyCustomScalarComparator { | ||
eq: MyCustomScalar | ||
# The custom operator to use for the comparison. | ||
myCustomOperator: MyCustomScalar | ||
} | ||
``` | ||
|
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
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
Oops, something went wrong.