Skip to content

FVitor7/POC_Strawberry_GraphQL_Federantion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

POC Strawberry GraphQL and FastAPI

This project demonstrates a federated GraphQL setup composed of two FastAPI microservices and an Apollo Gateway. Each service can be run individually or all together using Docker.

Installation

Use the package manager pip to install requirements.

Go to one of the microservice folders and run:

pip install -r requirements.txt

Usage

Users Microservice

Open the user_service folder in your terminal and run:

uvicorn app:app --port 8000 --reload

Tasks Microservice

Open the task_service folder in your terminal and run:

uvicorn app:app --port 8800 --reload

Gateway

Open the gateway folder in your terminal and isntall npm dependencies:

npm install
npm run-script dev

Federation of the two microservices will be available on port 8080

Access: http://localhost:8080

Running with Docker Compose

To start all services at once use docker-compose:

docker-compose build
docker-compose up

The gateway will be available on http://localhost:8080

Generating the Schema

In the microservice folder run:

strawberry export-schema schema.schema > schema/schema.graphql

Mutations

createUser

mutation {
  createUser(
    cpf: "12345678900"
    email: "fabio@example.com"
    name: "Fábio Vitor"
  ) {
    id
    name
    email
    cpf
  }
}

addCategory

mutation {
  addCategory(categoryName: "Tecnologia") {
    __typename
    ... on Category {
      id
      categoryName
    }
    ... on CategoryExists {
      message
    }
  }
}

addCategory

mutation {
  addTask(
    categoryName: "Tecnologia"
    taskName: "Estudar Federation"
    userId: 1
  ) {
    __typename
    ... on Task {
      id
      taskName
      userId
      category {
        id
        categoryName
      }
    }
    ... on TaskExists {
      message
    }
  }
}

Queries

federation Example

query {
  users(cpf: "12345678900") {
    id
    name
    email
    tasks {
      id
      taskName
      category {
        id
        categoryName
      }
    }
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors