Skip to content

Latest commit

 

History

History
96 lines (72 loc) · 1.86 KB

File metadata and controls

96 lines (72 loc) · 1.86 KB

Apollo Server Examples

This repository has some examples how to use apollo server. Please access Apollo Server to understand more details.

  1. A simple case. There are no data sources, just exist 1 query.
  2. A simple case that includes structured data and query, mutation. It works in memory.
  3. Rest API case. It calls one of GitHub API.
  4. Another API. It includes 2 APIs, GitHub API and PokéAPI.
  5. RDB and Authentication. It use PostgreSQL to have user table.
  6. Clustered server.
  7. Firestore integration.

These examples use graphql-tools to simplify code.

But I recommend other tools like graphql-code-generator

How to use

Before try it, please install packages.

yarn install

# or

npm install

Start

  1. Create .env file based on .env.example

    • If you use Postgres example, you need to prepare the information on your Postgres. Of course you can use other RDB like sqlite, mysql etc.
    • If you use Firestore example, you need to prepare secret file which approve this app admin.
  2. Start server

cd /path/to/example
# cd 0_examples/01_simple
node ./app.js

Check

Please access http://localhost:4000

Firestore integration.

This server use firebase-admin to treat firestore data.

This example assume the following data structure on firestore.

{
  "test(root collection)": [
    {
      "auto_generated_id": {
        "id": 0,
        "name": "string"
      }
    }
  ]
}
  • Query example

    query getTest {
      tests {
        id
        name
      }
    }
  • Result

{
  "data": {
    "tests": [
      {
        "id": "1",
        "name": "name1"
      },
      {
        "id": "2",
        "name": "name2"
      }
    ]
  }
}