Skip to content

lennertVanSever/graphcountries

master
Switch branches/tags
Code

Graph countries

Use GraphQL to query country-related data, free of charge and without restrictions. The data is the same as restcountries.eu with extra emoji's for flags because who doesn't like emoji's?

Explore the playground

Some example queries:

You can also select, paginate, filter, search and order any entity, the options are endless.

Once you have your desired query you can fetch the data like any other GraphQL endpoint but you probably want to use something like appolo client.

fetch('https://countries-274616.ew.r.appspot.com', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ query: `
    query {
      CallingCode {
        name
        countries {
          name
        }
      }
    }

` }),
})
  .then(res => res.json())
  .then(res => console.log(res.data));

How it works

The data from restcountries.eu is scraped with a JS script and inserted into a Neo4j graph database. Afterwards the GraphQL schema is automagically infered by the awesome neo4j-graphql-js package. We add some custom cypher queries to the schema to make the shortest path and distance data possible. Finally an Apollo server is used to create the GraphQL endpoint and playground.

Self hosting

It's quite straightforward to host the API yourself, unfortunately I can't share a read only user to the Neo4j database since I don't have a Neo4j enterprise license so you will need your own Neo4j graph database

Prerequisites:

Getting started:

  1. Clone this repo and navigate to it

  2. Create an .env file on the project root folder with your Neo4j credentials and an optional apollo engine API key

    ENGINE_API_KEY=REPLACE_ME_WITH_YOUR_APOLLO_ENGINE_API_KEY
    BOLT_ADDRESS=REPLACE_ME_WITH_YOUR_NEO4J_BOLT_ADDRESS
    DB_USERNAME=REPLACE_ME_WITH_YOUR_NEO4J_USERNAME
    DB_PASSWORD=REPLACE_ME_WITH_YOUR_NEO4J_PASSWORD
    
  3. Download the dependencies, run npm install

  4. Populate the Neo4j graph database, run npm run dataScraping. When this command is done, you will get an infered schema file in the graphql repo, you can use this to optionally change the main schema.graphql file in the same repo

  5. Start the GraphQL in dev mode, run npm run dev

  6. Visit http://localhost:8080/ to discover your self hosted API, have fun!

Graphql voyager

You can also explore the schema with graphql-voyager

About

An easy to use GraphQL API to query country-related data for free and without restrictions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published