Git Product home page Git Product logo

graphcountries's Introduction

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

graphcountries's People

Contributors

dependabot[bot] avatar lennertvansever avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.