graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.RQL.DDL.Webhook.Transform

Description

Webhook Transformations are data transformations used to modify HTTP Requests/Responses before requests are executed and after responses are received.

Transformations are supplied by users as part of the Metadata for a particular Action or EventTrigger as a RequestTransform record. Per-field Transformations are stored as data (defunctionalized), often in the form of a Kriti template, and then converted into actual functions (reified) at runtime by the Transform typeclass.

We take a Higher Kinded Data (HKD) approach to representing the transformations. RequestFields is an HKD which can represent the actual request data as 'RequestFields Identity' or the defunctionalized transforms as 'RequestFields (WithOptional TransformFn)'.

We can then traverse over the entire RequestFields HKD to reify all the fields at once and apply them to our actual request data.

NOTE: We don't literally use traverse or the HKD equivalent btraverse, but you can think of this operation morally as a traversal. See applyRequestTransform for implementation details.

Synopsis

Documentation

applyRequestTransform :: forall m. MonadError TransformErrorBundle m => (Request -> RequestContext) -> RequestTransformFns -> Request -> m Request Source #

Transform an Request with a RequestTransform.

Note: we pass in the request url explicitly for use in the ReqTransformCtx. We do this so that we can ensure that the url is syntactically identical to what the use submits. If we use the parsed request from the Request term then it is possible that the url is semantically equivalent but syntactically different. An example of this is the presence or lack of a trailing slash on the URL path. This important when performing string interpolation on the request url.

data ResponseTransform Source #

A set of data transformation functions generated from a MetadataResponseTransform. Nothing means use the original response value.

applyResponseTransform :: ResponseTransform -> ResponseTransformCtx -> Either TransformErrorBundle ByteString Source #

At the moment we only transform the body of Responses. 'http-client' does not export the constructors for Response. If we want to transform other fields then we will need additional apply functions.