From af8f25c1a4b4b9e1fb7588cd500e7c4e6bffecc2 Mon Sep 17 00:00:00 2001 From: Ope Abidemi Harry Date: Thu, 13 Jan 2022 02:16:32 +0000 Subject: [PATCH] feat(cheese): cleanup --- .../post/extends/entities/user.entity.ts | 12 ------- .../post/extends/resolvers/user.resolver.ts | 17 ---------- packages/cheese/src/entities/post/index.ts | 25 --------------- .../cheese/src/entities/post/post.entity.ts | 31 ------------------- .../src/entities/post/post.reference.ts | 9 ------ .../cheese/src/entities/post/post.resolver.ts | 18 ----------- .../cheese/src/entities/post/post.service.ts | 11 ------- packages/cheese/src/subgraphs/post.graphql | 16 ---------- 8 files changed, 139 deletions(-) delete mode 100644 packages/cheese/src/entities/post/extends/entities/user.entity.ts delete mode 100644 packages/cheese/src/entities/post/extends/resolvers/user.resolver.ts delete mode 100644 packages/cheese/src/entities/post/index.ts delete mode 100644 packages/cheese/src/entities/post/post.entity.ts delete mode 100644 packages/cheese/src/entities/post/post.reference.ts delete mode 100644 packages/cheese/src/entities/post/post.resolver.ts delete mode 100644 packages/cheese/src/entities/post/post.service.ts delete mode 100644 packages/cheese/src/subgraphs/post.graphql diff --git a/packages/cheese/src/entities/post/extends/entities/user.entity.ts b/packages/cheese/src/entities/post/extends/entities/user.entity.ts deleted file mode 100644 index 49d7c7f..0000000 --- a/packages/cheese/src/entities/post/extends/entities/user.entity.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ObjectType, Directive, Field, ID } from "type-graphql"; -import { ObjectIdColumn } from "typeorm"; - -@Directive("@extends") -@Directive(`@key(fields: "id")`) -@ObjectType() -export default class User { - @Directive("@external") - @Field(() => ID) - @ObjectIdColumn() - id: string; -} diff --git a/packages/cheese/src/entities/post/extends/resolvers/user.resolver.ts b/packages/cheese/src/entities/post/extends/resolvers/user.resolver.ts deleted file mode 100644 index 62e7d41..0000000 --- a/packages/cheese/src/entities/post/extends/resolvers/user.resolver.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { FieldResolver, Resolver, Root } from "type-graphql"; -import { Inject, Service } from "typedi"; -import UserService from "../../../user/user.service"; -import Post from "../../post.entity"; -import User from "../entities/user.entity"; - -@Service() -@Resolver(User) -export default class UserResolver { - @Inject() - userService: UserService; - - @FieldResolver(() => [Post]) - async post(@Root() user: User): Promise> { - return Post.find({ postedById: user.id }); - } -} diff --git a/packages/cheese/src/entities/post/index.ts b/packages/cheese/src/entities/post/index.ts deleted file mode 100644 index 56a8a7f..0000000 --- a/packages/cheese/src/entities/post/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { listen } from "../../modules/listen"; -import Post from "./post.entity"; -import PostResolver from "./post.entity"; -import { resolvePostReference } from "./post.reference"; -import { createSubgraph } from "../../helpers/createSubgraph"; - -export * from "./post.entity"; -export * from "./post.resolver"; - -const name = "post"; - -export async function init(): Promise { - const { url, schema } = await listen( - { - name, - orphanedTypes: [Post], - resolvers: [PostResolver], - }, - { __resolveReference: resolvePostReference } - ); - - await createSubgraph(name, schema); - - return url; -} diff --git a/packages/cheese/src/entities/post/post.entity.ts b/packages/cheese/src/entities/post/post.entity.ts deleted file mode 100644 index 0b250ad..0000000 --- a/packages/cheese/src/entities/post/post.entity.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { MinLength } from "class-validator"; -import { Directive, Field, ObjectType, ID } from "type-graphql"; -import { - BaseEntity, - Entity, - ObjectIdColumn, - Column, - CreateDateColumn, -} from "typeorm"; - -@Entity() -@Directive(`@key(fields: "id")`) -@ObjectType() -export default class Post extends BaseEntity { - @ObjectIdColumn() - @Field(() => ID) - id: string; - - @Field() - @Column() - @MinLength(2) - caption: string; - - @Field() - @Column() - postedById: string; - - @Field() - @CreateDateColumn() - datePosted: Date; -} diff --git a/packages/cheese/src/entities/post/post.reference.ts b/packages/cheese/src/entities/post/post.reference.ts deleted file mode 100644 index 9309990..0000000 --- a/packages/cheese/src/entities/post/post.reference.ts +++ /dev/null @@ -1,9 +0,0 @@ -import Post from "./post.entity"; - -export async function resolvePostReference( - reference: Pick -): Promise { - const products = await Post.findOne({ id: reference.id }); - - return products; -} diff --git a/packages/cheese/src/entities/post/post.resolver.ts b/packages/cheese/src/entities/post/post.resolver.ts deleted file mode 100644 index 5d9877e..0000000 --- a/packages/cheese/src/entities/post/post.resolver.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Query, Resolver } from "type-graphql"; -import { Inject, Service } from "typedi"; -import Post from "./post.entity"; -import PostService from "./post.service"; - -@Service() -@Resolver(Post) -class PostResolver { - @Inject() - postService: PostService; - - @Query(() => [Post]) - async posts(): Promise { - return await this.postService.posts(); - } -} - -export default PostResolver; diff --git a/packages/cheese/src/entities/post/post.service.ts b/packages/cheese/src/entities/post/post.service.ts deleted file mode 100644 index a071edc..0000000 --- a/packages/cheese/src/entities/post/post.service.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Service } from "typedi"; -import Post from "./post.entity"; - -@Service() -class PostService { - async posts(): Promise { - return await Post.find({}); - } -} - -export default PostService; diff --git a/packages/cheese/src/subgraphs/post.graphql b/packages/cheese/src/subgraphs/post.graphql deleted file mode 100644 index 86e10b5..0000000 --- a/packages/cheese/src/subgraphs/post.graphql +++ /dev/null @@ -1,16 +0,0 @@ -type Post @key(fields: "id") { - id: ID! - caption: String! - postedById: String! - datePosted: DateTime! -} - -""" -The javascript `Date` as string. Type represents date and time as the ISO Date string. -""" -scalar DateTime - -type Query { - _entities(representations: [_Any!]!): [_Entity]! - _service: _Service! -}