Skip to content

Commit

Permalink
Merge pull request #348 from hayes/mh--prisma-crud-spike
Browse files Browse the repository at this point in the history
create prisma utils plugin
  • Loading branch information
hayes authored Aug 20, 2022
2 parents 378ce16 + ad16d7c commit dc5704a
Show file tree
Hide file tree
Showing 55 changed files with 1,635 additions and 27 deletions.
1 change: 0 additions & 1 deletion packages/converter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fieldUtils/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class InputFieldBuilder<
*/
field<Type extends InputType<Types> | [InputType<Types>], Req extends FieldRequiredness<Type>>(
options: PothosSchemaTypes.InputFieldOptionsByKind<Types, Type, Req>[Kind],
) {
): InputFieldRef<InputShapeFromTypeParam<Types, Type, Req>, Kind> {
const ref: InputFieldRef<InputShapeFromTypeParam<Types, Type, Req>, Kind> = new InputFieldRef(
this.kind,
this.typename,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/refs/input-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import BaseTypeRef from './base';

export default class InputObjectRef<T>
extends BaseTypeRef
implements InputRef, PothosSchemaTypes.InputObjectRef<T>
implements InputRef<T>, PothosSchemaTypes.InputObjectRef<T>
{
override kind = 'InputObject' as const;

Expand Down
2 changes: 1 addition & 1 deletion packages/deno/packages/core/fieldUtils/input.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/deno/packages/core/refs/input-object.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/deno/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const excludedPackages = [
'deno',
'plugin-example',
'plugin-prisma',
'plugin-prisma-utils',
'test-utils',
'plugin-federation',
'tracing-opentelemetry',
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-authz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"auth",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-complexity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-dataloader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-directives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-mocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"giraphql",
"pothos",
"graphql",
"schema",
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-prisma-utils/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
prisma
test
tests
.turbo
babel.config.js
tsconfig.tsbuildinfo
6 changes: 6 additions & 0 deletions packages/plugin-prisma-utils/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ISC License (ISC)
Copyright 2021 Michael Hayes

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3 changes: 3 additions & 0 deletions packages/plugin-prisma-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prisma utils for Pothos

This package is highly experimental and not ready for production use
3 changes: 3 additions & 0 deletions packages/plugin-prisma-utils/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
};
2 changes: 2 additions & 0 deletions packages/plugin-prisma-utils/bin/generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/generator.js');
4 changes: 4 additions & 0 deletions packages/plugin-prisma-utils/esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!.npmignore
!package.json
Empty file.
3 changes: 3 additions & 0 deletions packages/plugin-prisma-utils/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
59 changes: 59 additions & 0 deletions packages/plugin-prisma-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@pothos/plugin-prisma-utils",
"version": "0.0.0",
"description": "A Pothos plugin containing utility functions for building prisma inputs",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"module": "./esm/index.js",
"exports": {
"import": "./esm/index.js",
"require": "./lib/index.js"
},
"scripts": {
"generate": "prisma generate",
"type": "tsc --project tsconfig.type.json",
"build": "pnpm build:clean && pnpm build:cjs && pnpm build:esm && pnpm build:dts",
"build:clean": "git clean -dfX esm lib",
"build:cjs": "swc src -d lib --config-file ../../.swcrc -C module.type=commonjs",
"build:esm": "swc src -d esm --config-file ../../.swcrc -C module.type=es6 && pnpm esm:extensions",
"build:dts": "tsc",
"esm:extensions": "TS_NODE_PROJECT=../../tsconfig.json node -r @swc-node/register ../../.config/esm-transformer.ts",
"test": "pnpm vitest --run"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hayes/pothos.git"
},
"author": "Michael Hayes",
"license": "ISC",
"keywords": [
"pothos",
"graphql",
"schema",
"typescript",
"prisma"
],
"publishConfig": {
"access": "public"
},
"prisma": {
"seed": "node prisma/seed.mjs"
},
"dependencies": {
"@prisma/generator-helper": "^4.1.0"
},
"peerDependencies": {
"@pothos/plugin-prisma": "workspace:*",
"@prisma/client": "*",
"graphql": ">=15.1.0"
},
"devDependencies": {
"@pothos/core": "workspace:*",
"@pothos/plugin-prisma": "workspace:*",
"@pothos/test-utils": "workspace:*",
"@prisma/client": "^4.1.0",
"graphql": "16.3.0",
"graphql-tag": "^2.12.6",
"prisma": "^4.1.0"
}
}
Binary file added packages/plugin-prisma-utils/prisma/dev.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
-- CreateTable
CREATE TABLE "Post" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"title" TEXT NOT NULL,
"content" TEXT,
"published" BOOLEAN NOT NULL DEFAULT false,
"authorId" INTEGER NOT NULL,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Media" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"url" TEXT NOT NULL,
"uploadedById" INTEGER,
CONSTRAINT "Media_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "PostMedia" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"postId" INTEGER NOT NULL,
"mediaId" INTEGER NOT NULL,
"order" INTEGER NOT NULL,
CONSTRAINT "PostMedia_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "PostMedia_mediaId_fkey" FOREIGN KEY ("mediaId") REFERENCES "Media" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Comment" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"content" TEXT NOT NULL,
"authorId" INTEGER NOT NULL,
"postId" INTEGER NOT NULL,
CONSTRAINT "Comment_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Comment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Profile" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"bio" TEXT,
"userId" INTEGER NOT NULL,
CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"email" TEXT NOT NULL,
"name" TEXT
);

-- CreateTable
CREATE TABLE "Follow" (
"fromId" INTEGER NOT NULL,
"toId" INTEGER NOT NULL,

PRIMARY KEY ("fromId", "toId"),
CONSTRAINT "Follow_fromId_fkey" FOREIGN KEY ("fromId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Follow_toId_fkey" FOREIGN KEY ("toId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Unrelated" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT
);

-- CreateTable
CREATE TABLE "WithID" (
"id" TEXT NOT NULL PRIMARY KEY
);

-- CreateTable
CREATE TABLE "WithUnique" (
"id" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "WithCompositeID" (
"a" TEXT NOT NULL,
"b" TEXT NOT NULL,

PRIMARY KEY ("a", "b")
);

-- CreateTable
CREATE TABLE "WithCompositeUnique" (
"a" TEXT NOT NULL,
"c" TEXT,
"b" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "FindUniqueRelations" (
"id" TEXT NOT NULL PRIMARY KEY,
"withID_id" TEXT NOT NULL,
"withUnique_id" TEXT NOT NULL,
"withCompositeID_a" TEXT NOT NULL,
"withCompositeID_b" TEXT NOT NULL,
"withCompositeUnique_a" TEXT NOT NULL,
"withCompositeUnique_b" TEXT NOT NULL,
CONSTRAINT "FindUniqueRelations_withID_id_fkey" FOREIGN KEY ("withID_id") REFERENCES "WithID" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "FindUniqueRelations_withUnique_id_fkey" FOREIGN KEY ("withUnique_id") REFERENCES "WithUnique" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "FindUniqueRelations_withCompositeID_a_withCompositeID_b_fkey" FOREIGN KEY ("withCompositeID_a", "withCompositeID_b") REFERENCES "WithCompositeID" ("a", "b") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "FindUniqueRelations_withCompositeUnique_a_withCompositeUnique_b_fkey" FOREIGN KEY ("withCompositeUnique_a", "withCompositeUnique_b") REFERENCES "WithCompositeUnique" ("a", "b") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "Post_createdAt_key" ON "Post"("createdAt");

-- CreateIndex
CREATE UNIQUE INDEX "Comment_createdAt_key" ON "Comment"("createdAt");

-- CreateIndex
CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- CreateIndex
CREATE UNIQUE INDEX "WithUnique_id_key" ON "WithUnique"("id");

-- CreateIndex
CREATE UNIQUE INDEX "WithCompositeUnique_c_key" ON "WithCompositeUnique"("c");

-- CreateIndex
CREATE UNIQUE INDEX "WithCompositeUnique_a_c_key" ON "WithCompositeUnique"("a", "c");

-- CreateIndex
CREATE UNIQUE INDEX "WithCompositeUnique_a_b_key" ON "WithCompositeUnique"("a", "b");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
Loading

1 comment on commit dc5704a

@vercel
Copy link

@vercel vercel bot commented on dc5704a Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.