GithubHelp home page GithubHelp logo

aerogear / create-graphql Goto Github PK

View Code? Open in Web Editor NEW
441.0 441.0 50.0 6.42 MB

Command-line utility to build production-ready servers with GraphQL.

License: MIT License

JavaScript 100.00%
boilerplate cli express graphql graphql-server koa mongoose nodejs relay yeoman

create-graphql's Introduction

Create-GraphQL Logo

Create GraphQL

Create production-ready GraphQL servers

NOTE: New command line client is currently under construction

About

Create-GraphQL is a command-line utility to build production-ready servers with GraphQL and also generate Mutations, Types and more into existent projects

Check out the post Announcing Create-GraphQL on Entria medium

Install

With Yarn:

yarn global add create-graphql

With NPM:

npm install --global create-graphql

Usage

You can create a brand new GraphQL project:

create-graphql init GraphQLProject

And can generate single files for Mutation, Type and others:

create-graphql generate --mutation Story

This generates a StoryAddMutation and StoryEditMutation

See more usage examples in the docs

Contributing

If you want to contribute, see the Contributing guidelines before and feel free to send your contributions.

Feedbacks

We love the feedbacks. It's help us to continue grow and improve. Give your feedbacks by open an issue. We will be glad to discuss your suggestions!

License

MIT © Lucas Bento

create-graphql's People

Contributors

danielfttorres avatar felippepuhle avatar greenkeeper[bot] avatar jcmais avatar lucasbento avatar rodrigooler avatar sibelius avatar wtrocki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

create-graphql's Issues

Support raw GraphQL Mutation

Example of raw graphql mutation based on https://learngraphql.com/basics/defining-mutations/2

const Mutation = new GraphQLObjectType({
  name: "BlogMutations",
  description: "Mutations of our blog",
  fields: () => ({
    createPost: {
      type: Post,
      args: {
        title: {type: new GraphQLNonNull(GraphQLString)},
        content: {type: new GraphQLNonNull(GraphQLString)}
      },
      resolve: function(source, args) {
        let post = Object.assign({}, args);
        // Generate the _id
        post._id = `${Date.now()}::${Math.ceil(Math.random() * 9999999)}`;
        // Assign a user
        post.author = "arunoda";

        // Add the Post to the data store
        PostsList.push(post);

        // return the new post.
        return post;
      }
    }
  })
});

I think this could work on apollo as well

handle mongoose ref

For instance

const Schema = new mongoose.Schema({
   user: {
       type: ObjectId,
       ref: 'User',
       indexed: true,
       description: 'User that created this comment',
       required: true,
  }
});

user field should resolve to UserType

maybe ask to create UserType as well if not created already

Generate dependency files

If the user ask only to generate a mutation file

we should also create the Loader and Connection for that mutation, if these files do not exist

Type name has Type on it

When I create a type User the name of the type is UserType on graphql

it would be better to be only User

Add support for sequelize

How about adding support for generating types from sequelize models in a similar way to mongoose models?

permit local installations

hi,

i'm trying to locally install create-graphql via yarn but i receive this error:

npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "-g" "generator-graphql"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

it would be nice to avoid every reference to global packages in order to install create-graphql globally o locally.

Handle timestamps of Mongoose model

if my model has createdAt and updatedAt like this:

}, {
  timestamps: {
    createdAt: 'createdAt',
    updatedAt: 'updatedAt',
  },
});

it does not create this fields on Loader and Type

Refactor to support plugin like babel

Babel plugin object example:

type PluginObject = {
  pre?: Function;
  post?: Function;
  manipulateOptions?: Function;

  visitor: ?{
    [key: string]: Function | {
      enter?: Function | Array<Function>;
      exit?: Function | Array<Function>;
    }
  };
};

each babel plugin returns an object like this.

we should think in CreateGraphQL PluginObject as well.


  • Separate mongoose schema to a plugin;
  • Separate relay templates to a plugin (figure out how to best do this);
  • Create boilerplate projects for Create-GraphQL plugins;
  • Handle plugins property on .graphqlrc.

update generated files

