-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from richardguerre/shortcuts
Shortcuts
- Loading branch information
Showing
28 changed files
with
1,124 additions
and
295 deletions.
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
16 changes: 16 additions & 0 deletions
16
apps/server/prisma/migrations/20241026061350_add_shortcuts/migration.sql
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,16 @@ | ||
-- CreateTable | ||
CREATE TABLE "Shortcut" ( | ||
"id" SERIAL NOT NULL, | ||
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMPTZ NOT NULL, | ||
"slug" TEXT NOT NULL, | ||
"pluginSlug" TEXT NOT NULL, | ||
"elementId" TEXT NOT NULL, | ||
"trigger" TEXT[], | ||
"enabled" BOOLEAN NOT NULL DEFAULT true, | ||
|
||
CONSTRAINT "Shortcut_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Shortcut_slug_pluginSlug_key" ON "Shortcut"("slug", "pluginSlug"); |
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
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
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
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,113 @@ | ||
import { prisma } from "../utils/prisma"; | ||
import { builder, u } from "./builder"; | ||
import { JsonFilter, StringFilter } from "./PrismaFilters"; | ||
|
||
export const ShortcutType = builder.prismaNode("Shortcut", { | ||
id: { field: "id" }, | ||
fields: (t) => ({ | ||
createdAt: t.expose("createdAt", { type: "DateTime" }), | ||
updatedAt: t.expose("updatedAt", { type: "DateTime" }), | ||
slug: t.exposeString("slug"), | ||
pluginSlug: t.exposeString("pluginSlug"), | ||
enabled: t.exposeBoolean("enabled"), | ||
elementId: t.exposeString("elementId"), | ||
trigger: t.exposeStringList("trigger"), | ||
}), | ||
}); | ||
|
||
export const ShortcutWhereInputType = builder.prismaWhere("Shortcut", { | ||
fields: { | ||
pluginSlug: StringFilter, | ||
slug: StringFilter, | ||
trigger: JsonFilter, | ||
AND: true, | ||
OR: true, | ||
NOT: true, | ||
}, | ||
}); | ||
|
||
export const ShortcutOrderByType = builder.prismaOrderBy("Shortcut", { | ||
fields: { | ||
slug: true, | ||
createdAt: true, | ||
updatedAt: true, | ||
}, | ||
}); | ||
|
||
builder.queryField("shortcuts", (t) => | ||
t.prismaConnection({ | ||
type: "Shortcut", | ||
cursor: "id", | ||
description: "Get keyboard shortcuts.", | ||
args: { | ||
where: t.arg({ type: ShortcutWhereInputType, required: false }), | ||
orderBy: t.arg({ type: ShortcutOrderByType, required: false }), | ||
}, | ||
resolve: async (query, _, args) => { | ||
return prisma.shortcut.findMany({ | ||
...query, | ||
where: args.where ?? undefined, | ||
orderBy: args.orderBy ?? undefined, | ||
}); | ||
}, | ||
}), | ||
); | ||
|
||
builder.mutationField("upsertShortcut", (t) => | ||
t.prismaFieldWithInput({ | ||
type: "Shortcut", | ||
description: "Create a new shortcut.", | ||
input: { | ||
slug: t.input.string({ required: true }), | ||
pluginSlug: t.input.string({ required: true }), | ||
elementId: t.input.string({ required: true }), | ||
trigger: t.input.stringList({ required: true }), | ||
enabled: t.input.boolean({ required: false }), | ||
}, | ||
resolve: async (_, __, args) => { | ||
return prisma.shortcut.upsert({ | ||
where: { | ||
slug_pluginSlug_unique: { slug: args.input.slug, pluginSlug: args.input.pluginSlug }, | ||
}, | ||
create: { | ||
slug: args.input.slug, | ||
pluginSlug: args.input.pluginSlug, | ||
elementId: args.input.elementId, | ||
trigger: args.input.trigger, | ||
}, | ||
update: { | ||
trigger: args.input.trigger, | ||
enabled: u(args.input.enabled), | ||
}, | ||
}); | ||
}, | ||
}), | ||
); | ||
|
||
builder.mutationField("disableShortcut", (t) => | ||
t.prismaField({ | ||
type: "Shortcut", | ||
description: "Disable a shortcut.", | ||
args: { id: t.arg.globalID({ required: true }) }, | ||
resolve: async (_, __, args) => { | ||
return prisma.shortcut.update({ | ||
where: { id: parseInt(args.id.id) }, | ||
data: { enabled: false }, | ||
}); | ||
}, | ||
}), | ||
); | ||
|
||
builder.mutationField("enableShortcut", (t) => | ||
t.prismaField({ | ||
type: "Shortcut", | ||
description: "Enable a shortcut.", | ||
args: { id: t.arg.globalID({ required: true }) }, | ||
resolve: async (_, __, args) => { | ||
return prisma.shortcut.update({ | ||
where: { id: parseInt(args.id.id) }, | ||
data: { enabled: true }, | ||
}); | ||
}, | ||
}), | ||
); |
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
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
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
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
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
Oops, something went wrong.