GithubHelp home page GithubHelp logo

shaungehring / python-graphql-federation-sample Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 5.0 21 KB

This is an example of using GraphQL federation with python. This includes multiple python graphql servers and a federated gateway.

License: MIT License

Dockerfile 3.75% Python 96.25%
python graphql graphql-server graphql-federation schema-federation apollo-federation

python-graphql-federation-sample's Introduction

Python GraphQL Federation Sample

This is an example of using GraphQL federation with python. This includes multiple python graphql servers and a federated gateway.

GraphQL Servers

Each server is made up of a default set of components

  • app.py - This is a generic Flask based application file to serve the GraphQL service. This does not need to be modified outside of the Flask Port.
  • schema/schema.graphql - This is the standard schema file where you define and document your service.
  • schema/schema.py - This is the Class that you will use most. This allows you to create your resolvers and return the final schema to the Flask App
  • schema/data_interface.py - This is just me stubbing out a data service so you can test this. You would create your own access to a DB or you could have this access a REST Api if you want.

Server A (User)

All data asociated with the User User - http://localhost:8300

Server B (Photo)

All data asociated with the Photo Photo - http://localhost:8301

Server C (Review)

All data asociated with the Review Review - http://localhost:8302

Federated Gateway

Gateway - http://localhost:4000

Docker Compose

To run this demo

docker-compose up --build

The Query Browser will run at http://localhost:4000 this is where you can test queries.

The config will also allow you yo use the individual GraphQL servers.

Sample Queries

This will connect all of the GraphQL Schemas with one query.

query {
  users(first_name:"Han"){
    id
    first_name
    last_name
    photos{
      id
      url
      reviews{
        id
        title
        body
      }
    }
  }
}
{
  "data": {
    "users": [
      {
        "id": "100",
        "first_name": "Han",
        "last_name": "Solo",
        "photos": [
          {
            "id": "1000",
            "url": "https://upload.wikimedia.org/wikipedia/en/thumb/b/be/Han_Solo_depicted_in_promotional_image_for_Star_Wars_%281977%29.jpg/220px-Han_Solo_depicted_in_promotional_image_for_Star_Wars_%281977%29.jpg",
            "reviews": [
              {
                "id": "10000",
                "title": "Great Photo",
                "body": "Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, "
              }
            ]
          },
          {
            "id": "1001",
            "url": "https://pbs.twimg.com/media/BlrdTeMIQAAN1rv.jpg",
            "reviews": [
              {
                "id": "10001",
                "title": "Great Photo",
                "body": "Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, Lorem Ipsum Set Adore, "
              }
            ]
          }
        ]
      }
    ]
  }
}

python-graphql-federation-sample's People

Contributors

shaungehring avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-graphql-federation-sample's Issues

error when running apollo gateway

Hello,

I tried to run the demo but I stumbled upon an error when running apollo gateway

Do you know what can be the cause? Is it related to federation v2?

$ node index.js
Server ready at http://localhost:4000/
Error checking for changes to service definitions: Couldn't load service definitions for "user" at http://localhost:8300: request to http://localhost:8300/ failed, reason: connect ECONNREFUSED ::1:8300
This data graph is missing a valid configuration. Couldn't load service definitions for "user" at http://localhost:8300: request to http://localhost:8300/ failed, reason: connect ECONNREFUSED ::1:8300

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.