Giter Club home page Giter Club 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?

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

graphcountries's Issues

Help me keep the graphcountries API online

After a year, my free Google Cloud account expired. With an average of 14 requests per minute, it will cost me around โ‚ฌ30 per month to keep it online. That's around 2 Netflix subscriptions in my country.

My goal is that this API can be kept online by contributions from the community. Consider sponsoring me through the Github Sponsors program. If I can reach the goal of $30 per month, I will keep this API in the air for as long as it lasts.

Personally, I'm open to contribute โ‚ฌ100 for this API, this will allow keeping this API online for 3 months. If after this period there are not enough contributions, I will have to bring the API down ๐Ÿ’”

Api has not returned more countries since yesterday.

Message: "Failed to connect to server. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0. Caused by: Failed to establish connection in 30000ms"

License

Hi, I would like to know about the license of this application.
Is MIT?

Using endpoint has SSL issue

Hi,

I am trying to use this endpoint. I have tried to consume the api using the apollo-client library. Both do not seem to work and provide me with the following error:

Screenshot 2020-05-23 at 14 44 17

Bellow is my code:

App.tsx

import React from 'react';
import './App.css';
import ViewCountries from './containers/ViewCountries';
import { ApolloProvider } from '@apollo/react-hooks';
import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { ApolloLink } from 'apollo-link';
import { InMemoryCache } from 'apollo-cache-inmemory';

const httpLink = createHttpLink({
  uri: 'https://countries-274616.ew.r.appspot.com/',
});

const link = ApolloLink.from([httpLink]);

const client = new ApolloClient({
  link,
  cache: new InMemoryCache(),
});

function App() {
  return (
    <ApolloProvider client={client}>
      <ViewCountries />
    </ApolloProvider>
  );
}

export default App;

ViewCountries.tsx

import React from 'react';
import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';

const COUNTRIES = gql`
  {
    countries {
      name
    }
  }
`;

const ViewCountries = () => {
  const { loading, error, data } = useQuery(COUNTRIES);

  return (
    <></>
  );
};

export default ViewCountries;

What am I doing wrong, or is it your server that does not work? ๐Ÿค”

Thank you ๐Ÿ‘

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.