- Go 1.16+
- Run
go mod download
in the directory ofAPIGATEWAY
Run make all
or make clean all
to compile the binaries, apigateway
and membermutation
in bin/
.
Configurations file names are implicitly hardcoded in cmd
via vipers
- Prepare
config.yaml
forapigateway
in theconfigs
diractory. - Prepare
membermutationConfig.yaml
formembermutation
in theconfigs
diractory. - Prepare the firebase credential and set the location in the config files. It will be used for verify firebase token.
Provides APIs for:
- Verify token
- Content delivery according to the member subscription state and content state
- Expose a GraphQL service for the queries and mutations of members and subscriptions
Architecture-wise, please check doc/infra.png
to see how it interact with other services.
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
.
apigateway
provides the following endpoints
/api/v2/graphql/member
as the GraphQL endpoint/api/v1/tokenState
as a simple token verification endpoint/api/v0/*
, any requests coming through it will be proxied to therestful service
in k8s./api/v0/story
, requests will be treated as content requests and proxied as agetposts
request. The response would be truncated if the content is premium/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
- Route functions can be found in
server/route.go
. - There several crucial middlewares
SetIDTokenOnly
to parse the token and save it to gin.ContextSetUserID
to parse the userID, i.e., Firebase ID, of the token and save it to gin.Context tooAuthenticateIDToken
to verify the token status and reject the request if it's not validAuthenticateMemberQueryAndFirebaseIDInArguments
to verify the firebaseID in the where filter of GraphQL requests against the token
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.
apigateway
stitchesgraph/member/type.graphql
, andgraph/member/query.graphql
as the first schema. Sends related GraphQL requests toMember GraphQL Service
. They needs to be in sync withMember GraphQL Service
.apigateway
stitchesgraph/member/type.graphql
, andgraph/member/mutation.graphql
as the second schema. Sends related GraphQL requests tomembermutation
. The implementation mutations are ingraph/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.
#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