Git Product home page Git Product logo

apollo-optics-dataloader's Introduction

Apollo + GraphQL + Optics + Facebook DataLoader

This is an Apollo version of the graphql-loader project on github.

Motivation: Complex querying with a rest api and building data driven React apps both suck, so I decided to start by building this server side REST API wrapper. The nice thing about GraphQL is that it can be integrated with any backends (sql, nosql, rest api) pretty quickly and easily. I chose to use Apollo to build my GraphQL server since their tooling makes writing production ready GraphQL servers quicker and more modular.

Key Features:

  • Graphql-Server-Express - Apollo's production ready GraphQL server library for Express
  • GraphQL-tools - Apollo's library to build GraphQL schemas with more ease and modularity
  • GraphQL - Facebook's application level query language and engine
  • GraphiQL - Facebook's in-browser IDE to send queries/mutations
  • Apollo Optics - Analytics for GraphQL
  • DataLoader - Facebook's batching/catching library to cache and reduce number of API calls

SWAPI REST API

This project makes use of the Star Wars REST API at http://swapi.co/ to demonstrate a Apollo Server running on Express integrated with Facebook's DataLoader. This port only has schemas for starships and characters.

Installation

ES6 / Node V4+

This project makes use of ES6 which requires a 4+ version of Node https://nodejs.org/en/download/

Install with:

npm install

API Key Registration

Apply for your own api key on the Apollo website and simply set your OPTICS_API_KEY environment variable to your API key or set it with OpticsAgent.configureAgent({ options }).

Run the project

Running in Development

npm dev is configured with nodmon so that the server automatically restarts when code files are changes

npm run dev
Running in Production
npm start

npm prestart will run first, transpile the ES6 code and save to dist folder. npm start will then run the code directly from the dist folder

Running GraphQL Queries

You can run these queries within GraphiQL, alternatively you can run them within a tool such as Postman. To do so ensure you POST the query / mutation in the body and set the content-type to GraphQL.

Find starship by Id

query{
  starship(id:10){
    name
    manufacturer
    cost_in_credits
    length
    max_atmosphering_speed
    crew
    passengers
    cargo_capacity
    consumables
    hyperdrive_rating
    MGLT
    starship_class
    created
    edited
    pilots{
      name
      hair_color
      skin_color
      eye_color
      birth_year
      gender
      starships {
        name
        manufacturer
        cost_in_credits
        length
        max_atmosphering_speed
        crew
        passengers
        cargo_capacity
        consumables
        hyperdrive_rating
        MGLT
        starship_class
        created
        edited
      }
    }
  }
}

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.