Giter Club home page Giter Club logo

jsonplaceholder-typicode-gql's Introduction

Jsonplaceholder-typicode-gql

Convert RestAPI to GraphQL from https://jsonplaceholder.typicode.com

To https://jsonplaceholder-typicode.herokuapp.com/graphiql

GraphQL layer that integrates existing systems

Another major use case for GraphQL is the integration of multiple existing systems behind a single, coherent GraphQL API. This is particularly compelling for companies with legacy infrastructures and many different APIs that have grown over years and now impose a high maintenance burden. One major problem with these legacy systems is that they make it practically impossible to build innovative products that need access to multiple systems.

In that context, GraphQL can be used to unify these existing systems and hide their complexity behind a nice GraphQL API. This way, new client applications can be developed that simply talk to the GraphQL server to fetch the data they need. The GraphQL server is then responsible for fetching the data from the existing systems and package it up in the GraphQL response format.

Just like in the previous architecture where the GraphQL server didn’t care about the type of database being used, this time it doesn’t care about the data sources that it needs to fetch the data that’s needed to resolve a query.

Source from: https://www.howtographql.com/basics/3-big-picture/

alt text

How to run local

Install package: npm install

Start: npm run start

Start with nodemon (auto reload server): npm run dev

Run with Docker

Run : docker-compose up

How to query & mutation

Query:
List:
  query usersQuery {
    photos{
      total
      items{
        id
        url
      }
    } 
  }

Get detail
  query userQuery {
    user(id: 1) {
      id
      name
      username
      email
    }
  }

Mutation:
mutation addUser($name: String, $username: String!, $email: String!, $avatar: String){
createNewUser(input:{
 	name: $name,
  username: $username,
  avatar: $avatar,
  email: $email
}){
  user{
    id
  }
}
}

varialbes:
{
  "name": "Son",
  "username": "sondeptrai",
  "email": "[email protected]",
  "avatar": "http://avatar.com/img.png"
}

Structure

config // config env for project
  default.js //default config env 
  development
  production
src
  graphql
    connectors #
      httpConnecttor //defind HTTPConnecttor call to ms-service
      index.js
    errors // To 
      apolloError.js //Show apollo error
      formatError.js
      index.js
      microserviceError.js //Show error when call to ms-service
    models
      ...#You can add more Models look like User
      User
        resolvers //Resolver for schema
          index.js
          mutation.js
          queries.js
          type.js
        schema
          index.js
          schema.gql //Defined schema type
          mutation.gql //Defined Mutation type
          input.gql // Defined Input type
        index.js // Exports resolvers, schema, userList, userModel.js // Defind User class
        userList.js // Defind UserList class
      index.js //Import all models of GraphQL
      root.js //Export rootSchema
      rootSchema.gql Defined all Mutation & Query
    utils
    index.js
  index.js
  plugin.js
  server.js
Dockerfile
docker-compose.yml

jsonplaceholder-typicode-gql's People

Contributors

nvs2394 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

scherlock90

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.