Skip to content

graphql-js/graphene-sequelize

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Graphene-JS Build Status PyPI version Coverage Status

A Sequelize integration for Graphene-JS.

Installation

For installing Graphene Sequelize, just run this command in your shell

npm install --save graphene-sequelize
# or
yarn add graphene-sequelize

Examples

Here is a simple Sequelize model:

import * as Sequelize from "sequelize";

const UserModel = sequelize.define("user", {
  name: Sequelize.STRING,
  lastName: Sequelize.STRING
});

To create a GraphQL schema for it you simply have to write the following:

import { ObjectType, Field, Schema } from "graphene-js";
import { SequelizeObjectType } from "graphene-sequelize";

@SequelizeObjectType({ model: UserModel })
class User {
  // Fields will be populated automatically from the sequelize
  // model, and we can also add extra fields here.
}

class Query {
  @Field([User])
  users() {
    return UserModel.findAll();
  }
}

schema = new Schema({ query: Query });

Then you can simply query the schema:

const query = `
query {
  users {
    name,
    lastName
  }
}
`
result = await schema.execute(query)

To learn more check out the following examples:

Contributing

After developing, the full test suite can be evaluated by running:

yarn test --coverage

Documentation

The documentation is generated using the excellent Sphinx and a custom theme.

The documentation dependencies are installed by running:

cd docs
pip install -r requirements.txt

Then to produce a HTML version of the documentation:

make html

About

Graphene Sequelize integration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published