Skip to content

Commit

Permalink
update docs (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
roneli committed Jul 15, 2024
1 parent 937802e commit 016af2c
Show file tree
Hide file tree
Showing 14 changed files with 797 additions and 405 deletions.
22 changes: 14 additions & 8 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default defineConfig({
}, {
label: 'Setup',
link: '/start/setup',
badge: "New",
}]
}, {
label: 'Queries',
Expand Down Expand Up @@ -83,13 +82,20 @@ export default defineConfig({
label: 'Interfaces',
link: '/schema/interfaces',
badge: {text: 'Experimental', variant: 'caution'},
}, {
label: 'Directives',
link: '/schema/directives'
}, {
label: 'Schema',
link: '/schema/schema'
}]
},
{
label: 'Custom Operators',
link: '/schema/operators',
badge: 'New',
},
{
label: 'Directives',
link: '/schema/directives'
},
{
label: 'Schema',
link: '/schema/schema'
}]
}, {
label: 'Reference',
autogenerate: {
Expand Down
28 changes: 0 additions & 28 deletions docs/src/content/docs/queries/aggregation.md

This file was deleted.

63 changes: 63 additions & 0 deletions docs/src/content/docs/queries/aggregation.mdx
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>
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
}
}
}
```
12 changes: 10 additions & 2 deletions docs/src/content/docs/schema/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ title: Interfaces
description: fastGQL interface type
---

GraphQL support interfaces, most graphql
:::danger[Experimental API]
Interface is an experimental feature and might change in the future.
:::

GraphQL supports interfaces type, FastGQL allows to define interfaces in the schema and resolve them using a "type" field.

## Interface Example


An example using interface type can be found [here](https://github.com/roneli/fastgql/tree/master/examples/interface).

## Interface Example
82 changes: 82 additions & 0 deletions docs/src/content/docs/schema/operators.md
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
}
```

7 changes: 3 additions & 4 deletions docs/src/content/docs/start/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Feel free to open Pull-Request for small fixes and changes. For bigger changes a

## Roadmap 🚧

* More tests
* configurable database connections
* Support multiple database (mongodb, cockroachDB, neo4j)
* full CRUD creation
- Integration testing, and generation testing
- configurable database connections, augmenters and better schema control
- Support multiple database (mongodb, cockroachDB, neo4j)
7 changes: 3 additions & 4 deletions docs/src/content/docs/start/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ title: Setup FastGQL
description: How to setup fastGQL
---

This tutorial will take you through the process of building a GraphQL server with fastgql that can:
This tutorial will take you through the process of building a GraphQL server with fastgql that can:
automatically query, filter, order and pagination users, posts & categories from a postgres database.

* automatically query, filter, order and pagination users, posts & categories from a postgres database.

You can find the finished code for this tutorial [here](https://github.com/roneli/fastgql/tree/master/example).
You can find the finished code for this tutorial [here](https://github.com/roneli/fastgql/tree/master/example/tutorial).

If you are familiar with [gqlgen](https://gqlgen.com), the setup is nearly identical, with a little work in your Schema you won't need to define any resolvers!

Expand Down
Loading

0 comments on commit 016af2c

Please sign in to comment.