Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.