Socket
Socket
Sign inDemoInstall

archen

Package Overview
Dependencies
3
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    archen

Archen - Add GraphQL API to your existing applications


Version published
Maintainers
1
Install size
3.12 MB
Created

Readme

Source

Archen is a simple, flexible and fast GraphQL library written in Typescript.

Installation

$ npm install archen

Usage

Archen is ridiculously easy to use. In the simplest form, it requires nothing more than the details to connect to an existing database. Below is an example to add GraphQL API to a MySQL database:

const { Archen } = require('archen');

const archen = new Archen({
  database: {
    connection: {
      dialect: 'postgres',
      connection: {
        user: 'root',
        password: 'secret',
        database: 'example'
      }
    }
  }
});

await archen.bootstrap();

const source = `
  query {
    users {
      id
      email
    }
  }
`;

const result = await archen.query({ source });

// console.log(result.users);

Command line

Archen provides a command line tool that lets you add GraphQL API to your existing databases without writing any code:

$ npm install express express-graphql mysql archen
$ node_modules/archen/bin/archen.js --user root --password secret --database example --listen 3000

Now you can open a browser and go to http://localhost:3000/graphql to interact with an automatically generated GraphQL server by Archen.

Configuration

Archen can be configured using an ArchenConfig object.

Exporting models to GraphQL API

By default, archen exports all models and fields to the GraphQL API. To stop a model from being exported, add an entry in graphql.models field and set it to false. The following config shows how to export all models except for User:

{
  graphql: {
    models: {
      User: false
    }
  }
}

Setting graphql.allowAll to false stops all models being exported to the API by default. The following config exports only Product and Category to the API:

{
  graphql: {
    allowAll: false,
    models: {
      Product: true,
      Category: true
    }
  }
}

Customising accessibility

The following config forbids creating User objects via the generated API:

{
  graphql: {
    models: {
      User: {
        create: false,
      },
    }
  }
}

Development

Running tests

# Test for SQLite
$ DB_TYPE=sqlite3 npm run test

# Test for Postgres
$ DB_TYPE=postgres DB_USER=postgres npm run test

# Test for MySQL
$ DB_TYPE=mysql DB_USER=root DB_PASS=secret npm run test

FAQs

Last updated on 31 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc