Skip to content

AhmedElywa/prisma-tools

Repository files navigation

PalJS Header

PalJS - Your Prisma GraphQL Toolkit

A comprehensive toolkit for building modern GraphQL APIs with Prisma

Version License Stars Discord

Table of Contents


Introduction

PalJS is a powerful toolkit that accelerates GraphQL API development with Prisma. It provides code generation, admin interfaces, query optimization, and project scaffolding tools that let you build production-ready GraphQL APIs in minutes, not hours.

Why Choose PalJS?

  • ⏰ Rapid Development: Go from Prisma schema to production API in minutes
  • 🛡️ Enterprise Ready: Built with type safety, security, and scalability in mind
  • 🔌 Framework Agnostic: Works with Apollo Server, Express, Next.js, and more
  • 📚 Well Documented: Comprehensive documentation and examples for every package
  • 🌍 Active Community: Join thousands of developers building with PalJS

Packages

PalJS is organized as a monorepo with focused packages for different aspects of GraphQL development:

Core Development Tools

@paljs/cli Command-line interface for project management and code generation 📖 Docs
@paljs/generator Powerful code generation engine for GraphQL schemas, resolvers, and types 📖 Docs
@paljs/create Project scaffolding with templates for multiple frameworks and architectures 📖 Docs

GraphQL Integration

@paljs/nexus Nexus plugin for Prisma integration with automatic field selection and admin schema 📖 Docs
@paljs/plugins GraphQL plugins for query optimization, field selection, and SDL generation 📖 Docs

UI Components

@paljs/admin React admin UI components with Tailwind CSS, forms, tables, and CRUD operations 📖 Docs

Schema & Utilities

@paljs/schema Prisma schema manipulation, conversion tools, and TypeScript generation 📖 Docs
@paljs/utils Common utilities for DMMF processing, schema validation, and helper functions 📖 Docs
@paljs/types Comprehensive TypeScript type definitions for the entire PalJS ecosystem 📖 Docs
@paljs/display Styled console output, progress indicators, and logging utilities for CLI tools 📖 Docs

Architecture

PalJS follows a modular architecture that supports different GraphQL patterns:

graph TB
    CLI[📱 PalJS CLI] --> Create[🚀 Project Creation]
    CLI --> Generate[⚡ Code Generation]

    Create --> Templates[📋 Templates]
    Templates --> NextJS[Next.js + GraphQL]
    Templates --> Apollo[Apollo Server]
    Templates --> Modules[GraphQL Modules]

    Generate --> Schema[🔧 Schema Processing]
    Generate --> Nexus[🎯 Nexus Integration]
    Generate --> SDL[📝 SDL Generation]
    Generate --> Admin[🎨 Admin UI]

    Schema --> Utils[🛠️ Utilities]
    Schema --> Types[📊 Type Definitions]

    Nexus --> Plugins[🔌 GraphQL Plugins]
    Plugins --> Optimization[⚡ Query Optimization]
Loading

🤖 AI-Powered Code Generation with MDC Templates

Transform 5 years of code generation expertise into AI-compatible instructions

PalJS now offers MDC (Model Data Context) Templates - comprehensive AI instructions that preserve all the power of our original generators while being maintenance-free and future-proof.

🎯 Why MDC Templates?

🚀 Future-Proof No package dependencies to maintain or update
🤖 AI-Compatible Works with any AI model that can read instructions
📚 Human-Readable Easy to understand, customize, and extend
⚡ Instant Setup No installation required - just copy and use

📦 Available MDC Templates

🎯 GraphQL Operations Generate client-side GraphQL fragments, queries, and mutations Frontend Development
🎨 Admin Pages Create React admin interfaces with Next.js support Admin Dashboards
⚡ Nexus Backend Build type-safe GraphQL APIs with Nexus framework Type-Safe APIs
📝 SDL Backend Generate SDL-first GraphQL schemas and resolvers Schema-First APIs
🛡️ Resolver Types Create TypeScript type definitions for resolvers Type Safety
🏗️ GraphQL Modules Build modular GraphQL with dependency injection Enterprise Scale
⚙️ Admin Settings Generate configuration files for admin interfaces UI Configuration

