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

Hasura.Backends.MySQL.DataLoader.Plan

Description

Make a plan for the data loader to execute (.Execute).

It will produce a graph of actions, to be executed by .Execute.

Synopsis

Documentation

data Ref Source #

A reference to a result of loading a recordset from the database.

Constructors

Ref 

Fields

  • idx :: Int

    This index will be generated by the planner.

  • text :: Text

    A display name. The idx gives us uniqueness.

Instances

Instances details
Eq Ref Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Methods

(==) :: Ref -> Ref -> Bool #

(/=) :: Ref -> Ref -> Bool #

Ord Ref Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Methods

compare :: Ref -> Ref -> Ordering #

(<) :: Ref -> Ref -> Bool #

(<=) :: Ref -> Ref -> Bool #

(>) :: Ref -> Ref -> Bool #

(>=) :: Ref -> Ref -> Bool #

max :: Ref -> Ref -> Ref #

min :: Ref -> Ref -> Ref #

Show Ref Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Methods

showsPrec :: Int -> Ref -> ShowS #

show :: Ref -> String #

showList :: [Ref] -> ShowS #

Generic Ref Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Associated Types

type Rep Ref :: Type -> Type #

Methods

from :: Ref -> Rep Ref x #

to :: Rep Ref x -> Ref #

Hashable Ref Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Methods

hashWithSalt :: Int -> Ref -> Int

hash :: Ref -> Int

type Rep Ref Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

type Rep Ref = D1 ('MetaData "Ref" "Hasura.Backends.MySQL.DataLoader.Plan" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "Ref" 'PrefixI 'True) (S1 ('MetaSel ('Just "idx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "text") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text)))

data Select Source #

A almost-the-same version of Select from Types.Internal, except with some fields used for planning and executing.

Instances

Instances details
Show Select Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

data Join Source #

An join action.

Constructors

Join 

Fields

  • leftRecordSet :: Ref

    Join this side...

  • rightRecordSet :: Ref

    with this side.

  • joinRhsTop :: Top

    Join only the top N results. It's important that we do this IN HASKELL, therefore this is not part of the generated SQL.

  • joinRhsOffset :: Maybe Int

    Offset applied to the right-hand-side table.

  • joinType :: JoinType

    Type of relational join to do.

  • joinFieldName :: Text

    Field name to return the join result as; e.g. "albums" for an artist with an array relation of albums.

  • wantedFields :: Maybe [Text]

    The SQL queries may achieve the data using joining fields, but those fields aren't supposed to be returned back to the user. To avoid that, we explicitly specify which fields are wanted from this join. E.g. "title" and "year", but not artist_id which was used to Haskell-join the row with an album_artist_id, or whatever.

Instances

Instances details
Show Join Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Methods

showsPrec :: Int -> Join -> ShowS #

show :: Join -> String #

showList :: [Join] -> ShowS #

data Action Source #

An action that the executor will perform. Either pull data from the database directly via a select, or join two other actions' record sets together.

Instances

Instances details
Show Action Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

data PlannedAction Source #

An action planned, with a unique reference. I.e. the action performed yields a result stored at reference ref.

Constructors

PlannedAction 

Fields

Instances

Instances details
Show PlannedAction Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

data Relationship Source #

A relationship lets the executor insert on-the-fly WHERE fkey1=fkey2 for relationships. These can only be inserted on-the-fly and aren't known at the time of planning, because the keys come from the left-hand-side table for a join.

Instances

Instances details
Show Relationship Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

newtype FieldName Source #

Just a wrapper to clarify some types. It's different from the MySQL.FieldName because it doesn't care about schemas: schemas aren't returned in recordsets from the database.

Constructors

FieldName Text 

Instances

Instances details
Eq FieldName Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Ord FieldName Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Show FieldName Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

IsString FieldName Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Hashable FieldName Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

FromJSON FieldName Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Methods

parseJSON :: Value -> Parser FieldName

parseJSONList :: Value -> Parser [FieldName]

ToJSONKey FieldName Source # 
Instance details

Defined in Hasura.Backends.MySQL.DataLoader.Plan

Methods

toJSONKey :: ToJSONKeyFunction FieldName

toJSONKeyList :: ToJSONKeyFunction [FieldName]

data HeadAndTail Source #

The reason for this is subtle. Read this documentation. For each join on a select (see above, there is a list), we split that out into three jobs:

  1. One job for the left hand side (i.e. the select).
  2. One job for the right hand side (i.e. the join).
  3. One job to join them (And in the darkness bind them...)

This is performed as a fold, like: foldM planJoin head joins. A nice linked-list or tree-like structure arises. The planner code produces a graph out of this; so it's possible that some parallelism can be achieved by running multiple jobs at once.

The "head" is the first, original select. The "tail" is the (indirectly) linked list of joins. That list may also be empty. In that case, the tail is simply the same as the head.

If the tail is different to the head, then we choose the tail, as it represents the joined up version of both. If they're the same, we take whichever.

Constructors

HeadAndTail 

Fields

data PlanState Source #

We're simply accumulating a set of actions with this. The counter lets us generate unique refs.

Constructors

PlanState 

newtype Plan a Source #

Simple monad to collect actions.

Constructors

Plan 

Fields

toFieldName :: FieldName -> FieldName Source #

Note that we're intentionally discarding the table qualification.

selectFromName :: From -> Text Source #

Used for display purposes, not semantic content.

planJoin :: Ref -> Join -> Plan Ref Source #

Given a left-hand-side table and a join spec, produce a single reference that refers to the composition of the two.

tell :: PlannedAction -> Plan () Source #

Write the planned action to the state, like a writer's tell.

generate :: Text -> Plan Ref Source #

Generate a unique reference with a label for debugging.

actionsForest :: (Graph -> Graph) -> [PlannedAction] -> Forest PlannedAction Source #

Graph the set of planned actions ready for execution in the correct order.

selectQuery :: Select -> Select Source #

Used by the executor to produce a plain old select that can be sent to the MySQL server.

fromSelect :: Maybe Relationship -> Maybe Text -> Select -> Select Source #

From a plain select, and possibly a parent/left-hand-side relationship, produce a select that is useful for execution.