Coder Social home page Coder Social logo

rpellerin / graphql-sequelize-schema-generator Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 4.0 99 KB

[DEPRECATED] A helper function to automatically generate a GraphQLSchema from Sequelize models.

Home Page: https://www.npmjs.com/package/graphql-sequelize-schema-generator

JavaScript 100.00%
graphql sequelize

graphql-sequelize-schema-generator's Introduction

DEPRECATED: unmaintained

graphql-sequelize-schema-generator

A helper function that automatically generates GraphQLSchema from Sequelize models.

npm version Build Status

js-standard-style

Installation

yarn add graphql-sequelize-schema-generator

or

npm install graphql-sequelize-schema-generator

Prerequisites

This package assumes you have graphql and sequelize already installed (both packages are declared as dependencies and peerDependencies).

Usage

var {generateModelTypes, generateSchema} = require('graphql-sequelize-schema-generator')
var models = require('./models')
var schema = generateSchema(models) // Generates the schema
// OR
var types = generateModelTypes(models)
var schema = generateSchema(models, types) // Generates the schema by reusing the types

Example with Express

var { GraphQLSchema } = require('graphql')
const express = require('express')
const graphqlHTTP = require('express-graphql')
const {generateSchema} = require('graphql-sequelize-schema-generator')
const models = require('./models')

var app = express()

app.use(
  '/graphql',
  graphqlHTTP({
    schema: new GraphQLSchema(generateSchema(models)),
    graphiql: true
  })
)

app.listen(8080, function() {
  console.log('RUNNING ON 8080')
})

graphql-sequelize-schema-generator's People

Contributors

coderreview avatar leopku avatar rpellerin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graphql-sequelize-schema-generator's Issues

Error: Schema query must be Object Type but got: Root_Query.

After a searching, I found this awesome generator.

But I had an issue when I add graphql-sequelize-schema-generator to my project according to readme.

My environment:

    "express": "^4.15.3",
    "express-graphql": "^0.6.7",
    "graphql": "^0.10.5",
    "graphql-relay": "^0.5.2",
    "graphql-sequelize": "^5.4.2",
    "graphql-sequelize-schema-generator": "^0.2.3",
    "lodash": "^4.17.4",
    "mysql2": "^1.4.0",
    "restify": "^5.0.1",
    "sequelize": "^4.4.2"

app.js

import { GraphQLSchema } from 'graphql';
import graphqlHTTP from 'express-graphql';
import ExpressBunyan from 'express-bunyan-logger';
import { /* generateModelTypes, */ generateSchema} from 'graphql-sequelize-schema-generator';
import restify from 'restify';
import logger from './util/logger';
import models from './models';

const app = restify.createServer();
const schema = new GraphQLSchema(generateSchema(models));

app.use(ExpressBunyan({
  'name': 'logger',
  streams: [{
    level: 'info',
    stream: process.stdout
  }]
}));

app.post('/graphql', graphqlHTTP({
  schema,
  graphiql: false
}));

app.get('/graphql', graphqlHTTP({
  schema,
  graphiql: true
}));

const port = process.env.PORT ? parseInt(process.env.PORT) : 3300;
app.listen(port, () => logger.info(`now server is listening in port: ${port}`));

I can't start it with error:

Schema query must be Object Type but got: Root_Query.

What's wrong with my project? Any guys would help me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.