🚀 Quick Start with AI

1. Choose Your Template

Pick the template that matches your needs from the table above.

2. Prepare Your Context

# Your Prisma schema
cat prisma/schema.prisma

# Choose configuration options
export OUTPUT_DIR="src/graphql"
export MODELS="User,Post,Comment"

3. Generate with AI

# Example prompt for ChatGPT/Claude/etc:
"I need you to generate GraphQL operations for my Prisma models.

Here's the MDC template: [paste template content]

Here's my Prisma schema: [paste schema]

Configuration:
- Output directory: src/graphql  
- Models: User, Post, Comment
- Exclude fields: createdAt, updatedAt
- Generate TypeScript

Please follow the exact patterns in the template."

4. Get Production-Ready Code

The AI will generate the same high-quality code that PalJS generators created, but without any package dependencies!

🎨 Example Output

Input: Simple blog schema with User and Post models
Output: Complete GraphQL operations, admin pages, or backend APIs

// Generated GraphQL operations
export const USER_FRAGMENT = gql`
  fragment UserFragment on User {
    id
    email
    name
    posts {
      id
      title
    }
  }
`;

export const FIND_MANY_USERS = gql`
  query FindManyUsers($where: UserWhereInput) {
    findManyUsers(where: $where) {
      ...UserFragment
    }
  }
  ${USER_FRAGMENT}
`;

🔄 Migration from PalJS Generators

Transitioning from the original generators is seamless:

Original Generator MDC Template Status
@paljs/generator → GraphQL GraphQL Operations ✅ 100% Compatible
@paljs/generator → Admin Admin Pages ✅ 100% Compatible
@paljs/generator → Nexus Nexus Backend ✅ 100% Compatible
@paljs/generator → SDL SDL Backend ✅ 100% Compatible

💡 Benefits Over Traditional Generators

Traditional Generators MDC Templates
📦 Package dependencies 🚀 Zero dependencies
🔄 Version compatibility issues ⚡ Always compatible
🛠️ Maintenance overhead 🎯 Maintenance-free
🏗️ Fixed patterns 🎨 AI-adaptable patterns
📅 Periodic updates needed 🔮 Future-proof

📚 Documentation & Examples


Installation

Choose one of the following installation methods:

Global Installation (Recommended)

# Install PalJS CLI globally to use the 'pal' command
npm install -g @paljs/cli

# After global installation, the 'pal' binary is available system-wide
pal --help

Use with npx (No Installation Required)

# Use npx to run commands without global installation
npx @paljs/cli --help

Usage

Quick Start

Create Your First Project

Using Global Installation (pal command)

# Create a new full-stack project
pal create my-graphql-app

# Choose your preferred setup:
# ✔ Project template: full-stack-nextjs
# ✔ UI framework: Tailwind CSS + PrismaAdmin UI
# ✔ Package manager: yarn
# ✔ Initialize git: yes

cd my-graphql-app
yarn dev

Using npx (Alternative Method)

# Create a new full-stack project without global installation
npx @paljs/cli create my-graphql-app

# Same interactive setup process follows
cd my-graphql-app
yarn dev

Generate GraphQL API

Using Global Installation

# After defining your Prisma schema
pal generate

# Generates:
# ✅ GraphQL schema with all CRUD operations
# ✅ Type-safe resolvers
# ✅ Admin interface pages
# ✅ Query optimization utilities

Using npx

# After defining your Prisma schema
npx @paljs/cli generate

# Same generated output

