SwagQL

Use GraphQL in minutes, leave the REST to us

Build GraphQL schema from a given Swagger schema

mkdir petstore-graphql
cd petstore-graphql
npm init
curl -o petstore.json https://petstore.swagger.io/v2/swagger.json
npm i swagql express express-graphql gofer
swagql < petstore.json > petstore-graphql.js
// array-to-connection.js
'use strict';module.exports = require('swagql/array-to-connection.js');
// server.js
'use strict';const PORT = 8000;
const express = require('express');
const app = express();app.listen(PORT);
console.log(`Listening on http://localhost:${PORT}`);
// server.js
const graphqlHTTP = require('express-graphql');// before app.listen
app.use('/graphql', graphqlHTTP({
  graphiql: true
}));
const { schema, FETCH } = require('./petstore-graphql');
const Gofer = require('gofer');const apiClient = new Gofer()
                  .with({baseUrl: 'http://petstore.swagger.io/v2'});app.use('/graphql', graphqlHTTP({
  schema: schema,
  context: { [FETCH]: apiClient.fetch.bind(apiClient) },
  graphiql: true
}));

Groupon Engineering

Tech blog from Groupon Engineers

60

60 claps
Saumitra Bhanage

Written by

Groupon Engineering

Tech blog from Groupon Engineers