Quick Start

The sGraph server ships with good features to get up and running with a simple graphql server. It is quite straight forward to spin up a server

npx @sayjava/sgraph --schema schema.graphql --database sqlite::memory:

Server Configuration

All supported configurations options can also be passed on as command line flags e.g --schema new.graphql --port 9090

Supported configuration file formats are:

  • sgraphrc
  • sgraphrc.json

Sample Full Configuration

{
    // Port number to start the server on
    "port": 8080,

    // The path to the schema file containing the graphql definitions
    "schema": "schema.graphql",

    // Enable the included Altair client reachable at /graphql in the browser
    "ui": true,

    // Enable cors request handling
    "cors": true,

    // The path that the API will be served on
    "path": "/graphql",

    // Enable Apollo tracing
    "tracing": false,

    // Depth limit for API calls
    "depthLimit": 3,

    // Enable logging (SQL and Resolver)
    "log": false
}

Configurations can be loaded from a different location using:

npx @sayjava/sgraph --config path/to/another/config

Supported Databases

sGraph supports all the same databases that are supported by Sequelize ORM

DatabaseDependenciesBundledConnection
SQLitesqlite3Yessqlite:path-to-file.sqlite
Postgrespg pg-hstoreYespostgres://user:pass@example.com:5432/dbname
MySQLmysql2Yesmysql://user:pass@example.com:3306
MariaDBmariadbNomariadb://user:pass@example.com:3306
Microsoft SQL ServertediousNoCheck the sequelize docs
Amazon Redshiftibm_dbNoCheck the sequelize docs
Snowflake’s Data CloudodbcNoCheck the sequelize docs

Programmatic Middleware

Bring your own sever. If you have an existing server or an SSR application, sGraph can be used as a middleware without spinning up a new server

import express from 'express'
import { useTiming } from '@envelop/core'
import { createHTTPGraphql } from '@sayjava/sgraph'

const server = express()
const { handler } = createHTTPGraphql({
    schema: 'schema.graphql',
    // sequelize database connection
    database: 'database:connection',
})

server.use(bodyParser.json())
server.post('/graphql', handler)

server.listen(8080, () => console.log(`Server started`))
Edit this page on GitHub Updated at Tue, Mar 8, 2022