Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to support plugin like babel #59

Open
4 tasks
sibelius opened this issue Feb 6, 2017 · 9 comments
Open
4 tasks

Refactor to support plugin like babel #59

sibelius opened this issue Feb 6, 2017 · 9 comments

Comments

@sibelius
Copy link
Collaborator

sibelius commented Feb 6, 2017

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.
@sibelius
Copy link
Collaborator Author

sibelius commented Feb 7, 2017

First draft of Plugins

Read Database Schema Plugins

Motivation

A read schema plugin should read a schema (collection/table definition) and return an object describing it.

Examples

  • create-graphql-mongoose
  • create-graphql-mysql
  • create-graphql-postgres
  • create-graphql-rethinkdb

Templates Plugins

Motivation

CreateGraphql should output a different file for a different option provided, for instance: output a raw mutation or a relay mutation

Examples

  • create-graphql-type-raw
  • create-graphql-type-relay
  • create-graphql-mutation-raw
  • create-graphql-mutation-relay

we need to define inputs and outputs of these plugins

@lucasbento
Copy link
Collaborator

I can imagine it to handle schema from multiple types of databases but how would that be for different templates?

@lucasbento
Copy link
Collaborator

Also, how do you plan on starting, should #43 wait for it?

Turning the mongoose schema reading into a plugin should be really straightforward.

We should also have a plugins property on .graphqlrc.

@sibelius
Copy link
Collaborator Author

sibelius commented Feb 7, 2017

A template plugin could have an option parameter, like -t for template

@lucasbento
Copy link
Collaborator

A template plugin could have an option parameter, like -t for template

@sibelius: what do you mean?

I meant, how will we implement a template plugin? Will we prepare all the variables, pass it to the plugin and it will return the files?

@sibelius
Copy link
Collaborator Author

sibelius commented Feb 7, 2017

Yep, I think so, we need to define the inputs and outputs of each plugin

@lucasbento
Copy link
Collaborator

lucasbento commented Feb 27, 2017

So, I started working on this, I thought the following as a blueprint for a create-graphql-plugin:

export default {
  pre: (arguments) => {
    const {
      config, // The content of `.graphqlrc`, will be the default if it doesn't exist
    } = arguments;

    console.log('this is a pre hook function');

    return {
      fields, // The fields generated on the plugin
      files, // Array of objects, e.g.: [{ name: 'ExampleAddMutation.js', content: 'Content of file }]
    };
  },
  post: (arguments) => {
    const {
      config, // The content of `.graphqlrc`, will be the default if it doesn't exist,
      fields, // The fields of the schema
    } = arguments;

    console.log('this is a post hook function');

    return {}; // What would this return?
  },
};

Would love your opinions on this, @sibelius & @felippepuhle.

Also, the plugins would be installed as a devDependency and specified on .graphqlrc under plugins, e.g.:

{
  "directories": {
    ...
    "connection": "connection",
    "loader": "loader",
    "model": "model",
    ...
  },
  "plugins": [
    "create-graphql-plugin-mongoose",
    "create-graphql-plugin-sequelize",
    ...
  ]
}

The generator would then call each plugin based on the order defined, so it would call the mongoose one and then sequelize with the results brought from mongoose.

Still have to figure out how we will deal with files.

@lucasbento
Copy link
Collaborator

Good content on Babel plugins: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md

@lucasbento
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants