You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have re-graph working with AppSync and Cognito (Amplify), but I needed to make some changes to support subscription. I'll raise a PR very shortly to cast your eye over.
I needed to carefully configure re-graph using the JWT token from my Cognito authorised session. Might be worth getting this into the README?
(nsapp.core
(:require
...
["/aws-exports.js":default aws-exports])) ;; generated by Amplify
(defnclj->json-str [obj]
(.stringify js/JSON (clj->js obj)))
(defnstr->base64 [s]
(.btoa js/window s))
(defnextract-host [url]
(-> url
(string/replace#"^https?://""")
(string/split#"/")
(first)))
(defnre-graph-appsync-init [{:keys [token] :as data}]
(let [graphql-endpoint-url (.-aws_appsync_graphqlEndpoint aws-exports)
;; https://docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html
graphql-endpoint-ws-url (-> graphql-endpoint-url
(string/replace#"^https:""wss:")
(string/replace#"\.appsync-api\."".appsync-realtime-api."))
appsync-host (extract-host graphql-endpoint-url)
header-b64 (str->base64 (clj->json-str {"Host" appsync-host, "Authorization" token}))
payload-b64 (str->base64 (clj->json-str {})) ;; documentation states that an empty payload is required here
graphql-endpoint-ws-url-with-auth (str graphql-endpoint-ws-url "?header=" header-b64 "&payload=" payload-b64)]
(rf/dispatch
[:re-graph.core/init
{:ws {:url graphql-endpoint-ws-url-with-auth
:supported-operations #{:subscribe}
:impl {:subscription-query-as-data?true;; this also will cause extensions to be included in the subscription query payload:extensions {"authorization" {"Authorization" token
"host" appsync-host}}}}
:http {:url graphql-endpoint-url
:supported-operations #{:query:mutation}
:impl {:with-credentials?false:headers {"Authorization" token}}}}])))
The text was updated successfully, but these errors were encountered:
Hi Oli,
I have re-graph working with AppSync and Cognito (Amplify), but I needed to make some changes to support subscription. I'll raise a PR very shortly to cast your eye over.
I needed to carefully configure re-graph using the JWT token from my Cognito authorised session. Might be worth getting this into the README?
The text was updated successfully, but these errors were encountered: