### Start Example Application Source: https://github.com/tripss/nestjs-query/blob/master/CONTRIBUTING.md Starts a specific example application within the NestJS Query project. Replace `{example-name}` with the desired example's directory name. ```bash npm run start -- {example-name} ``` -------------------------------- ### Set up NestJS App and Install Dependencies Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Installs the NestJS CLI globally and creates a new NestJS project. It also installs additional dependencies like 'pg' and 'apollo-server-express' for database and GraphQL integration. ```sh npm i -g @nestjs/cli nest new nestjs-query-getting-started npm i pg apollo-server-express ``` -------------------------------- ### Run E2E Tests with Jest Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/contributing.md Executes end-to-end tests located in the examples directory. Requires starting backing services first using Docker Compose. ```bash cd ./examples docker compose up -d npm run jest:e2e ``` -------------------------------- ### NestJS App Module Setup with GraphQL and TypeORM Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Configures the main AppModule for a NestJS application. It sets up the GraphQLModule with ApolloDriver and integrates TypeOrmModule for database connection. This snippet is a starting point for connecting different modules, including the TodoItemModule. ```typescript import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; import { Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { TodoItemModule } from './todo-item/todo-item.module'; ``` -------------------------------- ### Install and Build NestJS Query Project Source: https://github.com/tripss/nestjs-query/blob/master/CONTRIBUTING.md Commands to install project dependencies, bootstrap the environment, and build the project. These are essential steps before writing new code or tests. ```bash npm install npm run bootstrap npm run build ``` -------------------------------- ### Docker Compose Configuration for NestJS Project Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Defines the Docker services required to run the NestJS project, including PostgreSQL, MongoDB, and Mongo Express for database management. This file simplifies the setup of development and production environments. ```yaml services: postgres: image: "postgres:17" environment: - "POSTGRES_USER=gettingstarted" - "POSTGRES_DB=gettingstarted" - "POSTGRES_PASSWORD=gettingstarted" expose: - "5432" ports: - "5432:5432" # only needed if using mongoose mongo: image: "mongo:4.4" restart: always ports: - "27017:27017" mongo-express: image: "mongo-express:latest" restart: always ports: - 8081:8081 ``` -------------------------------- ### GraphQL Mutation: Create TodoItem Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Example GraphQL mutation to create a new TodoItem. ```APIDOC ## GraphQL Mutation: Create TodoItem ### Description Example GraphQL mutation to create a new TodoItem. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters N/A #### Request Body - **query** (String) - Required - The GraphQL query string. - **variables** (Object) - Optional - Variables for the query. - **input** (Object) - Required - Input object for creating a TodoItem. - **todoItem** (Object) - Required - The TodoItem data. - **title** (String) - Required - The title of the todo item. - **completed** (Boolean) - Required - The completion status of the todo item. ### Request Example ```graphql mutation { createOneTodoItem( input: { todoItem: { title: "Create One Todo Item", completed: false } } ) { id title completed created updated } } ``` ### Response #### Success Response (200) - **data** (Object) - The response data. - **createOneTodoItem** (Object) - The created TodoItem. - **id** (String) - The ID of the created todo item. - **title** (String) - The title of the created todo item. - **completed** (Boolean) - The completion status of the created todo item. - **created** (String) - The creation timestamp. - **updated** (String) - The last update timestamp. #### Response Example ```json { "data": { "createOneTodoItem": { "id": "1", "title": "Create One Todo Item", "completed": false, "created": "2020-01-01T00:43:16.000Z", "updated": "2020-01-01T00:43:16.000Z" } } } ``` ``` -------------------------------- ### NestJS App Module Configuration with TypeORM and GraphQL Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Configures the main NestJS application module, integrating TypeORM for PostgreSQL database connection and GraphQLModule for setting up a GraphQL API. It also includes TodoItemModule. This setup is suitable for projects requiring a relational database and GraphQL. ```typescript import { TypeOrmModule, } from '@nestjs/typeorm'; import { GraphQLModule, ApolloDriver, ApolloDriverConfig, } from '@nestjs/graphql'; import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { TodoItemModule } from './todo-item/todo-item.module'; @Module({ imports: [ TypeOrmModule.forRoot({ type: 'postgres', database: 'gettingstarted', username: 'gettingstarted', password: 'gettingstarted', autoLoadEntities: true, synchronize: true, logging: true, }), GraphQLModule.forRoot({ driver: ApolloDriver, // set to true to automatically generate schema autoSchemaFile: true, }), TodoItemModule, ], controllers: [AppController], providers: [AppService], }) export class AppModule {} ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Docker Compose file to set up PostgreSQL, MongoDB, and Mongo Express services. ```APIDOC ## Docker Compose Configuration ### Description Docker Compose file to set up PostgreSQL, MongoDB, and Mongo Express services. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Install Nestjs-Query Packages Source: https://context7.com/tripss/nestjs-query/llms.txt Installs the core nestjs-query packages and an ORM-specific package for integration. Choose one ORM package based on your project's needs. ```bash # Core packages npm install @ptc-org/nestjs-query-core @ptc-org/nestjs-query-graphql # Choose one ORM package: npm install @ptc-org/nestjs-query-typeorm # For TypeORM npm install @ptc-org/nestjs-query-sequelize # For Sequelize npm install @ptc-org/nestjs-query-mongoose # For Mongoose npm install @ptc-org/nestjs-query-typegoose # For Typegoose ``` -------------------------------- ### GraphQL Aggregation Query Example Source: https://context7.com/tripss/nestjs-query/llms.txt Demonstrates how to perform aggregation queries in GraphQL, including grouping by fields, and calculating count, sum, average, minimum, and maximum values. The example shows a query for todo item statistics. ```graphql # GraphQL Query - Aggregate with groupBy query TodoItemStats { todoItemAggregate(filter: { created: { gte: "2024-01-01" } }) { groupBy { completed created(by: MONTH) } count { id } sum { priority } avg { priority } min { created priority } max { created priority } } } # Response { "data": { "todoItemAggregate": [ { "groupBy": { "completed": false, "created": "2024-01-01T00:00:00.000Z" }, "count": { "id": 15 }, "sum": { "priority": 45 }, "avg": { "priority": 3 }, "min": { "created": "2024-01-02T08:00:00.000Z", "priority": 1 }, "max": { "created": "2024-01-31T18:00:00.000Z", "priority": 5 } }, { "groupBy": { "completed": true, "created": "2024-01-01T00:00:00.000Z" }, "count": { "id": 8 }, "sum": { "priority": 20 }, "avg": { "priority": 2.5 }, "min": { "created": "2024-01-05T10:00:00.000Z", "priority": 1 }, "max": { "created": "2024-01-28T14:00:00.000Z", "priority": 4 } } ] } } ``` -------------------------------- ### NestJS App Module Configuration with Mongoose and GraphQL Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Configures the NestJS application module for use with Mongoose and GraphQL. This setup is suitable for projects utilizing MongoDB as the database and requiring a GraphQL API. ```typescript import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; import { Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import { MongooseModule } from '@nestjs/mongoose'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { TodoItemModule } from './todo-item/todo-item.module'; @Module({ imports: [ MongooseModule.forRoot('mongodb://localhost/nest', options), GraphQLModule.forRoot({ driver: ApolloDriver, // set to true to automatically generate schema autoSchemaFile: true, }), TodoItemModule, ], controllers: [AppController], providers: [AppService], }) export class AppModule {} ``` -------------------------------- ### NestJS App Module with Sequelize Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Configuration for the NestJS application module using Sequelize for PostgreSQL persistence. ```APIDOC ## NestJS App Module with Sequelize ### Description Configuration for the NestJS application module using Sequelize for PostgreSQL persistence. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Conventional Commit Example Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/contributing.md Illustrates the format for conventional commits, which includes a type, optional scope, and a summary. This helps in standardizing commit messages for better changelog generation and project understanding. ```git feat(core): add new authentication module ^--^ ^--------------------------------^ | | | +-> Summary in present tense. | +-------> Type: chore, docs, feat, fix, refactor, style, or test. ``` -------------------------------- ### NestJS App Module with TypeORM Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Configuration for the NestJS application module using TypeORM for PostgreSQL persistence. ```APIDOC ## NestJS App Module with TypeORM ### Description Configuration for the NestJS application module using TypeORM for PostgreSQL persistence. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### GraphQL Filtering Example Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/graphql/queries/filtering.mdx This example demonstrates how to filter todo items based on their 'completed' status using GraphQL. ```APIDOC ## GET /todoItems ### Description Retrieves a list of todo items, with the ability to filter based on various criteria. This example specifically shows filtering for completed items. ### Method GET ### Endpoint /todoItems ### Query Parameters #### Path Parameters None #### Query Parameters - **filter** (object) - Required - An object defining the filtering criteria. For example, `{completed: {is: true}}`. ### Request Example ```graphql { todoItems(filter: {completed: {is: true}}) { pageInfo { hasNextPage hasPreviousPage startCursor endCursor } edges { node { id title completed created updated } cursor } } } ``` ### Response #### Success Response (200) - **data** (object) - The response data containing the filtered todo items. - **todoItems** (object) - Contains pagination information and a list of todo items. - **pageInfo** (object) - Pagination details. - **edges** (array) - An array of todo item edges, each containing a node and cursor. - **node** (object) - The todo item object with its properties (id, title, completed, created, updated). - **cursor** (string) - The cursor for pagination. #### Response Example ```json { "data": { "todoItems": { "pageInfo": { "hasNextPage": false, "hasPreviousPage": false, "startCursor": "YXJyYXljb25uZWN0aW9uOjA=", "endCursor": "YXJyYXljb25uZWN0aW9uOjE=" }, "edges": [ { "node": { "id": "3", "title": "Create Many Todo Items - 2", "completed": true, "created": "2020-01-14T07:00:34.111Z", "updated": "2020-01-14T07:00:34.111Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjA=" }, { "node": { "id": "5", "title": "Create Many Todo Items - 4", "completed": true, "created": "2020-01-14T07:01:27.805Z", "updated": "2020-01-14T07:01:27.805Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjE=" } ] } } } ``` ``` -------------------------------- ### Run All Tests with Jest Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/contributing.md Executes all tests, including unit and E2E tests. Requires backing services to be started for E2E tests. ```bash npm run jest ``` -------------------------------- ### Query All TodoItems Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Retrieves a paginated list of all todo items. Includes pagination information and details for each todo item. ```APIDOC ## GET /graphql ### Description Queries for all todo items with pagination. ### Method GET ### Endpoint /graphql ### Query Parameters - **query** (string) - Required - The GraphQL query string. ### Request Example ```json { "query": "{ todoItems { pageInfo { hasNextPage hasPreviousPage startCursor endCursor } edges { node { id title completed created updated } cursor } } }" } ``` ### Response #### Success Response (200) - **data.todoItems** (object) - Contains pagination information and a list of todo items. - **pageInfo** (object) - Pagination details. - **hasNextPage** (boolean) - Indicates if there is a next page. - **hasPreviousPage** (boolean) - Indicates if there is a previous page. - **startCursor** (string) - The cursor for the start of the current page. - **endCursor** (string) - The cursor for the end of the current page. - **edges** (array) - An array of todo item edges. - **node** (object) - The todo item object. - **id** (string) - The unique identifier of the todo item. - **title** (string) - The title of the todo item. - **completed** (boolean) - The completion status of the todo item. - **created** (string) - The timestamp when the todo item was created. - **updated** (string) - The timestamp when the todo item was last updated. - **cursor** (string) - The cursor for this specific item. #### Response Example ```json { "data": { "todoItems": { "pageInfo": { "hasNextPage": false, "hasPreviousPage": false, "startCursor": "YXJyYXljb25uZWN0aW9uOjA=", "endCursor": "YXJyYXljb25uZWN0aW9uOjI=" }, "edges": [ { "node": { "id": "1", "title": "Create One Todo Item", "completed": false, "created": "2020-01-01T00:43:16.000Z", "updated": "2020-01-01T00:43:16.000Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjA=" }, { "node": { "id": "2", "title": "Create Many Todo Items - 1", "completed": false, "created": "2020-01-01T00:49:01.000Z", "updated": "2020-01-01T00:49:01.000Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjE=" }, { "node": { "id": "3", "title": "Create Many Todo Items - 2", "completed": true, "created": "2020-01-01T00:49:01.000Z", "updated": "2020-01-01T00:49:01.000Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjI=" } ] } } } ``` ``` -------------------------------- ### NestJS App Module with Typegoose Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Configuration for the NestJS application module using Typegoose for MongoDB persistence. ```APIDOC ## NestJS App Module with Typegoose ### Description Configuration for the NestJS application module using Typegoose for MongoDB persistence. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Conventional Commit Example Source: https://github.com/tripss/nestjs-query/blob/master/CONTRIBUTING.md Illustrates the format for commit messages following the Conventional Commits specification. This includes a type, an optional scope, and a subject. ```text feat: allow overriding of webpack config ^--^ ^--------------------------------^ | | | +-> Summary in present tense. | +-------> Type: chore, docs, feat, fix, refactor, style, or test. ``` -------------------------------- ### NestJS App Module with Mongoose Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Configuration for the NestJS application module using Mongoose for MongoDB persistence. ```APIDOC ## NestJS App Module with Mongoose ### Description Configuration for the NestJS application module using Mongoose for MongoDB persistence. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### OffsetConnection Example Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/graphql/relations.mdx Illustrates the use of @OffsetConnection to automatically generate endpoints for querying and mutating related entities with offset-based pagination. ```APIDOC ## Query: todoItem.subTasks ### Description This query retrieves a paginated list of `SubTasks` related to a specific `TodoItem` using offset-based pagination. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **paging** (Object) - Optional - Configuration for offset-based pagination. - **limit** (Int) - Optional - The maximum number of results to return. Defaults to 10. - **offset** (Int) - Optional - The number of results to skip. - **filter** (Object) - Optional - Filter criteria for `SubTasks`. - **sorting** (Array) - Optional - Array of sorting criteria for `SubTasks`. ### Request Example ```graphql { todoItem(id: "1") { subTasks(paging: { limit: 5 }, filter: { completed: { is: true } }) { edges { node { id title completed } cursor } pageInfo { hasNextPage hasPreviousPage startCursor endCursor } } } } ``` ### Response #### Success Response (200) - **data** (Object) - The response data containing the queried `TodoItem` and its `subTasks`. - **todoItem** (Object) - The `TodoItem` object. - **subTasks** (Object) - Connection object for `SubTasks`. - **edges** (Array) - Array of `SubTask` edges. - **node** (Object) - The `SubTask` object. - **id** (ID) - The unique identifier of the `SubTask`. - **title** (String) - The title of the `SubTask`. - **completed** (Boolean) - The completion status of the `SubTask`. - **cursor** (String) - The cursor for pagination. - **pageInfo** (Object) - Information about the pagination. #### Response Example ```json { "data": { "todoItem": { "subTasks": { "edges": [ { "node": { "id": "sub1", "title": "Task A", "completed": true }, "cursor": "cursorA" } ], "pageInfo": { "hasNextPage": false, "hasPreviousPage": false, "startCursor": "cursorA", "endCursor": "cursorA" } } } } } ``` ## Mutation: addSubTasksToTodoItem ### Description This mutation adds existing `SubTasks` to a `TodoItem`. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **input** (Object) - Required - Input object for the mutation. - **id** (ID) - Required - The ID of the `TodoItem` to which `SubTasks` will be added. - **relationIds** (Array) - Required - An array of IDs of the `SubTasks` to add. ### Request Example ```graphql mutation { addSubTasksToTodoItem(input: { id: "1", relationIds: ["sub1", "sub2"] }) { id title } } ``` ### Response #### Success Response (200) - **data** (Object) - The response data containing the updated `TodoItem`. - **addSubTasksToTodoItem** (Object) - The updated `TodoItem` object. - **id** (ID) - The ID of the updated `TodoItem`. - **title** (String) - The title of the updated `TodoItem`. #### Response Example ```json { "data": { "addSubTasksToTodoItem": { "id": "1", "title": "Updated Todo Item" } } } ``` ## Mutation: removeSubTasksFromTodoItem (Conditional) ### Description This mutation removes `SubTasks` from a `TodoItem`. This mutation is exposed only if `remove.enabled` is set to `true` in the `NestjsQueryGraphQLModule` configuration. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **input** (Object) - Required - Input object for the mutation. - **id** (ID) - Required - The ID of the `TodoItem` from which `SubTasks` will be removed. - **relationIds** (Array) - Required - An array of IDs of the `SubTasks` to remove. ### Request Example ```graphql mutation { removeSubTasksFromTodoItem(input: { id: "1", relationIds: ["sub1"] }) { id title } } ``` ### Response #### Success Response (200) - **data** (Object) - The response data containing the updated `TodoItem`. - **removeSubTasksFromTodoItem** (Object) - The updated `TodoItem` object. - **id** (ID) - The ID of the updated `TodoItem`. - **title** (String) - The title of the updated `TodoItem`. #### Response Example ```json { "data": { "removeSubTasksFromTodoItem": { "id": "1", "title": "Updated Todo Item" } } } ``` ``` -------------------------------- ### Query Completed TodoItems Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Retrieves a paginated list of todo items that are marked as completed. Includes pagination information and details for each completed todo item. ```APIDOC ## GET /graphql ### Description Queries for completed todo items with pagination. ### Method GET ### Endpoint /graphql ### Query Parameters - **query** (string) - Required - The GraphQL query string. ### Request Example ```json { "query": "{ todoItems(filter: { completed: { is: true } }) { pageInfo { hasNextPage hasPreviousPage startCursor endCursor } edges { node { id title completed created updated } cursor } } }" } ``` ### Response #### Success Response (200) - **data.todoItems** (object) - Contains pagination information and a list of completed todo items. - **pageInfo** (object) - Pagination details. - **hasNextPage** (boolean) - Indicates if there is a next page. - **hasPreviousPage** (boolean) - Indicates if there is a previous page. - **startCursor** (string) - The cursor for the start of the current page. - **endCursor** (string) - The cursor for the end of the current page. - **edges** (array) - An array of todo item edges. - **node** (object) - The todo item object. - **id** (string) - The unique identifier of the todo item. - **title** (string) - The title of the todo item. - **completed** (boolean) - The completion status of the todo item. - **created** (string) - The timestamp when the todo item was created. - **updated** (string) - The timestamp when the todo item was last updated. - **cursor** (string) - The cursor for this specific item. #### Response Example ```json { "data": { "todoItems": { "pageInfo": { "hasNextPage": false, "hasPreviousPage": false, "startCursor": "YXJyYXljb25uZWN0aW9uOjA=", "endCursor": "YXJyYXljb25uZWN0aW9uOjA=" }, "edges": [ { "node": { "id": "3", "title": "Create Many Todo Items - 2", "completed": true, "created": "2020-01-01T00:49:01.000Z", "updated": "2020-01-01T00:49:01.000Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjA=" } ] } } } ``` ``` -------------------------------- ### Create Multiple TodoItems Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Allows for the creation of multiple todo items in a single request. It takes an array of todo item objects as input and returns the created items with their IDs and timestamps. ```APIDOC ## POST /graphql ### Description Creates multiple todo items. ### Method POST ### Endpoint /graphql ### Request Body - **input** (object) - Required - Input object containing an array of todo items. - **todoItems** (array) - Required - Array of todo item objects to create. - **title** (string) - Required - The title of the todo item. - **completed** (boolean) - Required - The completion status of the todo item. ### Request Example ```json { "mutation": "mutation { createManyTodoItems(input: { todoItems: [ { title: \"Create Many Todo Items - 1\", completed: false }, { title: \"Create Many Todo Items - 2\", completed: true } ] }) { id title completed created updated } }" } ``` ### Response #### Success Response (200) - **data.createManyTodoItems** (array) - An array of the created todo items. - **id** (string) - The unique identifier of the todo item. - **title** (string) - The title of the todo item. - **completed** (boolean) - The completion status of the todo item. - **created** (string) - The timestamp when the todo item was created. - **updated** (string) - The timestamp when the todo item was last updated. #### Response Example ```json { "data": { "createManyTodoItems": [ { "id": "2", "title": "Create Many Todo Items - 1", "completed": false, "created": "2020-01-01T00:49:01.000Z", "updated": "2020-01-01T00:49:01.000Z" }, { "id": "3", "title": "Create Many Todo Items - 2", "completed": true, "created": "2020-01-01T00:49:01.000Z", "updated": "2020-01-01T00:49:01.000Z" } ] } } ``` ``` -------------------------------- ### Serve Documentation Locally with Docusaurus Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/contributing.md Builds and serves the project documentation locally using Docusaurus. This allows for previewing documentation changes before deployment. ```bash cd ./documentation npm install npm run start ``` -------------------------------- ### Delete Many Records with NestJS Query Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/graphql/mutations.mdx Deletes multiple records based on a provided filter. This example shows how to delete records whose titles start with a specific string. The filter cannot be empty to prevent accidental mass deletion. ```graphql mutation { deleteManyTodoItems( input: { filter: { title: { like: "Create Many Todo Items%" } } } ) { deletedCount } } ``` ```json { "data": { "deleteManyTodoItems": { "deletedCount": 6 } } } ``` -------------------------------- ### Remove Public ConnectionType and SortType Functions (TypeScript) Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/migration-guides/v0.23.x-to-v0.24.x.mdx In NestJS Query v0.24.0, the public ConnectionType and SortType functions were removed. Previously, these were used to get references to Connection and Sort GraphQL implementations. The new approach involves obtaining these from QueryArgs, which helps prevent the creation of incompatible types. ```typescript import { ConnectionType, SortType } from '@ptc-org/nestjs-query-graphql'; import { TodoItemDTO } from './dto/todo-item.dto'; export const TodoItemConnection = ConnectionType(TodoItemDTO); export const TodoItemSort = SortType(TodoItemDTO); ``` ```typescript import { QueryArgsType } from '@ptc-org/nestjs-query-graphql'; import { TodoItemDTO } from './dto/todo-item.dto'; export const TodoItemQueryArgs = QueryArgsType(TodoItemDTO) export const TodoItemConnection = TodoItemQueryArgs.ConnectionType; export const TodoItemSort = TodoItemQueryArgs.SortType; ``` -------------------------------- ### Serve Documentation Locally with Docusaurus Source: https://github.com/tripss/nestjs-query/blob/master/CONTRIBUTING.md Builds and serves the project's documentation locally using Docusaurus. This allows developers to preview documentation changes before committing. ```bash nx serve documentation ``` -------------------------------- ### NestJS App Module Configuration with Typegoose and GraphQL Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Demonstrates the configuration of a NestJS application module using Typegoose for MongoDB integration and GraphQL. This is an alternative for projects using MongoDB with a more TypeScript-centric approach. ```typescript import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; import { Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import { TypegooseModule } from '@m8a/nestjs-typegoose'; import { TodoItemModule } from './todo-item/todo-item.module'; @Module({ imports: [ TypegooseModule.forRoot('mongodb://localhost/nest', options), GraphQLModule.forRoot({ driver: ApolloDriver, // set to true to automatically generate schema autoSchemaFile: true, }), TodoItemModule, ], }) export class AppModule {} ``` -------------------------------- ### GraphQL Sorting Response Example Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/graphql/queries/sorting.mdx Provides an example of the JSON response structure when sorting is applied to a GraphQL query for todo items. This helps in understanding the output format. ```json { "data": { "todoItems": { "pageInfo": { "hasNextPage": false, "hasPreviousPage": false, "startCursor": "YXJyYXljb25uZWN0aW9uOjA=", "endCursor": "YXJyYXljb25uZWN0aW9uOjQ=" }, "edges": [ { "node": { "id": "1", "title": "Create One Todo Item", "completed": false, "created": "2020-01-14T07:00:31.763Z", "updated": "2020-01-14T07:00:31.763Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjA=" }, { "node": { "id": "5", "title": "Create Many Todo Items - 4", "completed": true, "created": "2020-01-14T07:01:27.805Z", "updated": "2020-01-14T07:01:27.805Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjE=" }, { "node": { "id": "4", "title": "Create Many Todo Items - 3", "completed": false, "created": "2020-01-14T07:01:27.805Z", "updated": "2020-01-14T07:01:27.805Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjI=" }, { "node": { "id": "3", "title": "Create Many Todo Items - 2", "completed": true, "created": "2020-01-14T07:00:34.111Z", "updated": "2020-01-14T07:00:34.111Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjM=" }, { "node": { "id": "2", "title": "Create Many Todo Items - 1", "completed": false, "created": "2020-01-14T07:00:34.111Z", "updated": "2020-01-14T07:00:34.111Z" }, "cursor": "YXJyYXljb25uZWN0aW9uOjQ=" } ] } } } ``` -------------------------------- ### Configure Multiple TypeORM Connections in AppModule Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/persistence/typeorm/multiple-databases.md This example demonstrates setting up multiple database connections within the AppModule using TypeOrmModule. It includes both a default connection and a named connection configured asynchronously. Ensure that named connections have a 'name' property specified. ```typescript import { MUSIC_DB_CONNECTION, SECRET_DB_CONNECTION, } from './constants'; const musicEntities = [ ArtistEntity, AlbumEntity, SongEntity, GenreEntity, // ... ]; const secretEntities = [SecretEntity]; @Module({ imports: [ ConfigModule.forRoot(environment), TypeOrmModule.forRoot({ // name: MUSIC_DB_CONNECTION, // if you leave this out, this will be the "default" connection! type: "postgres", host: "localhost", port: 5436, username: 'user', password: 'password', database: 'music', synchronize: true, logging: true, entities: musicEntities, }), // this also works with the ASYNC configuration! TypeOrmModule.forRootAsync({ name: SECRET_DB_CONNECTION, // you need to set the name here! imports: [ConfigModule], inject: [ConfigService], useFactory: (configService: ConfigService): TypeOrmModuleOptions => ({ ...configService.get('dbConnections.secret'), entities: secretEntities, }), }), GraphQLModule.forRootAsync({ // ... }), // other modules ], controllers: [], providers: [], }) export class AppModule {} ``` -------------------------------- ### Get By Id Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/persistence/services.mdx Retrieves a single record by its ID, throwing an error if not found. ```APIDOC ## GET /:id (Strict) ### Description Retrieves a single record by its ID. Throws an exception if the record is not found. ### Method GET ### Endpoint /:id ### Parameters #### Path Parameters - **id** (number) - Required - The ID of the record to retrieve. ### Response #### Success Response (200) - **record** (object) - The retrieved record. #### Error Response (404) - **message** (string) - Error message indicating the record was not found. #### Response Example ```json { "id": 1, "title": "Example Todo", "completed": false } ``` ``` -------------------------------- ### FilterableUnPagedRelation Example Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/graphql/relations.mdx Demonstrates how to use @FilterableUnPagedRelation to enable filtering on related entities in GraphQL queries. ```APIDOC ## POST /graphql ### Description This endpoint allows querying `TodoItems` with filters applied to their related `subTasks`. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **filter** (Object) - Optional - Filter criteria for `TodoItems` and their relations. - **subTasks** (Object) - Optional - Filter criteria for the `subTasks` relation. - **completed** (Object) - Optional - Filter criteria for the `completed` field of `subTasks`. - **is** (Boolean) - Optional - Filter for `subTasks` where `completed` is true. ### Request Example ```graphql { todoItems(filter: { subTasks: { completed: { is: true } } }) { pageInfo { hasNextPage hasPreviousPage startCursor endCursor } edges { node { id title description completed subTasks { title description completed } } cursor } } } ``` ### Response #### Success Response (200) - **data** (Object) - The response data containing the queried `todoItems`. - **todoItems** (Object) - Connection object for `TodoItems`. - **pageInfo** (Object) - Information about the pagination. - **edges** (Array) - Array of `TodoItem` edges. - **node** (Object) - The `TodoItem` object. - **id** (ID) - The unique identifier of the `TodoItem`. - **title** (String) - The title of the `TodoItem`. - **description** (String) - The description of the `TodoItem`. - **completed** (Boolean) - The completion status of the `TodoItem`. - **subTasks** (Array) - Array of related `SubTaskDTO` objects. - **cursor** (String) - The cursor for pagination. #### Response Example ```json { "data": { "todoItems": { "pageInfo": { "hasNextPage": true, "hasPreviousPage": false, "startCursor": "cursor1", "endCursor": "cursor2" }, "edges": [ { "node": { "id": "1", "title": "Learn NestJS", "description": "Study NestJS documentation", "completed": false, "subTasks": [ { "title": "Read basics", "description": "Understand core concepts", "completed": true } ] }, "cursor": "cursor1" } ] } } } ``` ``` -------------------------------- ### Build All Nestjs-Query Packages Source: https://github.com/tripss/nestjs-query/blob/master/README.md This command builds all packages within the Nestjs-Query project. It's a foundational step for development and testing, ensuring all modules are compiled. ```bash yarn nx run-many --target=build --all ``` -------------------------------- ### Delete Many TodoItems Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Deletes multiple TodoItems based on a filter, allowing for bulk deletion. ```APIDOC ## POST /graphql ### Description Deletes multiple TodoItems that match the provided filter criteria. Returns the count of deleted items. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **query** (string) - The GraphQL mutation query. - **variables** (object) - Optional variables for the mutation. ### Request Example ```json { "query": "mutation { deleteManyTodoItems(input: { filter: { title: { like: \"Create Many Todo Items%\" } } }) { deletedCount } }" } ``` ### Response #### Success Response (200) - **data** (object) - The response data. - **deleteManyTodoItems** (object) - Details about the delete operation. - **deletedCount** (integer) - The number of TodoItems that were deleted. #### Response Example ```json { "data": { "deleteManyTodoItems": { "deletedCount": 2 } } } ``` ``` -------------------------------- ### Update Many TodoItems Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Updates multiple TodoItems based on specified filters, allowing bulk modifications. ```APIDOC ## POST /graphql ### Description Updates multiple TodoItems that match the provided filter criteria. Returns the count of updated items. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **query** (string) - The GraphQL mutation query. - **variables** (object) - Optional variables for the mutation. ### Request Example ```json { "query": "mutation { updateManyTodoItems(input: { filter: { id: { in: [1, 2] } }, update: { completed: true } }) { updatedCount } }" } ``` ### Response #### Success Response (200) - **data** (object) - The response data. - **updateManyTodoItems** (object) - Details about the update operation. - **updatedCount** (integer) - The number of TodoItems that were updated. #### Response Example ```json { "data": { "updateManyTodoItems": { "updatedCount": 2 } } } ``` ``` -------------------------------- ### GraphQL Response for Creating a TodoItem Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx The JSON response received after successfully executing the 'createOneTodoItem' GraphQL mutation. It includes the details of the newly created todo item, such as its ID, title, completion status, and timestamps. ```json { "data": { "createOneTodoItem": { "id": "1", "title": "Create One Todo Item", "completed": false, "created": "2020-01-01T00:43:16.000Z", "updated": "2020-01-01T00:43:16.000Z" } } } ``` -------------------------------- ### Update One TodoItem Source: https://github.com/tripss/nestjs-query/blob/master/documentation/docs/introduction/example.mdx Updates a single TodoItem, allowing modification of its properties like 'completed' status. ```APIDOC ## POST /graphql ### Description Updates a single TodoItem. You can specify the ID of the item to update and the fields to change. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **query** (string) - The GraphQL mutation query. - **variables** (object) - Optional variables for the mutation. ### Request Example ```json { "query": "mutation { updateOneTodoItem(input: { id: 3, update: { completed: false } }) { id title completed created updated } }" } ``` ### Response #### Success Response (200) - **data** (object) - The response data containing the updated TodoItem. - **updateOneTodoItem** (object) - Details of the updated TodoItem. - **id** (string) - The unique identifier of the TodoItem. - **title** (string) - The title of the TodoItem. - **completed** (boolean) - The completion status of the TodoItem. - **created** (string) - The timestamp when the TodoItem was created. - **updated** (string) - The timestamp when the TodoItem was last updated. #### Response Example ```json { "data": { "updateOneTodoItem": { "id": "3", "title": "Create Many Todo Items - 2", "completed": false, "created": "2020-01-13T09:19:46.727Z", "updated": "2020-01-13T09:23:37.658Z" } } } ``` ```