5-Minute Setup

  1. Install PalJS CLI

    npm install -g @paljs/cli
  2. Create a new project

    pal create my-app --example full-stack-nextjs --framework "Tailwind CSS + PrismaAdmin UI"
  3. Define your data model

    // prisma/schema.prisma
    model User {
      id    Int     @id @default(autoincrement())
      email String  @unique
      name  String?
      posts Post[]
    }
    
    model Post {
      id        Int     @id @default(autoincrement())
      title     String
      content   String?
      published Boolean @default(false)
      author    User    @relation(fields: [authorId], references: [id])
      authorId  Int
    }
  4. Generate GraphQL API

    cd my-app
    pal generate
  5. Start developing

    npm run dev

Choose Your Architecture

Nexus Schema-First

pal create my-nexus-api --example apollo-nexus-schema

Perfect for: Type-safe GraphQL with excellent TypeScript integration

SDL-First

pal create my-sdl-api --example apollo-sdl-first

Perfect for: Schema-first development with flexible resolver patterns

GraphQL Modules

pal create my-modular-api --example graphql-modules

Perfect for: Large, scalable applications with modular architecture

Full-Stack Next.js

pal create my-fullstack-app --example full-stack-nextjs

Perfect for: Complete web applications with admin interfaces

Use Cases

Rapid Prototyping

  • Generate complete GraphQL APIs from Prisma schemas
  • Instant admin interfaces for data management
  • Built-in authentication and authorization patterns

Enterprise Applications

  • Multi-schema support for microservices
  • Type-safe code generation
  • Scalable GraphQL architectures

Learning & Education

  • Best practice templates and examples
  • Comprehensive documentation
  • Community support and tutorials

API Modernization

  • Migrate REST APIs to GraphQL
  • Add admin interfaces to existing databases
  • Optimize query performance automatically

Migration & Upgrading

From v7 to v8

# Update all PalJS packages
npm update @paljs/cli @paljs/generator @paljs/nexus

# Regenerate with latest templates
pal generate --force

Database Migrations

# Generate Prisma migration
npx prisma migrate dev

# Regenerate GraphQL schema
pal generate

Features

Features

  • 🔥 Instant CRUD Generation - Auto-generate complete GraphQL schemas, resolvers, and mutations
  • 🎨 Admin UI Components - Ready-to-use React admin interfaces with full CRUD operations
  • Query Optimization - Automatic field selection and query optimization for better performance
  • 🏗️ Project Scaffolding - Create full-stack applications with modern frameworks and best practices
  • 🎯 Type Safety - Full TypeScript support across all packages and generated code
  • 🔧 Multiple Architectures - Support for Nexus, SDL-first, and GraphQL Modules approaches

Performance & Best Practices

Query Optimization

  • Automatic field selection based on GraphQL queries
  • Reduced database load with smart relationship loading
  • Built-in query complexity analysis

Security

  • Input validation and sanitization
  • Rate limiting and query depth limiting
  • Secure authentication patterns

Monitoring

  • Built-in performance metrics
  • Error tracking and logging
  • Development and production optimizations

Community & Support

Resources

  • Documentation - Comprehensive guides and API references
  • Examples - Real-world project templates
  • Blog - Tutorials, tips, and best practices

Community

Contributing

We welcome contributions! See our Contributing Guide for details.

Professional Support

Need enterprise support? Contact us at [email protected]


Configuration

Basic Configuration (paljs.config.js)

module.exports = {
  schema: './prisma/schema.prisma',
  backend: {
    generator: 'nexus', // 'nexus' | 'sdl' | 'graphql-modules'
    output: './src/graphql',
    excludeFields: ['password', 'hash'],
    excludeModels: [{ name: 'Log', queries: true, mutations: false }],
  },
  frontend: {
    admin: {
      models: ['User', 'Post', 'Category'],
      output: './src/admin/pages',
    },
  },
};

Multi-Schema Configuration

module.exports = {
  multiSchema: true,
  schemas: {
    user: {
      schema: './prisma/user.prisma',
      backend: { generator: 'nexus', output: './src/graphql/user' },
    },
    blog: {
      schema: './prisma/blog.prisma',
      backend: { generator: 'sdl', output: './src/graphql/blog' },
    },
  },
};

License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ by the PalJS team

⭐ Star on GitHub💬 Join Discord📚 Read Docs