Graphql is a query language and a web service architectures.
In theory, we can use this plugin for all service based on graphql. But some graphql implementations are different because they customize it. We may need to change some code to fit it. Or we can use aws appsync.
Graphql is a query language, so, to use graphql, we need to learn the language first. We can also use firecamp or paw to generate the query. But we still need to write schema and resolver. Or we can use appsync to generate it automatically.
Graphql introduces us two major features, request and subscription.
To send request, we need to call send graphql request with endpoint, method(most of the cases, just leave it as post), query, operation name, variables, headers.
If the request success, result will be returned in data pin.
Subscription is a feature which can help us get data in realtime.
To start a subscription, we need to create a subclass of graphql subscription handler first. Graphql subscription handler is used to help us receive data message. We need to override the on receive data message event in graphql subscription handler to receive data message.
Then, we need to construct the graphql subscription handler with game instance.
Game instance is used to set timer for ka, also know as keep alive, message. If ka message is missing, the connection will be disconnected and on keep alive message missing event in subscription handler will be trigered.
Next, we need to call subscribe graphql subscription with endpoint, header, query parameters, handler.
Then we need to call connect to connect with handler to connect the graphql subscription service.
After that, we can call send start subscription request from subscription handler with id, query, variables, authorization to start a subscription.
We can call is connected from subscription handler to check whether it's still connected the graphql subscription service.
We can call disconnect from subscription handler to disconnect the graphql subscription service.
Appsync is an aws based on graphql. We can use appsync to set up graphql web api for our game. There are many other graphql implementations which we can use with this plugin as well.
The most different part of appsync compare to standard graphql is appsync uses vtl as resolver language.
This plugin also provide functions to help us using appsync.
We can get appsync api's request endpoint from web console.
For subscription endpoint, we nee to change
We need to get host from the endpoint as well, we need to remove
from the endpoint to get the host of appsync graphql api.
There are 3 types of authorization methods supported in appsync: api key, openid connect, IAM.
We can set the default authorization mode and add addition authorization provides after we create an appsync graphql api.
Api key is the simplest authorization method. Api key can only be default authorization mode. We can add new api keys after we create the appsync graphql api.
To use api key, we need to call aws appsync graphql api key helper with host and api key.
Openid connect is also a simple authorization method. We can set openid connect or cognito user pool as default authorization mode or add openid connect or cognito user pool as an additional authorization provider.
To use openid connect, we need to call aws appsync graphql oidc helper with host and api key.
IAM is the most complicated authorization method. We can set IAM as default authorization mode or add IAM as an additional authorization provider.
To use IAM, we need to call aws appsync graphql IAM helper with host, access key id, secret key, security token, query, operation name, variables, date, region and leave the rest as default.