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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
prisma-version: [4.7.0, 4.8.0]
node-version: [16, 18]
prisma-version: [5.5.2]
node-version: [16, 18, 20]

name: Node ${{ matrix.node-version }} with Prisma ${{ matrix.prisma-version }}
steps:
Expand All @@ -44,5 +44,5 @@ jobs:
run: yarn install

- name: 🧪 Run tests
run: yarn test
run: yarn checksrc

18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ generator pothosCrud {
generatorConfigPath = "./pothos.config.js"
// You may also set the `generatorConfigPath` via the `POTHOS_CRUD_CONFIG_PATH` environment variable.
// The environment variable will override the path hardcoded here.
// Use .cjs if you are using ESM module.
}

/// This is a user!
Expand Down Expand Up @@ -119,11 +120,12 @@ module.exports = {
},
crud: {
outputDir: './src/graphql/__generated__/',
inputsImporter: `import * as Inputs from '@graphql/__generated__/inputs';`,
inputsImporter: `import * as Inputs from '@graphql/__generated__/inputs';`, // "inputs.js" if using ESM module
resolversImports: `import prisma from '@lib/prisma';`,
prismaCaller: 'prisma',
},
global: {
esm: false,
},
};
```
Expand Down Expand Up @@ -195,6 +197,8 @@ module.exports = {
beforeGenerate?: (dmmf: DMMF.Document) => void;
/** Run function after generate */
afterGenerate?: (dmmf: DMMF.Document) => void;
/** Make generated file esm compatible */
esm?: boolean;
};
}
```
Expand Down Expand Up @@ -260,8 +264,8 @@ export const UserUpdateInputCustom = builder
```ts
// ./src/graphql/User/object.ts

import { UserObject } from '@/graphql/__generated__/User';
import { builder } from '@/graphql/builder'; // Pothos schema builder
import { UserObject } from '@/graphql/__generated__/User/index.js';
import { builder } from '@/graphql/builder.js'; // Pothos schema builder

// Use the Object export to accept all default generated query code
builder.prismaObject('User', UserObject);
Expand Down Expand Up @@ -296,8 +300,8 @@ builder.prismaObject('User', {
```ts
// ./src/graphql/User/query.ts

import { findManyUserQuery, findManyUserQueryObject } from '@/graphql/__generated__/User';
import { builder } from '@/graphql/builder'; // Pothos schema builder
import { findManyUserQuery, findManyUserQueryObject } from '@/graphql/__generated__/User/index.js';
import { builder } from '@/graphql/builder.js'; // Pothos schema builder

// Use the Query exports to accept all default generated query code
builder.queryFields(findManyUserQuery);
Expand Down Expand Up @@ -336,8 +340,8 @@ import {
generateAllObjects,
generateAllQueries,
generateAllMutations
} from '@/graphql/__generated__/autocrud.ts',
import { builder } from '@/graphql/builder'; // Pothos schema builder
} from '@/graphql/__generated__/autocrud.js',
import { builder } from '@/graphql/builder.js'; // Pothos schema builder

// (option 1) generate all objects, queries and mutations
generateAllCrud()
Expand Down
1 change: 1 addition & 0 deletions examples/inputs-simple-sqlite-esm/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POTHOS_CRUD_CONFIG_PATH="../src/schema/configs.cjs"
7 changes: 7 additions & 0 deletions examples/inputs-simple-sqlite-esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
893 changes: 893 additions & 0 deletions examples/inputs-simple-sqlite-esm/.yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/inputs-simple-sqlite-esm/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
34 changes: 34 additions & 0 deletions examples/inputs-simple-sqlite-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "inputs-simple",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"license": "MIT",
"scripts": {
"generate": "prisma generate",
"generate-debug": "npx cross-env DEBUG=* prisma generate",
"migrate": "prisma migrate dev",
"seed": "prisma migrate reset -f",
"start": "node --loader ts-node/esm src/server.ts",
"generator": "node --loader ts-node/esm src/pothos-plugin/src/inputsGenerator/index.ts",
"type": "tsc --noEmit",
"format": "eslint --fix ./src",
"genstart": "yarn generate && yarn start",
"tscheck": "tsc --noEmit"
},
"prisma": {
"seed": "node --loader ts-node/esm prisma/seed.ts"
},
"dependencies": {
"@pothos/core": "^3.41.0",
"@pothos/plugin-prisma": "^3.63.0",
"@prisma/client": "^5.7.1",
"@swc/core": "^1.3.101",
"apollo-server": "^3.13.0",
"graphql": "^16.8.1",
"prisma": "^5.7.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"packageManager": "yarn@4.0.2"
}
1 change: 1 addition & 0 deletions examples/inputs-simple-sqlite-esm/prisma/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.db*
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
-- CreateTable
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"firstName" TEXT NOT NULL,
"lastName" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME
);

-- CreateTable
CREATE TABLE "Post" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"title" TEXT NOT NULL,
"content" TEXT NOT NULL,
"authorId" INTEGER NOT NULL,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Comment" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"comment" TEXT NOT NULL,
"authorId" INTEGER NOT NULL,
"postId" INTEGER NOT NULL,
CONSTRAINT "Comment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Comment_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post" ("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 "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 "IdOnly" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);

-- CreateTable
CREATE TABLE "WithoutID" (
"name" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "WithScalars" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"string" TEXT,
"boolean" BOOLEAN,
"int" INTEGER,
"float" REAL,
"decimal" DECIMAL,
"bigint" BIGINT,
"datetime" DATETIME,
"bytes" BLOB
);

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

-- CreateIndex
CREATE UNIQUE INDEX "WithoutID_name_key" ON "WithoutID"("name");
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Warnings:

- Added the required column `birthdate` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `login` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `password` to the `User` table without a default value. This is not possible if the table is not empty.

*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"firstName" TEXT NOT NULL,
"lastName" TEXT NOT NULL,
"birthdate" DATETIME NOT NULL,
"login" TEXT NOT NULL,
"password" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME
);
INSERT INTO "new_User" ("createdAt", "firstName", "id", "lastName", "updatedAt") SELECT "createdAt", "firstName", "id", "lastName", "updatedAt" FROM "User";
DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- CreateTable
CREATE TABLE "ExtraModal" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"title" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Warnings:

- The primary key for the `WithScalars` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to alter the column `id` on the `WithScalars` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`.

*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_WithScalars" (
"id" BIGINT NOT NULL PRIMARY KEY,
"string" TEXT,
"boolean" BOOLEAN,
"int" INTEGER,
"float" REAL,
"decimal" DECIMAL,
"bigint" BIGINT,
"datetime" DATETIME,
"bytes" BLOB
);
INSERT INTO "new_WithScalars" ("bigint", "boolean", "bytes", "datetime", "decimal", "float", "id", "int", "string") SELECT "bigint", "boolean", "bytes", "datetime", "decimal", "float", "id", "int", "string" FROM "WithScalars";
DROP TABLE "WithScalars";
ALTER TABLE "new_WithScalars" RENAME TO "WithScalars";
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- CreateTable
CREATE TABLE "UserLast" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL
);
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