1.2.0 • Published 4 months ago

@nodestitch/pgql v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

pgql

pgql is a TypeScript library that provides automatic bridging between SQL and GraphQL APIs. It allows you to generate Nexus objects that can be used with GraphQL, enabling seamless integration between your database and API.

Features

  • Automatic generation of GraphQL schema based on your PostgreSQL database schema.
  • Support for CRUD operations (CREATE, READ, UPDATE, DELETE).
  • Integration with popular frameworks like Express and Next.js.
  • Built-in support for TypeScript

Installation

NPM

npm install pgql

Yarn

yarn install pgql

PNpm

pnpm install pgql

Usage

Next.js Example

// pages/api/graphql/index.ts
import { NextApiRequest, NextApiResponse } from 'next';
import { createSchema } from './services/graphql/schema';
import { createYoga } from 'graphql-yoga';

export default createYoga<{
    req: NextApiRequest;
    res: NextApiResponse;
}>({
    graphqlEndpoint: '/api/graphql/',
    graphiql: { title: 'My GraphQL Playground' },
    batching: true,
    schema: await createSchema(),
});

// services/graphql/schema.ts
import { generateDBSchema } from 'pgql';
import { makeSchema } from 'nexus';

export async function createSchema() {
    const credentials = {};

    const dbSchema = await generateDBSchema(credentials, {
        schemas: [
            {
                name: 'website',
                tables: [
                    {
                        name: 'user',
                        operations: ['READ'],
                        defaultWhere: `id IS NOT NULL`,
                        cols: ['id', 'name', 'email'],
                    },
                    { name: 'payment', operations: ['CREATE', 'READ', 'UPDATE', 'DELETE'] },
                ],
                views: [{ name: 'payments_per_user', operations: ['READ'] }],
            },
        ],
        generateForeignTables: true,
    });

    const types = await generateSchema(credentials, dbSchema);

    return makeSchema({
        types,
    });
}

License

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

Contributing

Contributions are welcome! Fork the repository, make your changes, and submit a pull request.

Support

If you have any questions, issues, or feature requests, please create an issue on the repository.

1.2.0

4 months ago

1.2.0-beta.44

4 months ago

1.2.0-beta.41

4 months ago

1.2.0-beta.40

4 months ago

1.2.0-beta.43

4 months ago

1.2.0-beta.42

4 months ago

1.2.0-beta.38

4 months ago

1.2.0-beta.39

4 months ago

1.2.0-beta.37

4 months ago

1.2.0-beta.34

4 months ago

1.2.0-beta.33

4 months ago

1.2.0-beta.36

4 months ago

1.2.0-beta.35

4 months ago

1.2.0-beta.30

4 months ago

1.2.0-beta.32

4 months ago

1.2.0-beta.31

4 months ago

1.2.0-beta.27

4 months ago

1.2.0-beta.26

4 months ago

1.2.0-beta.29

4 months ago

1.2.0-beta.28

4 months ago

1.2.0-beta.23

4 months ago

1.2.0-beta.22

4 months ago

1.2.0-beta.25

4 months ago

1.2.0-beta.24

4 months ago

1.2.0-beta.21

4 months ago

1.2.0-beta.20

4 months ago

1.2.0-beta.18

4 months ago

1.2.0-beta.19

4 months ago

1.2.0-beta.9

4 months ago

1.2.0-beta.8

4 months ago

1.2.0-beta.5

4 months ago

1.2.0-beta.4

4 months ago

1.2.0-beta.7

4 months ago

1.2.0-beta.6

4 months ago

1.2.0-beta.16

4 months ago

1.2.0-beta.15

4 months ago

1.2.0-beta.17

4 months ago

1.2.0-beta.12

4 months ago

1.2.0-beta.11

4 months ago

1.2.0-beta.14

4 months ago

1.2.0-beta.13

4 months ago

1.2.0-beta.10

4 months ago

1.2.0-beta.1

4 months ago

1.2.0-beta.3

4 months ago

1.2.0-beta.2

4 months ago

1.1.0

9 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.0

11 months ago

1.0.1

11 months ago