Skip to content

Commit

Permalink
Fix for issue 42
Browse files Browse the repository at this point in the history
* [DOCS] Added clarification around individual resolvers and relations with examples #42
* [ADDED] Exposed `Relatable` mixin from `@nestjs-query/graphql` #42
  • Loading branch information
doug-martin committed Mar 3, 2020
1 parent 36732e4 commit 1217f5a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.5.1

* [DOCS] Added clarification around individual resolvers and relations with examples [#42](https://github.com/doug-martin/nestjs-query/issues/42)
* [ADDED] Exposed `Relatable` mixin from `@nestjs-query/graphql` [#42](https://github.com/doug-martin/nestjs-query/issues/42)

# v0.5.0

* Added `decorators` option to resolver options to allow providing custom decorators to endpoints [#36](https://github.com/doug-martin/nestjs-query/issues/36)
Expand Down
32 changes: 32 additions & 0 deletions documentation/docs/graphql/relations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,35 @@ export class TodoItemResolver extends CRUDResolver(TodoItemDTO, {
```

Now any requests that go to the `update` or `remove` endpoints will require the guard.

## Relation Mixin

If you are using the [resolvers individually](./resolvers#individual-resolvers) you can use the following mixins to add relations functionality.

### Relatable

When using The `Relatable` mixin adds all relations functionality to a resolver.

In this example we expose on read endpoints for todo items with a readable subtasks realtion.

```ts
import { ReadResolver, Relatable } from '@nestjs-query/query-graphql';
import { Resolver } from '@nestjs/graphql';
import { AuthGuard } from '../auth.guard';
import { SubTaskDTO } from '../sub-task/dto/sub-task.dto';
import { TodoItemDTO } from './dto/todo-item.dto';
import { TodoItemService } from './todo-item.service';

const guards = [AuthGuard];

@Resolver(() => TodoItemDTO)
export class TodoItemResolver extends Relatable(TodoItemDTO, {
many: {
subTasks: { DTO: SubTaskDTO, disableRemove: true, disableUpdate: true },
},
})(ReadResolver(TodoItemDTO)) {
constructor(readonly service: TodoItemService) {
super(service);
}
}
```
4 changes: 4 additions & 0 deletions documentation/docs/graphql/resolvers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,12 @@ export class TodoItemResolver extends CRUDResolver(TodoItemDTO, {
The `@nestjs-query/query-graphql` package exposes each part of `CRUD` into individual mixins and resolvers allowing you
to pick and choose what functionality you want to expose.

**NOTE** This is advanced usage of the resolvers API and is subject to change!

**NOTE** All examples below can be achieved with the options exposed through the `CRUDResolver`.

**NOTE** The following resolvers do not expose relations options, to add relations options see [Relateable](./relations#relatable)

### `CreateResolver`

The `CreateResolver` will only expose the `createOne` and `createMany` endpoints. The [options](#options) described for
Expand Down
3 changes: 2 additions & 1 deletion packages/query-graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './types';
export { FilterableField } from './decorators';
export { FilterableField, ResolverMethodOpts } from './decorators';
export * from './resolvers';
export { DTONamesOpts } from './common';
2 changes: 2 additions & 0 deletions packages/query-graphql/src/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export { CreateResolver, CreateResolverOpts } from './create.resolver';
export { ReadResolver, ReadResolverOpts } from './read.resolver';
export { UpdateResolver, UpdateResolverOpts } from './update.resolver';
export { DeleteResolver, DeleteResolverOpts } from './delete.resolver';
export { Relatable, RemoveRelationsResolver, ReadRelationsResolver, UpdateRelationsResolver } from './relations';
export { RelationsOpts, ResolverOpts, ResolverRelation } from './resolver.interface';

0 comments on commit 1217f5a

Please sign in to comment.