A wrapper around The Star Wars API built using GraphQL converting it into this schema.
Install dependencies with
npm installA local express server is in ./server. It can be run with:
npm run build
npm run startA GraphiQL instance will be opened at http://localhost:xxxx/ (the actual port number will be printed to the console) to explore the API.
Send out the queries, there are several schemas to use with (Paste one of the following schemas into the left column and click on the PLAY button on left up corner):
{
allFilms
{
films
{
title
episodeID
openingCrawl
director
producers
releaseDate
}
}
}
{
allPeople
{
people
{
name
birthYear
eyeColor
gender
hairColor
height
mass
skinColor
homeworld
{
name
diameter
rotationPeriod
orbitalPeriod
gravity
population
climates
}
}
}
}
{
allPlanets {
planets {
name
diameter
rotationPeriod
orbitalPeriod
gravity
population
climates
terrains
surfaceWater
}
}
}
{
allSpecies {
species {
name
classification
designation
averageHeight
averageLifespan
eyeColors
hairColors
skinColors
language
homeworld {
name
diameter
rotationPeriod
population
}
}
}
}
{
allStarships {
starships {
name
model
starshipClass
manufacturers
costInCredits
length
crew
passengers
maxAtmospheringSpeed
hyperdriveRating
MGLT
cargoCapacity
consumables
}
}
}
{
allVehicles {
vehicles {
name
model
vehicleClass
manufacturers
costInCredits
length
crew
passengers
maxAtmospheringSpeed
cargoCapacity
consumables
}
}
}
- Play button: to fulfill the queries in left column and show responses in the right column
- Prettify button: to prettify the JSON format.
- History button: click on the History button so that you can see the history queries you have been made.
- Docs button: Can check the schema types in the search bar, for example, input allFilms.
- Based on the GraphQL HTTP Server middleware to render the whole page, use Express to load the graphiql page:
import express from 'express';
import graphqlHTTP from 'express-graphql';
const app = express();
app.use(
'/',
graphqlHTTP(() => ({
schema: swapiSchema,
graphiql: true,
})),
);
- Use Node.js to assign local port and start local server.
- Listening to user's input JSON in local port.
- When get the input JSON, decode from Root node, like allVehicles. The local graphql schema resolvers decode each field to get id string and type string.
- Use DataLoader to get data from url
https://swapi.co/api/${type}/${id}/(The type and id comes from the above step)
References:
- graphql-js - a JavaScript GraphQL runtime.
- DataLoader - for coalescing and caching fetches.
- express-graphql - to provide HTTP access to GraphQL.
- GraphiQL - for easy exploration of this GraphQL server.