Skip to content

Latest commit

 

History

History
executable file
·
88 lines (53 loc) · 2.81 KB

README.md

File metadata and controls

executable file
·
88 lines (53 loc) · 2.81 KB

Ionic3 App + GraphQL Server on Cloud Functions for Firebase

This repo shows how to implement an architecture using Express + GraphQL + Sequelize in the backed, and an Ionic application in the frontend.

The logic is a simple CRUD of contacts with fields: name, address and phone.

The data layer is managed by Sequelize using SQLite as persistence.

GraphQL is handled with the Apollo libraries.

TLDR;

Host your GraphQL Server on Cloud Functions enabling rapid development with GraphQL on a low-cost, auto-scaling web server leveraging Firebase's sweet, sweet developer experience.

Cloud Functions can accept an Express Server object directly, so leverage the Apollo apollo-server-express pacakge to setup our GraphQL server.

Routes

Schema: https://us-central1-<project-name>.cloudfunctions.net/api/schema

GraphiQL: https://us-central1-<project-name>.cloudfunctions.net/api/graphiql

GraphQL: https://us-central1-<project-name>.cloudfunctions.net/api/graphql?<query>

Requirements

You need to have installed on your computer:

  • Node.js
  • Yarn (optional) # npm install -g yarn
  • Firebase tools # npm install -g firebase-tools

Installation

git clone https://github.com/jonathanferreyra/ionic-graphql-firebase-starter
cd ionic-graphql-firebase-starter
yarn install

# install firebase functions packages
cd functions/ && yarn install

# install ionic packages
cd app/ && yarn install

Note: you can use npm install instead of yarn install

Environment

  • Node 6.11.1

Setup empty database

npm install -g sequelize-cli

sequelize model:create --name Contact --attributes name:string,address:string,phone:string

sequelize db:migrate

sequelize db:seed:all

Local Development

yarn serve

This will serve the Cloud Functions locally using the Firebase emulator.

After running the first time, you can rerun using yarn test or what is the same cd dist/functions && node server.js

Ionic app

From the app you can try operations: create, edit, update, list & search

Deploy to Firebase

yarn deploy

N.B.: Replace <project-name> in the .firebaserc to connect the project to your Firebase project.