Skip to content

Instantly share code, notes, and snippets.

@joeynimu
Last active May 28, 2018
Embed
What would you like to do?
Swapi API GraphQL Wrapper
//constants.js
export const APP_PORT = 5000
export const BASE_URL = 'https://swapi.co/api' // star wars API base URL
import express from 'express';
import graphqlHTTP from 'express-graphql';
import fetch from 'node-fetch';
import bodyParser from 'body-parser';
import { APP_PORT } from './constants'
import schema from './schema'
const app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json())
app.use(graphqlHTTP({
graphiql: true,
schema,
pretty: true
}));
try {
app.listen(APP_PORT, () => console.log(`GraphQL server running at ${APP_PORT}`))
} catch (error) {
console.log(`Something went wrong ${error}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment