Skip to content

JustinWang23/graphql-grpc-apollo-mali-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL + gRPC

This is a sample project using Apollo as an isolate GraphQL server and using Mali as a gRPC backend microservice server.

Installation

git clone [email protected]:JustinWang23/graphql-grpc-apollo-mali-api.git

cd node-graphql

# or if you are using npm: npm install
yarn  

Usage

start graphql server

# cd node-graphql

yarn start

Then you will see the GraphQL playground running 🚀 Server ready at http://localhost:4000/graphql

start microservices server

# cd node-api

yarn start

Now you can connect to the microservices at localhost:50051 via gRPC.

Example

First, we define a schema for GraphQL.

type Books {
  id: Int
  title: String
  author: Author
  price: Float
  categories: [String]
}

type Author {
  id: Int
  name: String
  age: Int
}

type Query {
  listBooks(title: String): [Books]
}

schema {
  query: Query
}

Then, you can make queries for what data you want to fetch.

query {
  listBooks {
    title
    categories
    author {
      name
    }
  }
}

Afterwards, you can get the result based on your queries.

{
  "data": {
    "listBooks": [
      {
        "title": "Talent",
        "categories": [
          "Education",
          "Popular"
        ],
        "author": {
          "name": "Justin"
        }
      },
      {
        "title": "GraphQL",
        "categories": [
          "Skills"
        ],
        "author": {
          "name": "Somebody"
        }
      },
      {
        "title": "Talent is not enough",
        "categories": [
          "Skills",
          "Popular"
        ],
        "author": {
          "name": "Justin"
        }
      }
    ]
  }
}

License

GraphQL-gRPC-Apollo-Mali-Api is licensed under the MIT License.

About

A sample for GraphQL server and gRPC server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published