Skip to content

Instantly share code, notes, and snippets.

@joeynimu
Last active May 28, 2018 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeynimu/f6452b1a5159599a54f798dfe174594a to your computer and use it in GitHub Desktop.
Save joeynimu/f6452b1a5159599a54f798dfe174594a to your computer and use it in GitHub Desktop.
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