if I add one or more fields to my mongoose model, it would great to update the generated GraphQL files

[help]do not understand the schema design

Thanks for your work about this repo. And I am not sure whether this is the right place to ask questions.

I'm relative new to graphql world, and know the basic of graphql, also read some apollo graphql things. But not quiet sure how to design real world schema, I notice the github graphql api has something like "Node", "edges", also include in your repo.

where are they come from? relay world? Could it possible not touch the relay instead of using apollo graphql and basic graphql knowledge to get insight of schema design?

thanks again

create-graphql init Spawn error

$ create-graphql init AwesomeProject

✓ GraphQL project AwesomeProject created.
⠋ Creating a new GraphQL project...events.js:160
throw er; // Unhandled 'error' event
^

Error: spawn yarn ENOENT
at exports._errnoException (util.js:1026:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

captura de tela 2017-02-07 as 11 54 50

Any idea?

Read existing 'schema.json' to serve querys/mutations

If we could read an existing schema.json file, for creating the types, queries and mutations allowed by the server, it would be great for frontend development...

Another improvement would be generating "Loren Ipsun"-style data for each type.

This is specially useful for other backend languages/frameworks (Flask, Django, Rails, etc) that generates schema.json file.

An in-range update of yeoman-assert is breaking the build 🚨

Version 2.2.3 of yeoman-assert just got published.

Branch Build failing 🚨
Dependency yeoman-assert
Current Version 2.2.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As yeoman-assert is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build is in progress Details

  • continuous-integration/appveyor/branch AppVeyor build failed Details

Commits

The new version differs by 5 commits .

  • fa51fc5 2.2.3
  • 7d2945b Add eslint as dev dependency
  • 446ff2d Remove last dependency by es6-ing a line of code
  • 69639ae reduce dependencies and code complexity (#20)
  • 41b7f28 Update dependencies to enable Greenkeeper 🌴 (#22)

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of babel-core is breaking the build 🚨

Version 6.23.0 of babel-core just got published.

Branch Build failing 🚨
Dependency babel-core
Current Version 6.22.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As babel-core is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/appveyor/branch AppVeyor build failed Details

  • continuous-integration/travis-ci/push The Travis CI build passed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

/bin/sh: yo: command not found

Somehow I got this error on my macOS

$ create-graphql generate --mutation Awesome
✗ GraphQL CLI requires Yeoman to be installed.
✓ Yeoman installed!
/bin/sh: yo: command not found
(node:37016) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Exited with status 127
(node:37016) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

FYI

$ node --version
v7.4.0

Any hint?

object notation should be optional

hi,

when i'm trying to generate a type and a mutation from this example schema, the generator will crashes because of missing 'type' property on the field.

'use strict'

var mongoose = require('mongoose')
var example= new mongoose.Schema({
	title: String
})

module.exports = mongoose.model('Example', example)

changing the schema in this way make the generator works again:

'use strict'

var mongoose = require('mongoose')
var example= new mongoose.Schema({
	title: { type: String, }
})

module.exports = mongoose.model('Example', example)

Improve Relay generation

I think we need a flag on .graphqlrc to enable some Relay generation code tweaks

for instance a Relay GraphQL Type could have a globalIdField()

Changes required on Type.js.template

import {
  globalIdField,
} from 'graphql-relay';
import {
  NodeInterface,
} from '../interface/NodeInterface';
                                     
fields: () => ({
    id: globalIdField('Company'),
    _id: {
      type: GraphQLString,
      resolve: obj => obj._id,
    },
...

interfaces: () => [NodeInterface],                                                                                 

Create a mongoose schema when generating a new type

I can see that it is possible to create a graphql type or mutation based on an existing mongoose schema using the --schema command, it would be great if creating a model without an existing mongoose schema could generate one.

For example the command:

create-graphql generate -tm User

Generates:

./src/model/User.js

Cannot read property 'toString' of undefined on Loader

we should check if id is valid on Loader.load

static async load(viewer, id) {
    if (!id) return null;

    const data = await User.UserLoader.load(id.toString());

    return User.viewerCanSee(viewer, data) ? new User(data) : null;
  }

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.