From 4d00cfb8f0dbcfb0155f8f1e4b829b20b96ae9b4 Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:02:06 +0530 Subject: [PATCH] Add graphql schema (#18) * Add graphql schema * Remove circular references in gql schema * Remove unnecessary todos --------- Co-authored-by: neeraj --- packages/backend/src/entity/Deployment.ts | 4 +- packages/backend/src/entity/Project.ts | 4 +- packages/backend/src/entity/ProjectMember.ts | 4 +- .../backend/src/entity/UserOrganization.ts | 4 +- packages/backend/src/index.ts | 6 +- .../backend/src/{resolver.ts => resolvers.ts} | 2 +- packages/backend/src/schema.gql | 118 ++++++++++++++++++ packages/backend/src/schema.ts | 9 -- 8 files changed, 131 insertions(+), 20 deletions(-) rename packages/backend/src/{resolver.ts => resolvers.ts} (86%) create mode 100644 packages/backend/src/schema.gql delete mode 100644 packages/backend/src/schema.ts diff --git a/packages/backend/src/entity/Deployment.ts b/packages/backend/src/entity/Deployment.ts index 52e3b555..08f42c54 100644 --- a/packages/backend/src/entity/Deployment.ts +++ b/packages/backend/src/entity/Deployment.ts @@ -30,11 +30,11 @@ export class Deployment { id!: number; @ManyToOne(() => Project, { onDelete: 'CASCADE' }) - @JoinColumn({ name: 'projectID' }) + @JoinColumn({ name: 'projectId' }) project!: Project; @OneToOne(() => Domain) - @JoinColumn({ name: 'domainID' }) + @JoinColumn({ name: 'domainId' }) domain!: Domain; @Column('varchar') diff --git a/packages/backend/src/entity/Project.ts b/packages/backend/src/entity/Project.ts index de520391..e709c97f 100644 --- a/packages/backend/src/entity/Project.ts +++ b/packages/backend/src/entity/Project.ts @@ -17,11 +17,11 @@ export class Project { id!: string; @ManyToOne(() => User) - @JoinColumn({ name: 'ownerID' }) + @JoinColumn({ name: 'ownerId' }) owner!: User; @ManyToOne(() => Organization, { nullable: true }) - @JoinColumn({ name: 'organizationID' }) + @JoinColumn({ name: 'organizationId' }) organization!: Organization | null; @Column('varchar') diff --git a/packages/backend/src/entity/ProjectMember.ts b/packages/backend/src/entity/ProjectMember.ts index fa160018..2c208c7b 100644 --- a/packages/backend/src/entity/ProjectMember.ts +++ b/packages/backend/src/entity/ProjectMember.ts @@ -23,11 +23,11 @@ export class ProjectMember { id!: number; @ManyToOne(() => User, { onDelete: 'CASCADE' }) - @JoinColumn({ name: 'userID' }) + @JoinColumn({ name: 'userId' }) user!: User; @ManyToOne(() => Project, { onDelete: 'CASCADE' }) - @JoinColumn({ name: 'projectID' }) + @JoinColumn({ name: 'projectId' }) project!: Project; @Column({ diff --git a/packages/backend/src/entity/UserOrganization.ts b/packages/backend/src/entity/UserOrganization.ts index 167c11a9..5d11c4c8 100644 --- a/packages/backend/src/entity/UserOrganization.ts +++ b/packages/backend/src/entity/UserOrganization.ts @@ -23,11 +23,11 @@ export class UserOrganization { id!: number; @ManyToOne(() => User, { onDelete: 'CASCADE' }) - @JoinColumn({ name: 'userID' }) + @JoinColumn({ name: 'userId' }) user!: User; @ManyToOne(() => Organization, { onDelete: 'CASCADE' }) - @JoinColumn({ name: 'organizationID' }) + @JoinColumn({ name: 'organizationId' }) organization!: Organization; @Column({ diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index a2273f32..7fa58981 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -1,10 +1,11 @@ import 'reflect-metadata'; import debug from 'debug'; +import fs from 'fs'; +import path from 'path'; import { initializeDatabase } from './database'; import { createAndStartServer } from './server'; -import { createResolvers } from './resolver'; -import { typeDefs } from './schema'; +import { createResolvers } from './resolvers'; import { getConfig } from './utils'; import { Config } from './type'; @@ -16,6 +17,7 @@ export const main = async (): Promise => { const { server } = await getConfig(configFilePath); await initializeDatabase(); + const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString(); await createAndStartServer(typeDefs, createResolvers, server); }; diff --git a/packages/backend/src/resolver.ts b/packages/backend/src/resolvers.ts similarity index 86% rename from packages/backend/src/resolver.ts rename to packages/backend/src/resolvers.ts index f86dece9..8a745398 100644 --- a/packages/backend/src/resolver.ts +++ b/packages/backend/src/resolvers.ts @@ -6,7 +6,7 @@ export const createResolvers = async (): Promise => { return { Query: { // TODO: fetch user data from db - getUser: () => user + user: () => user } }; }; diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql new file mode 100644 index 00000000..b8e8cf70 --- /dev/null +++ b/packages/backend/src/schema.gql @@ -0,0 +1,118 @@ +enum Role { + Owner + Maintainer + Reader +} + +enum Permission { + View + Edit +} + +enum Environment { + Production + Preview + Development +} + +enum DeploymentStatus { + Building + Ready + Error +} + +enum DomainStatus { + Live + Pending +} + +type User { + id: String! + name: String! + email: String! + organizations: [Organization!] + projects: [Project!] + createdAt: String! + updatedAt: String! +} + +type Organization { + id: String! + name: String! + projects: [Project!] + createdAt: String! + updatedAt: String! + members: [OrganizationMember!] +} + +type OrganizationMember { + id: String! + member: User! + role: Role! + createdAt: String! + updatedAt: String! +} + +type Project { + id: String! + owner: User! + deployments: [Deployment!] + name: String! + repository: String! + prodBranch: String! + description: String + template: String + framework: String! + webhooks: [String!] + members: [ProjectMember!] + environmentVariables: [EnvironmentVariable!] + createdAt: String! + updatedAt: String! +} + +type ProjectMember { + id: String! + member: User! + permissions: [Permission!]! + createdAt: String! + updatedAt: String! +} + +type Deployment { + id: String! + domain: Domain + branch: String! + commitHash: String! + title: String! + environment: Environment! + isCurrent: Boolean! + status: DeploymentStatus! + createdAt: String! + updatedAt: String! +} + +type Domain { + id: String! + branch: String! + name: String! + isRedirected: Boolean! + status: DomainStatus! + createdAt: String! + updatedAt: String! +} + +type EnvironmentVariable { + id: String! + environments: [Environment!]! + key: String! + value: String! + createdAt: String! + updatedAt: String! +} + +type Query { + user: User! + organizations: [Organization!] + projects: [Project!] + deployments(projectId: String!): [Deployment!] +} diff --git a/packages/backend/src/schema.ts b/packages/backend/src/schema.ts deleted file mode 100644 index 9098e48c..00000000 --- a/packages/backend/src/schema.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const typeDefs = /* GraphQL */ ` - type User { - id: Int - } - - type Query { - getUser: User - } -`;