-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(graphql): Use the provided connection name (#204)
Fixes #201
- Loading branch information
Showing
26 changed files
with
4,146 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Connection } from 'typeorm' | ||
|
||
import { executeTruncate } from '../../helpers' | ||
import { SubTaskEntity } from '../src/sub-task/sub-task.entity' | ||
import { TagEntity } from '../src/tag/tag.entity' | ||
import { TodoItemEntity } from '../src/todo-item/todo-item.entity' | ||
|
||
const tables = ['todo_item', 'sub_task', 'tag'] | ||
export const truncate = async (connection: Connection): Promise<void> => executeTruncate(connection, tables) | ||
|
||
export const refresh = async (connection: Connection): Promise<void> => { | ||
await truncate(connection) | ||
|
||
const todoRepo = connection.getRepository(TodoItemEntity) | ||
const subTaskRepo = connection.getRepository(SubTaskEntity) | ||
const tagsRepo = connection.getRepository(TagEntity) | ||
|
||
const urgentTag = await tagsRepo.save({ name: 'Urgent' }) | ||
const homeTag = await tagsRepo.save({ name: 'Home' }) | ||
const workTag = await tagsRepo.save({ name: 'Work' }) | ||
const questionTag = await tagsRepo.save({ name: 'Question' }) | ||
const blockedTag = await tagsRepo.save({ name: 'Blocked' }) | ||
|
||
const todoItems = await todoRepo.save([ | ||
{ title: 'Create Nest App', completed: true, tags: [urgentTag, homeTag] }, | ||
{ title: 'Create Entity', completed: false, tags: [urgentTag, workTag] }, | ||
{ title: 'Create Entity Service', completed: false, tags: [blockedTag, workTag] }, | ||
{ title: 'Add Todo Item Resolver', completed: false, tags: [blockedTag, homeTag] }, | ||
{ | ||
title: 'How to create item With Sub Tasks', | ||
completed: false, | ||
tags: [questionTag, blockedTag] | ||
} | ||
]) | ||
|
||
await subTaskRepo.save( | ||
todoItems.reduce( | ||
(subTasks, todo) => [ | ||
...subTasks, | ||
{ completed: true, title: `${todo.title} - Sub Task 1`, todoItem: todo }, | ||
{ completed: false, title: `${todo.title} - Sub Task 2`, todoItem: todo }, | ||
{ completed: false, title: `${todo.title} - Sub Task 3`, todoItem: todo } | ||
], | ||
[] as Partial<SubTaskEntity>[] | ||
) | ||
) | ||
} |
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,55 @@ | ||
export const todoItemFields = ` | ||
id | ||
title | ||
completed | ||
description | ||
` | ||
|
||
export const subTaskFields = ` | ||
id | ||
title | ||
description | ||
completed | ||
todoItemId | ||
` | ||
|
||
export const tagFields = ` | ||
id | ||
name | ||
` | ||
|
||
export const offsetPageInfoField = ` | ||
pageInfo{ | ||
hasNextPage | ||
hasPreviousPage | ||
} | ||
` | ||
|
||
export const cursorPageInfoField = ` | ||
pageInfo{ | ||
hasNextPage | ||
hasPreviousPage | ||
startCursor | ||
endCursor | ||
} | ||
` | ||
|
||
export const nodes = (fields: string): string => ` | ||
nodes { | ||
${fields} | ||
} | ||
` | ||
|
||
export const offsetConnection = (fields: string): string => ` | ||
${nodes(fields)} | ||
${offsetPageInfoField} | ||
` | ||
|
||
export const edgeNodes = (fields: string): string => ` | ||
edges { | ||
node{ | ||
${fields} | ||
} | ||
cursor | ||
} | ||
` |
Oops, something went wrong.