Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@
"node": ">=20.0.0"
},
"dependencies": {
"@apollo/server": "^5.5.1",
"@as-integrations/express4": "^1.1.2",
"@endgit/database": "workspace:*",
"@endgit/storage": "workspace:*",
"@endgit/types": "workspace:*",
"bcryptjs": "^2.4.3",
"body-parser": "^2.2.2",
"bullmq": "^5.76.2",
"compression": "^1.8.1",
"cors": "^2.8.5",
"dataloader": "^2.2.3",
"dotenv": "^16.4.0",
"express": "^4.21.0",
"express-rate-limit": "^7.4.0",
"graphql": "^16.14.2",
"helmet": "^8.0.0",
"ioredis": "^5.10.1",
"jsonwebtoken": "^9.0.0",
Expand Down
618 changes: 618 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions skills-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"skillPath": "skills/find-skills/SKILL.md",
"computedHash": "9e1c8b3103f92fa8092568a44fe64858de7c5c9dc65ce4bea8f168080e889cfd"
},
"graphql-schema": {
"source": "apollographql/skills",
"sourceType": "github",
"skillPath": "skills/graphql-schema/SKILL.md",
"computedHash": "95f5384cc907635fc31121648dffffed0bb6f773ee594cbfe9be9e5e4a0e6aba"
},
"prisma-client-api": {
"source": "prisma/skills",
"sourceType": "github",
Expand Down
8 changes: 8 additions & 0 deletions src/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApolloServer } from "@apollo/server";
import { typeDefs } from "./typeDefs";
import { resolvers } from "./resolvers";

export const apolloServer = new ApolloServer({
typeDefs,
resolvers,
});
83 changes: 83 additions & 0 deletions src/graphql/resolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { prisma } from "@endgit/database";
import { dashboardService } from "../modules/dashboard/dashboard.service";
import { pluginsService } from "../modules/plugins/plugins.service";

export const resolvers = {
Query: {
plugins: async (_: any, args: { limit: number; offset: number; status?: string }) => {
return prisma.plugin.findMany({
where: args.status ? { status: args.status as any } : undefined,
take: args.limit,
skip: args.offset,
orderBy: { heatScore: "desc" },
});
},
plugin: async (_: any, args: { slug: string }, context: any) => {
return pluginsService.getBySlug(args.slug, context.user);
},
me: async (_: any, __: any, context: any) => {
if (!context.user) return null;
return prisma.user.findUnique({ where: { id: context.user.id } });
},
homePlugins: async () => {
return pluginsService.getHome();
},
myPlugins: async (_: any, __: any, context: any) => {
if (!context.user) throw new Error("Unauthorized");
return dashboardService.getMyPlugins(context.user.id);
},
myStats: async (_: any, __: any, context: any) => {
if (!context.user) throw new Error("Unauthorized");
return dashboardService.getMyStats(context.user.id);
},
dashboardStatus: async (_: any, __: any, context: any) => {
if (!context.user) throw new Error("Unauthorized");
return dashboardService.getStatus(context.user.id);
}
},
Mutation: {
createPlugin: async (_: any, { input }: any, context: any) => {
if (!context.user) throw new Error("Unauthorized");
return pluginsService.createPlugin(input, context.user.id);
},
updatePlugin: async (_: any, { slug, input }: any, context: any) => {
if (!context.user) throw new Error("Unauthorized");
return pluginsService.updatePlugin(slug, input, context.user);
},
deletePlugin: async (_: any, { slug }: any, context: any) => {
if (!context.user) throw new Error("Unauthorized");
await pluginsService.deletePlugin(slug, context.user);
return true;
},
triggerBuild: async (_: any, { slug, commitHash, branch }: any, context: any) => {
if (!context.user) throw new Error("Unauthorized");
return pluginsService.triggerBuild(slug, { commitHash, branch }, context.user);
}
},
Plugin: {
author: async (parent: any, _: any, context: any) => {
if (parent.author) return parent.author;
return context.loaders.userLoader.load(parent.authorId);
},
versions: async (parent: any, args: { status?: string }, context: any) => {
let versions;
if (parent.versions) {
versions = parent.versions;
} else {
versions = await context.loaders.versionLoader.load(parent.id);
}
if (args.status) {
return versions.filter((v: any) => v.status === args.status);
}
return versions;
},
stars: (parent: any) => parent.stars || 0,
downloads: (parent: any) => parent.downloads || 0,
commentCount: (parent: any) => parent.commentCount || 0,
heatScore: (parent: any) => parent.heatScore || 0,
status: (parent: any) => parent.status || "UNKNOWN",
isVerified: (parent: any) => parent.isVerified || false,
isFeatured: (parent: any) => parent.isFeatured || false,
pluginType: (parent: any) => parent.pluginType || "UNKNOWN",
},
};
144 changes: 144 additions & 0 deletions src/graphql/typeDefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
export const typeDefs = `#graphql
type User {
id: ID!
githubId: String!
username: String!
displayName: String
email: String
avatarUrl: String
bio: String
trustLevel: String!
trustScore: Int!
createdAt: String!
updatedAt: String!
}

type Producer {
githubUser: String!
role: String!
}

type VirusTotal {
scanId: String
status: String
malicious: Int
suspicious: Int
undetected: Int
total: Int
permalink: String
scanDate: String
}

type Version {
id: ID!
version: String!
changelog: String
longDescription: String
fileName: String!
fileSize: Int!
fileHash: String!
minApiVersion: String
supportedApis: [String!]!
downloads: Int!
isLatest: Boolean!
isPreRelease: Boolean!
status: String!
statusReason: String
createdAt: String!
producers: [Producer!]
virustotal: VirusTotal
}

type Plugin {
id: ID!
name: String!
slug: String!
displayName: String!
description: String!
longDescription: String
iconUrl: String
repoUrl: String
license: String
tags: [String!]!
keywords: [String!]!
pluginType: String!
downloads: Int!
stars: Int!
commentCount: Int!
heatScore: Int!
status: String!
qualityBadge: String!
isVerified: Boolean!
isFeatured: Boolean!
createdAt: String!
updatedAt: String!
author: User!
versions(status: String): [Version!]!
latestVersion: String
isPreRelease: Boolean
}

type HomePlugins {
hotPlugins: [Plugin!]!
newPlugins: [Plugin!]!
topPlugins: [Plugin!]!
featuredPlugins: [Plugin!]!
}

type DashboardStats {
totalPlugins: Int!
totalDownloads: Int!
totalVersions: Int!
pendingReviews: Int!
}

type Quota {
used: Int!
limit: Int!
resetsAt: String!
}

type DashboardStatus {
hasAppInstalled: Boolean!
githubTokenExpired: Boolean!
quota: Quota!
}

type Query {
plugins(limit: Int = 10, offset: Int = 0, status: String): [Plugin!]!
plugin(slug: String!): Plugin
me: User
homePlugins: HomePlugins!
myPlugins: [Plugin!]!
myStats: DashboardStats!
dashboardStatus: DashboardStatus!
}

input CreatePluginInput {
name: String!
displayName: String!
description: String!
longDescription: String
pluginType: String
repoUrl: String
license: String
tags: [String!]
}

input UpdatePluginInput {
displayName: String
description: String
longDescription: String
iconUrl: String
license: String
tags: [String!]
isPreRelease: Boolean
}

type Mutation {
createPlugin(input: CreatePluginInput!): Plugin!
updatePlugin(slug: String!, input: UpdatePluginInput!): Plugin!
deletePlugin(slug: String!): Boolean!
triggerBuild(slug: String!, commitHash: String, branch: String): String!
}
`;
Loading