SwagQL

Use GraphQL in minutes, leave the REST to us

Saumitra Bhanage
Mar 4, 2019 · 3 min read
Image for post
Image for post
Build GraphQL schema from a given Swagger schema

Image for post
Image for post
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
}));
Image for post
Image for post

Groupon Product and Engineering

All things technology from Groupon staff

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store