Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module calculates parameterized query hash, which is a way to hash an incoming query (after resolving variables) with all leaf nodes (i.e. scalar values) discarded. In other words, two queries having the same parameterized query hash are essentially the same query but may differ in leaf values.
For example:
- query { authors (where: {id: {_eq: 2}}) { id name } }
- query { authors (where: {id: {_eq: 203943}}) { id name } }
- query { authors (where: {id: {_eq: $id}}) { id name } }
For any value of id
- query { authors (where: $whereBoolExp) { id name } }
only when whereBoolExp
is of the form of
{ "id": { "_eq": id } }
All the above queries should result in the same parameterized query hash.
The following steps are done to calculate the parameterized query hash:
- Normalize the GraphQL query by substituting the variables (if any) in appropriate places.
- Substitute any scalar GraphQL values (Int, Float, Enum, String and Boolean) to null
- For input objects and list, traverse through them and do step no 2.
- Calculate the hash of the query obtained from step 3.
Note: Parameterized query hash is a PRO only feature
Synopsis
- data ParameterizedQueryHashList
- parameterizedQueryHashListToObject :: ParameterizedQueryHashList -> Object
- newtype ParameterizedQueryHash = ParameterizedQueryHash {}
- normalizeSelectionSet :: SelectionSet NoFragments Variable -> SelectionSet NoFragments Void
- calculateParameterizedQueryHash :: SelectionSet NoFragments Variable -> ParameterizedQueryHash
- mkUnsafeParameterizedQueryHash :: Text -> ParameterizedQueryHash
Documentation
data ParameterizedQueryHashList Source #
a set of parameterized query hashes attached to a request
this type exists because a simple list of ParameterisedQueryHash
es won't
let us log a single-request batch and a single non-batched request
differently. the log format uses json lists for requests executed in batched
mode, for fields like query
, but not for requests in single mode (e.g.
query: "..."
vs query: ["..."]
) and so to conform to that, we capture the
whole _set_ of parameterised query hashes when it's created, tagging it with
information about how it was created (i.e. from a batched request, a single
request, etc.)
PQHSetEmpty | an empty query hash set, either for an operation that does not produce query hashes, or due to failure in operation execution |
PQHSetSingleton !ParameterizedQueryHash | a query hash set consisting of a single element, corresponding to e.g. a single (non-batched) graphql request |
PQHSetBatched ![ParameterizedQueryHash] | a query hash set associated to a batched request note that this does not need to contain multiple query hashes: it is possible for a batch to contain only one request |
Instances
parameterizedQueryHashListToObject :: ParameterizedQueryHashList -> Object Source #
we use something that explicitly produces an Object
instead of writing
a ToJSON
instance. in the latter case, functions consuming the output of
toJSON
would have to perform a partial pattern-match on the Value
output to extract a JSON object from it. for the other patterns, it would
have to either throw a runtime error on or silently ignore the other
patterns, and the latter choice would cause a silent failure if the
ToJSON
instance were modified to no longer always return objects
newtype ParameterizedQueryHash Source #
Instances
Eq ParameterizedQueryHash Source # | |
Defined in Hasura.GraphQL.ParameterizedQueryHash | |
Show ParameterizedQueryHash Source # | |
Defined in Hasura.GraphQL.ParameterizedQueryHash showsPrec :: Int -> ParameterizedQueryHash -> ShowS # show :: ParameterizedQueryHash -> String # showList :: [ParameterizedQueryHash] -> ShowS # | |
ToJSON ParameterizedQueryHash Source # | |
Defined in Hasura.GraphQL.ParameterizedQueryHash toJSON :: ParameterizedQueryHash -> Value toEncoding :: ParameterizedQueryHash -> Encoding toJSONList :: [ParameterizedQueryHash] -> Value toEncodingList :: [ParameterizedQueryHash] -> Encoding |
normalizeSelectionSet :: SelectionSet NoFragments Variable -> SelectionSet NoFragments Void Source #
calculateParameterizedQueryHash :: SelectionSet NoFragments Variable -> ParameterizedQueryHash Source #