Skip to content

Instantly share code, notes, and snippets.

@MiguelCastillo
Last active October 25, 2016 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiguelCastillo/52dd36d9e3b7b021fd5507dba1ca192e to your computer and use it in GitHub Desktop.
Save MiguelCastillo/52dd36d9e3b7b021fd5507dba1ca192e to your computer and use it in GitHub Desktop.
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { buildSchema } = require('graphql');
const Bitbundler = require('bit-bundler');
// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
input Module {
name: String!
version: String
}
type Result {
name: String!,
version: String
}
type Bundler {
bundle(modules: [Module]): [Result]
bundleAsString(modules: [Module]): String
}
type Query {
bundler: Bundler
}
`);
// This class implements the RandomDie GraphQL type
class Bundler {
bundle({modules}) {
console.log('npm install', modules);
console.log('run bundler', modules);
return modules;
}
bundleAsString({modules}) {
console.log('npm install', modules);
console.log('run bundler', modules);
return 'listo chico';
}
}
// The root provides the top-level API endpoints
var root = {
bundler: function () {
return new Bundler();
}
}
const app = express();
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
rootValue: root
}));
app.listen(4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment