Giter Club home page Giter Club logo

apigateway's Introduction

apigateway

Preliminaries

  1. Go 1.16+
  2. Run go mod download in the directory of APIGATEWAY

Build

Run make all or make clean all to compile the binaries, apigateway and membermutation in bin/.

Run

Configurations file names are implicitly hardcoded in cmd via vipers

  1. Prepare config.yaml for apigateway in the configs diractory.
  2. Prepare membermutationConfig.yaml for membermutation in the configs diractory.
  3. Prepare the firebase credential and set the location in the config files. It will be used for verify firebase token.

Responsibility

Provides APIs for:

  1. Verify token
  2. Content delivery according to the member subscription state and content state
  3. Expose a GraphQL service for the queries and mutations of members and subscriptions

Design

Architecture-wise, please check doc/infra.png to see how it interact with other services.

infra diagram

CMD

APIGATEWAY composites two process, apigateway and membermutation, which are located in the cmd folder. The handling of GraphQL mutation falls to membermutation. Anything else is the responsibility of apigateway, which is also the entrypoint of the whole service and relay GraphQL mutation to membermutation.

Endpoints

apigateway provides the following endpoints

  1. /api/v2/graphql/member as the GraphQL endpoint
  2. /api/v1/tokenState as a simple token verification endpoint
  3. /api/v0/*, any requests coming through it will be proxied to the restful service in k8s.
    1. /api/v0/story, requests will be treated as content requests and proxied as a getposts request. The response would be truncated if the content is premium
    2. /api/v0/getposts, /api/v0/posts, and /api/v0/post, requests are treated content requests. The response would be truncated if the content is premium and the member has no premium privilege

Routes and middlewares

  1. Route functions can be found in server/route.go.
  2. There several crucial middlewares
    1. SetIDTokenOnly to parse the token and save it to gin.Context
    2. SetUserID to parse the userID, i.e., Firebase ID, of the token and save it to gin.Context too
    3. AuthenticateIDToken to verify the token status and reject the request if it's not valid
    4. AuthenticateMemberQueryAndFirebaseIDInArguments to verify the firebaseID in the where filter of GraphQL requests against the token

GraphQL Schema

UGLY PART

The schema is manually maintained. It's defined as in graph/member/type.graphql, graph/member/query.graphql, and graph/member/mutation.graphql.

The usage of pathes is hardcoded in routes.

Modification of them is a pain in the something.

How/when to use/change them

  1. apigateway stitches graph/member/type.graphql, and graph/member/query.graphql as the first schema. Sends related GraphQL requests to Member GraphQL Service. They needs to be in sync with Member GraphQL Service.
  2. apigateway stitches graph/member/type.graphql, and graph/member/mutation.graphql as the second schema. Sends related GraphQL requests to membermutation. The implementation mutations are in graph/member/mutationgraph/mutation.resolvers.go

When any of the *.graphql files are changed, apigateway automatically picks them up. However, the implementation of mutations needs to be updated too.

To update them, run go run github.com/99designs/gqlgen generate in graph/member to generate the boilerplate of go codes and update the signatures in graph/member/mutationgraph/mutation.resolvers.go

Implementation can be updated manually after it.

Known Issues:

  • #68: "null" is a keyworkd and can't be used in graphql variables due to a hack in PR#66 (Fiexed in #70)
  • an empty array of input is parsed as null #95
  • Cache doesn't work properly #137

apigateway's People

Contributors

baron-chiu avatar hcchien avatar nickhsine avatar

Watchers

 avatar  avatar

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.