UNPKG

charlotte-graphql

Version:

Generates GraphQL type definitions and resolvers off of a concise spec.

37 lines (30 loc) 755 B
'use strict'; const http = require('http'); const express = require('express'); const bodyParser = require('body-parser'); const { graphqlExpress, graphiqlExpress } = require('apollo-server-express'); const { generateApi } = require('./api'); const createServer = ({ types, adapter }) => { const app = express(); const server = http.createServer(app); const { schema, typesExpanded, typeDefs, resolvers } = generateApi({ types, adapter }); app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }) ); app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' })); return { app, server, types, typesExpanded, schema, adapter, resolvers }; }; module.exports = { createServer };