Swapi API GraphQL Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//constants.js | |
export const APP_PORT = 5000 | |
export const BASE_URL = 'https://swapi.co/api' // star wars API base URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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