graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellNone
LanguageHaskell2010

Hasura.GraphQL.Execute.RemoteJoin.Collect

Synopsis

Documentation

getRemoteJoinsQueryDB :: Backend b => QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b) -> (QueryDB b Void (UnpreparedValue b), Maybe RemoteJoins) Source #

Collects remote joins from the a QueryDB if any, and transforms the selection to add new join fields where those occured.

Returns the transformed selection set, in which remote fields have been inserted, and for which the r type is now Void.

getRemoteJoinsMutationDB :: Backend b => MutationDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b) -> (MutationDB b Void (UnpreparedValue b), Maybe RemoteJoins) Source #

Collects remote joins from the a MutationDB if any, and transforms the selection to add new join fields where those occured.

Returns the transformed selection set, in which remote fields have been inserted, and for which the r type is now Void.

newtype Collector a Source #

A writer monad used to collect together all remote joins appearing in some data structure.

In the functions below, the withField function is used to track the context of the path from the root of the current selection set.

It is important that we work bottom-up, and do not collect duplicate field names at any level, because the Semigroup instance for RemoteJoins does not allow for these duplicates.

Constructors

Collector 

collect :: NEHashMap QualifiedFieldName RemoteJoin -> Collector () Source #

Collect some remote joins appearing at the given field names in the current context.

withField :: Maybe Text -> Text -> Collector a -> Collector a Source #

Keep track of the given field name in the current path from the root of the selection set.

traverseFields :: (a -> Collector b) -> Fields a -> Collector (Fields b) Source #

Traverse a list of fields, while applying withField to keep track of the path within the AST. This function assumes that no type name is required for the QualifiedFieldName and uses Nothing.

transformAnnFields :: forall src. Backend src => AnnFieldsG src (RemoteRelationshipField UnpreparedValue) (UnpreparedValue src) -> Collector (AnnFieldsG src Void (UnpreparedValue src)) Source #

Transforms a source selection set.

This function takes an AnnFieldsG, which corresponds to a selection of fields on a source, and extracts remote joins: for every field we encounter that maps to a remote destination (either another source or a remote schema), we replace it with a phantom field and collect the corresponding RemoteJoin.

transformActionFields :: ActionFieldsG (RemoteRelationshipField UnpreparedValue) -> Collector ActionFields Source #

Transforms an action's selection set.

This function takes an ActionFieldsG, which corresponds to a selection of fields on the result of an action, and extracts remote joins: for every field we encounter that maps to a remote destination (either a source or a remote schema), we replace it with a phantom field and collect the corresponding RemoteJoin.

transformObjectSelectionSet Source #

Arguments

:: Maybe Name

The type name on which this selection set is defined; this is only expected to be provided for unions and interfaces, not for regular objects, as this is used to determine whether a selection set is potentially "ambiguous" or not, and regular objects cannot. This will be used as the type name in the QualifiedFieldName key of the join tree if this selection set or its subselections contain remote joins.

-> ObjectSelectionSet (RemoteRelationshipField UnpreparedValue) var 
-> Collector (ObjectSelectionSet Void var) 

Transforms a GraphQL selection set.

This function takes an SelectionSet, which corresponds to a selection of fields on a remote GraphQL schema, and extracts remote joins: for every field we encounter that maps to a remote destination (either a source or another remote schema), we replace it with a phantom field and collect the corresponding RemoteJoin.

createRemoteJoin :: HashMap FieldName JoinColumnAlias -> RemoteRelationshipField UnpreparedValue -> RemoteJoin Source #

Converts a remote relationship field into a RemoteJoin that the execution engine understands.

getJoinColumnAlias :: (Eq field, Hashable field) => FieldName -> field -> HashMap field FieldName -> [FieldName] -> JoinColumnAlias Source #

Constructs a JoinColumnAlias for a given field in a selection set.

If the field was already requested, we leave it unchanged, to avoid double-fetching the same information. However, if this field is a "phantom" field, that we only add for the purpose of fetching a join key, we rename it in a way that is guaranteed to avoid conflicts.

NOTE: if the fieldName argument is a valid GraphQL name, then the constructed alias MUST also be a valid GraphQL name.

getFields :: Traversal' super sub -> [(any, super)] -> [(any, sub)] Source #

Get the fields targeted by some Traversal for an arbitrary list of tuples, discarding any elements whose fields cannot be focused upon.