Recently I met a problem.
- For building a GraphQL Application that has a server with AWS AppSync, and Apollo SDK as client tool.
- Ream-time is requrement so I will use GraphQL Subscription. By some reason can not use the Amplify of AWS.
- Integrate them in an iOS client and test them.
There are 3 steps mainly:
- Build server api by AppSync console.
- Build client program and integrate Apollo in it.
- Generate code about GraphQL in client, and test functionality.
Step1 and Step2 can be completed smoothly if following the official docs. But most problems are in step 3.
- If
codegen
failed, it may be there wrong in the schema.json file. Operation.graphql
files are required by default.- Subscription
- Its endPoint is a little different and
Query
,mutation
. - Server that implementd sub protocal of GraphQL over Websocket Protocol may be different.
AppSync
's server protocol isgraphql-ws
, so we need manually config that by Apollo SDK.
- Need customize a header in auth mode.
- Format of payload.
-
Format of payload in connection is different in
Apollo
SDK andAppSync
,so we need fix that. -
Appsync payload
{ "id": "subscriptionId", "type": "start", "payload": { "data": { "query": "query stirng", "variables": "variables" }, "extensions": { "authorization": { "host": "host", "x-api-key": "apikey" } } } }
-
Apollo payload
{ "id": "subscriptionId", "type": "start", "payload": { "variables": "variables", "extensions": "extensions", "operationName": "subscriptionName", "query": "quey string" } }
-
- Its endPoint is a little different and
Because of something above, I customized a simple network class as a sample. It just contains some simple and required things.