{-# LANGUAGE TemplateHaskell #-}

-- | Representation for queries going to remote schemas. Due to the existence of
-- remote relationships from remote schemas, we can't simply reuse the GraphQL
-- document AST we define in graphql-parser-hs, and instead redefine a custom
-- structure to represent such queries.
module Hasura.RQL.IR.RemoteSchema
  ( -- AST
    SelectionSet (..),
    DeduplicatedSelectionSet (..),
    dssCommonFields,
    dssMemberSelectionSets,
    ObjectSelectionSet,
    mkInterfaceSelectionSet,
    mkUnionSelectionSet,
    Field (..),
    _FieldGraphQL,
    _FieldRemote,
    GraphQLField (..),
    fAlias,
    fName,
    fArguments,
    fDirectives,
    fSelectionSet,
    mkGraphQLField,
    -- entry points
    RemoteSchemaRootField (..),
    SchemaRemoteRelationshipSelect (..),
    RemoteFieldArgument (..),
    RemoteSchemaSelect (..),
    -- AST conversion
    convertSelectionSet,
    convertGraphQLField,
  )
where

import Control.Lens.TH (makeLenses, makePrisms)
import Data.HashMap.Strict qualified as Map
import Data.HashMap.Strict.InsOrd.Extended qualified as OMap
import Data.HashSet qualified as Set
import Data.List.Extended (longestCommonPrefix)
import Hasura.GraphQL.Parser.Name as GName
import Hasura.GraphQL.Parser.Variable (InputValue)
import Hasura.Prelude
import Hasura.RQL.Types.Common (FieldName)
import Hasura.RQL.Types.Relationships.ToSchema
import Hasura.RQL.Types.RemoteSchema
import Hasura.RQL.Types.RemoteSchema qualified as RQL
import Hasura.RQL.Types.ResultCustomization
import Hasura.RQL.Types.ResultCustomization qualified as RQL
import Language.GraphQL.Draft.Syntax qualified as G

-------------------------------------------------------------------------------
-- Custom AST

-- | Custom representation of a selection set.
--
-- Similarly to other parts of the IR, the @r@ argument is used for remote
-- relationships.
data SelectionSet r var
  = SelectionSetObject (ObjectSelectionSet r var)
  | SelectionSetUnion (DeduplicatedSelectionSet r var)
  | SelectionSetInterface (DeduplicatedSelectionSet r var)
  | SelectionSetNone
  deriving (Int -> SelectionSet r var -> ShowS
[SelectionSet r var] -> ShowS
SelectionSet r var -> String
(Int -> SelectionSet r var -> ShowS)
-> (SelectionSet r var -> String)
-> ([SelectionSet r var] -> ShowS)
-> Show (SelectionSet r var)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall r var.
(Show var, Show r) =>
Int -> SelectionSet r var -> ShowS
forall r var. (Show var, Show r) => [SelectionSet r var] -> ShowS
forall r var. (Show var, Show r) => SelectionSet r var -> String
showList :: [SelectionSet r var] -> ShowS
$cshowList :: forall r var. (Show var, Show r) => [SelectionSet r var] -> ShowS
show :: SelectionSet r var -> String
$cshow :: forall r var. (Show var, Show r) => SelectionSet r var -> String
showsPrec :: Int -> SelectionSet r var -> ShowS
$cshowsPrec :: forall r var.
(Show var, Show r) =>
Int -> SelectionSet r var -> ShowS
Show, SelectionSet r var -> SelectionSet r var -> Bool
(SelectionSet r var -> SelectionSet r var -> Bool)
-> (SelectionSet r var -> SelectionSet r var -> Bool)
-> Eq (SelectionSet r var)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall r var.
(Eq var, Eq r) =>
SelectionSet r var -> SelectionSet r var -> Bool
/= :: SelectionSet r var -> SelectionSet r var -> Bool
$c/= :: forall r var.
(Eq var, Eq r) =>
SelectionSet r var -> SelectionSet r var -> Bool
== :: SelectionSet r var -> SelectionSet r var -> Bool
$c== :: forall r var.
(Eq var, Eq r) =>
SelectionSet r var -> SelectionSet r var -> Bool
Eq, a -> SelectionSet r b -> SelectionSet r a
(a -> b) -> SelectionSet r a -> SelectionSet r b
(forall a b. (a -> b) -> SelectionSet r a -> SelectionSet r b)
-> (forall a b. a -> SelectionSet r b -> SelectionSet r a)
-> Functor (SelectionSet r)
forall a b. a -> SelectionSet r b -> SelectionSet r a
forall a b. (a -> b) -> SelectionSet r a -> SelectionSet r b
forall r a b. a -> SelectionSet r b -> SelectionSet r a
forall r a b. (a -> b) -> SelectionSet r a -> SelectionSet r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> SelectionSet r b -> SelectionSet r a
$c<$ :: forall r a b. a -> SelectionSet r b -> SelectionSet r a
fmap :: (a -> b) -> SelectionSet r a -> SelectionSet r b
$cfmap :: forall r a b. (a -> b) -> SelectionSet r a -> SelectionSet r b
Functor, SelectionSet r a -> Bool
(a -> m) -> SelectionSet r a -> m
(a -> b -> b) -> b -> SelectionSet r a -> b
(forall m. Monoid m => SelectionSet r m -> m)
-> (forall m a. Monoid m => (a -> m) -> SelectionSet r a -> m)
-> (forall m a. Monoid m => (a -> m) -> SelectionSet r a -> m)
-> (forall a b. (a -> b -> b) -> b -> SelectionSet r a -> b)
-> (forall a b. (a -> b -> b) -> b -> SelectionSet r a -> b)
-> (forall b a. (b -> a -> b) -> b -> SelectionSet r a -> b)
-> (forall b a. (b -> a -> b) -> b -> SelectionSet r a -> b)
-> (forall a. (a -> a -> a) -> SelectionSet r a -> a)
-> (forall a. (a -> a -> a) -> SelectionSet r a -> a)
-> (forall a. SelectionSet r a -> [a])
-> (forall a. SelectionSet r a -> Bool)
-> (forall a. SelectionSet r a -> Int)
-> (forall a. Eq a => a -> SelectionSet r a -> Bool)
-> (forall a. Ord a => SelectionSet r a -> a)
-> (forall a. Ord a => SelectionSet r a -> a)
-> (forall a. Num a => SelectionSet r a -> a)
-> (forall a. Num a => SelectionSet r a -> a)
-> Foldable (SelectionSet r)
forall a. Eq a => a -> SelectionSet r a -> Bool
forall a. Num a => SelectionSet r a -> a
forall a. Ord a => SelectionSet r a -> a
forall m. Monoid m => SelectionSet r m -> m
forall a. SelectionSet r a -> Bool
forall a. SelectionSet r a -> Int
forall a. SelectionSet r a -> [a]
forall a. (a -> a -> a) -> SelectionSet r a -> a
forall r a. Eq a => a -> SelectionSet r a -> Bool
forall r a. Num a => SelectionSet r a -> a
forall r a. Ord a => SelectionSet r a -> a
forall m a. Monoid m => (a -> m) -> SelectionSet r a -> m
forall r m. Monoid m => SelectionSet r m -> m
forall r a. SelectionSet r a -> Bool
forall r a. SelectionSet r a -> Int
forall r a. SelectionSet r a -> [a]
forall b a. (b -> a -> b) -> b -> SelectionSet r a -> b
forall a b. (a -> b -> b) -> b -> SelectionSet r a -> b
forall r a. (a -> a -> a) -> SelectionSet r a -> a
forall r m a. Monoid m => (a -> m) -> SelectionSet r a -> m
forall r b a. (b -> a -> b) -> b -> SelectionSet r a -> b
forall r a b. (a -> b -> b) -> b -> SelectionSet r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: SelectionSet r a -> a
$cproduct :: forall r a. Num a => SelectionSet r a -> a
sum :: SelectionSet r a -> a
$csum :: forall r a. Num a => SelectionSet r a -> a
minimum :: SelectionSet r a -> a
$cminimum :: forall r a. Ord a => SelectionSet r a -> a
maximum :: SelectionSet r a -> a
$cmaximum :: forall r a. Ord a => SelectionSet r a -> a
elem :: a -> SelectionSet r a -> Bool
$celem :: forall r a. Eq a => a -> SelectionSet r a -> Bool
length :: SelectionSet r a -> Int
$clength :: forall r a. SelectionSet r a -> Int
null :: SelectionSet r a -> Bool
$cnull :: forall r a. SelectionSet r a -> Bool
toList :: SelectionSet r a -> [a]
$ctoList :: forall r a. SelectionSet r a -> [a]
foldl1 :: (a -> a -> a) -> SelectionSet r a -> a
$cfoldl1 :: forall r a. (a -> a -> a) -> SelectionSet r a -> a
foldr1 :: (a -> a -> a) -> SelectionSet r a -> a
$cfoldr1 :: forall r a. (a -> a -> a) -> SelectionSet r a -> a
foldl' :: (b -> a -> b) -> b -> SelectionSet r a -> b
$cfoldl' :: forall r b a. (b -> a -> b) -> b -> SelectionSet r a -> b
foldl :: (b -> a -> b) -> b -> SelectionSet r a -> b
$cfoldl :: forall r b a. (b -> a -> b) -> b -> SelectionSet r a -> b
foldr' :: (a -> b -> b) -> b -> SelectionSet r a -> b
$cfoldr' :: forall r a b. (a -> b -> b) -> b -> SelectionSet r a -> b
foldr :: (a -> b -> b) -> b -> SelectionSet r a -> b
$cfoldr :: forall r a b. (a -> b -> b) -> b -> SelectionSet r a -> b
foldMap' :: (a -> m) -> SelectionSet r a -> m
$cfoldMap' :: forall r m a. Monoid m => (a -> m) -> SelectionSet r a -> m
foldMap :: (a -> m) -> SelectionSet r a -> m
$cfoldMap :: forall r m a. Monoid m => (a -> m) -> SelectionSet r a -> m
fold :: SelectionSet r m -> m
$cfold :: forall r m. Monoid m => SelectionSet r m -> m
Foldable, Functor (SelectionSet r)
Foldable (SelectionSet r)
Functor (SelectionSet r)
-> Foldable (SelectionSet r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> SelectionSet r a -> f (SelectionSet r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    SelectionSet r (f a) -> f (SelectionSet r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> SelectionSet r a -> m (SelectionSet r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    SelectionSet r (m a) -> m (SelectionSet r a))
-> Traversable (SelectionSet r)
(a -> f b) -> SelectionSet r a -> f (SelectionSet r b)
forall r. Functor (SelectionSet r)
forall r. Foldable (SelectionSet r)
forall r (m :: * -> *) a.
Monad m =>
SelectionSet r (m a) -> m (SelectionSet r a)
forall r (f :: * -> *) a.
Applicative f =>
SelectionSet r (f a) -> f (SelectionSet r a)
forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SelectionSet r a -> m (SelectionSet r b)
forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SelectionSet r a -> f (SelectionSet r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
SelectionSet r (m a) -> m (SelectionSet r a)
forall (f :: * -> *) a.
Applicative f =>
SelectionSet r (f a) -> f (SelectionSet r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SelectionSet r a -> m (SelectionSet r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SelectionSet r a -> f (SelectionSet r b)
sequence :: SelectionSet r (m a) -> m (SelectionSet r a)
$csequence :: forall r (m :: * -> *) a.
Monad m =>
SelectionSet r (m a) -> m (SelectionSet r a)
mapM :: (a -> m b) -> SelectionSet r a -> m (SelectionSet r b)
$cmapM :: forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SelectionSet r a -> m (SelectionSet r b)
sequenceA :: SelectionSet r (f a) -> f (SelectionSet r a)
$csequenceA :: forall r (f :: * -> *) a.
Applicative f =>
SelectionSet r (f a) -> f (SelectionSet r a)
traverse :: (a -> f b) -> SelectionSet r a -> f (SelectionSet r b)
$ctraverse :: forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SelectionSet r a -> f (SelectionSet r b)
$cp2Traversable :: forall r. Foldable (SelectionSet r)
$cp1Traversable :: forall r. Functor (SelectionSet r)
Traversable)

-- | Representation of the normalized selection set of an interface/union type.
--
-- This representation is used to attempt to minimize the size of the GraphQL
-- query that eventually gets sent to the GraphQL server by defining as many
-- fields as possible on the abstract type.
data DeduplicatedSelectionSet r var = DeduplicatedSelectionSet
  { -- | Fields that aren't explicitly defined for member types
    DeduplicatedSelectionSet r var -> HashSet Name
_dssCommonFields :: Set.HashSet G.Name,
    -- | SelectionSets of individual member types
    DeduplicatedSelectionSet r var
-> HashMap Name (ObjectSelectionSet r var)
_dssMemberSelectionSets :: Map.HashMap G.Name (ObjectSelectionSet r var)
  }
  deriving (Int -> DeduplicatedSelectionSet r var -> ShowS
[DeduplicatedSelectionSet r var] -> ShowS
DeduplicatedSelectionSet r var -> String
(Int -> DeduplicatedSelectionSet r var -> ShowS)
-> (DeduplicatedSelectionSet r var -> String)
-> ([DeduplicatedSelectionSet r var] -> ShowS)
-> Show (DeduplicatedSelectionSet r var)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall r var.
(Show var, Show r) =>
Int -> DeduplicatedSelectionSet r var -> ShowS
forall r var.
(Show var, Show r) =>
[DeduplicatedSelectionSet r var] -> ShowS
forall r var.
(Show var, Show r) =>
DeduplicatedSelectionSet r var -> String
showList :: [DeduplicatedSelectionSet r var] -> ShowS
$cshowList :: forall r var.
(Show var, Show r) =>
[DeduplicatedSelectionSet r var] -> ShowS
show :: DeduplicatedSelectionSet r var -> String
$cshow :: forall r var.
(Show var, Show r) =>
DeduplicatedSelectionSet r var -> String
showsPrec :: Int -> DeduplicatedSelectionSet r var -> ShowS
$cshowsPrec :: forall r var.
(Show var, Show r) =>
Int -> DeduplicatedSelectionSet r var -> ShowS
Show, DeduplicatedSelectionSet r var
-> DeduplicatedSelectionSet r var -> Bool
(DeduplicatedSelectionSet r var
 -> DeduplicatedSelectionSet r var -> Bool)
-> (DeduplicatedSelectionSet r var
    -> DeduplicatedSelectionSet r var -> Bool)
-> Eq (DeduplicatedSelectionSet r var)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall r var.
(Eq var, Eq r) =>
DeduplicatedSelectionSet r var
-> DeduplicatedSelectionSet r var -> Bool
/= :: DeduplicatedSelectionSet r var
-> DeduplicatedSelectionSet r var -> Bool
$c/= :: forall r var.
(Eq var, Eq r) =>
DeduplicatedSelectionSet r var
-> DeduplicatedSelectionSet r var -> Bool
== :: DeduplicatedSelectionSet r var
-> DeduplicatedSelectionSet r var -> Bool
$c== :: forall r var.
(Eq var, Eq r) =>
DeduplicatedSelectionSet r var
-> DeduplicatedSelectionSet r var -> Bool
Eq, a -> DeduplicatedSelectionSet r b -> DeduplicatedSelectionSet r a
(a -> b)
-> DeduplicatedSelectionSet r a -> DeduplicatedSelectionSet r b
(forall a b.
 (a -> b)
 -> DeduplicatedSelectionSet r a -> DeduplicatedSelectionSet r b)
-> (forall a b.
    a -> DeduplicatedSelectionSet r b -> DeduplicatedSelectionSet r a)
-> Functor (DeduplicatedSelectionSet r)
forall a b.
a -> DeduplicatedSelectionSet r b -> DeduplicatedSelectionSet r a
forall a b.
(a -> b)
-> DeduplicatedSelectionSet r a -> DeduplicatedSelectionSet r b
forall r a b.
a -> DeduplicatedSelectionSet r b -> DeduplicatedSelectionSet r a
forall r a b.
(a -> b)
-> DeduplicatedSelectionSet r a -> DeduplicatedSelectionSet r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> DeduplicatedSelectionSet r b -> DeduplicatedSelectionSet r a
$c<$ :: forall r a b.
a -> DeduplicatedSelectionSet r b -> DeduplicatedSelectionSet r a
fmap :: (a -> b)
-> DeduplicatedSelectionSet r a -> DeduplicatedSelectionSet r b
$cfmap :: forall r a b.
(a -> b)
-> DeduplicatedSelectionSet r a -> DeduplicatedSelectionSet r b
Functor, DeduplicatedSelectionSet r a -> Bool
(a -> m) -> DeduplicatedSelectionSet r a -> m
(a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b
(forall m. Monoid m => DeduplicatedSelectionSet r m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> DeduplicatedSelectionSet r a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> DeduplicatedSelectionSet r a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b)
-> (forall a. (a -> a -> a) -> DeduplicatedSelectionSet r a -> a)
-> (forall a. (a -> a -> a) -> DeduplicatedSelectionSet r a -> a)
-> (forall a. DeduplicatedSelectionSet r a -> [a])
-> (forall a. DeduplicatedSelectionSet r a -> Bool)
-> (forall a. DeduplicatedSelectionSet r a -> Int)
-> (forall a. Eq a => a -> DeduplicatedSelectionSet r a -> Bool)
-> (forall a. Ord a => DeduplicatedSelectionSet r a -> a)
-> (forall a. Ord a => DeduplicatedSelectionSet r a -> a)
-> (forall a. Num a => DeduplicatedSelectionSet r a -> a)
-> (forall a. Num a => DeduplicatedSelectionSet r a -> a)
-> Foldable (DeduplicatedSelectionSet r)
forall a. Eq a => a -> DeduplicatedSelectionSet r a -> Bool
forall a. Num a => DeduplicatedSelectionSet r a -> a
forall a. Ord a => DeduplicatedSelectionSet r a -> a
forall m. Monoid m => DeduplicatedSelectionSet r m -> m
forall a. DeduplicatedSelectionSet r a -> Bool
forall a. DeduplicatedSelectionSet r a -> Int
forall a. DeduplicatedSelectionSet r a -> [a]
forall a. (a -> a -> a) -> DeduplicatedSelectionSet r a -> a
forall r a. Eq a => a -> DeduplicatedSelectionSet r a -> Bool
forall r a. Num a => DeduplicatedSelectionSet r a -> a
forall r a. Ord a => DeduplicatedSelectionSet r a -> a
forall m a.
Monoid m =>
(a -> m) -> DeduplicatedSelectionSet r a -> m
forall r m. Monoid m => DeduplicatedSelectionSet r m -> m
forall r a. DeduplicatedSelectionSet r a -> Bool
forall r a. DeduplicatedSelectionSet r a -> Int
forall r a. DeduplicatedSelectionSet r a -> [a]
forall b a. (b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b
forall a b. (a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b
forall r a. (a -> a -> a) -> DeduplicatedSelectionSet r a -> a
forall r m a.
Monoid m =>
(a -> m) -> DeduplicatedSelectionSet r a -> m
forall r b a.
(b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b
forall r a b.
(a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: DeduplicatedSelectionSet r a -> a
$cproduct :: forall r a. Num a => DeduplicatedSelectionSet r a -> a
sum :: DeduplicatedSelectionSet r a -> a
$csum :: forall r a. Num a => DeduplicatedSelectionSet r a -> a
minimum :: DeduplicatedSelectionSet r a -> a
$cminimum :: forall r a. Ord a => DeduplicatedSelectionSet r a -> a
maximum :: DeduplicatedSelectionSet r a -> a
$cmaximum :: forall r a. Ord a => DeduplicatedSelectionSet r a -> a
elem :: a -> DeduplicatedSelectionSet r a -> Bool
$celem :: forall r a. Eq a => a -> DeduplicatedSelectionSet r a -> Bool
length :: DeduplicatedSelectionSet r a -> Int
$clength :: forall r a. DeduplicatedSelectionSet r a -> Int
null :: DeduplicatedSelectionSet r a -> Bool
$cnull :: forall r a. DeduplicatedSelectionSet r a -> Bool
toList :: DeduplicatedSelectionSet r a -> [a]
$ctoList :: forall r a. DeduplicatedSelectionSet r a -> [a]
foldl1 :: (a -> a -> a) -> DeduplicatedSelectionSet r a -> a
$cfoldl1 :: forall r a. (a -> a -> a) -> DeduplicatedSelectionSet r a -> a
foldr1 :: (a -> a -> a) -> DeduplicatedSelectionSet r a -> a
$cfoldr1 :: forall r a. (a -> a -> a) -> DeduplicatedSelectionSet r a -> a
foldl' :: (b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b
$cfoldl' :: forall r b a.
(b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b
foldl :: (b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b
$cfoldl :: forall r b a.
(b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b
foldr' :: (a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b
$cfoldr' :: forall r a b.
(a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b
foldr :: (a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b
$cfoldr :: forall r a b.
(a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b
foldMap' :: (a -> m) -> DeduplicatedSelectionSet r a -> m
$cfoldMap' :: forall r m a.
Monoid m =>
(a -> m) -> DeduplicatedSelectionSet r a -> m
foldMap :: (a -> m) -> DeduplicatedSelectionSet r a -> m
$cfoldMap :: forall r m a.
Monoid m =>
(a -> m) -> DeduplicatedSelectionSet r a -> m
fold :: DeduplicatedSelectionSet r m -> m
$cfold :: forall r m. Monoid m => DeduplicatedSelectionSet r m -> m
Foldable, Functor (DeduplicatedSelectionSet r)
Foldable (DeduplicatedSelectionSet r)
Functor (DeduplicatedSelectionSet r)
-> Foldable (DeduplicatedSelectionSet r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> DeduplicatedSelectionSet r a
    -> f (DeduplicatedSelectionSet r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    DeduplicatedSelectionSet r (f a)
    -> f (DeduplicatedSelectionSet r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> DeduplicatedSelectionSet r a
    -> m (DeduplicatedSelectionSet r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    DeduplicatedSelectionSet r (m a)
    -> m (DeduplicatedSelectionSet r a))
-> Traversable (DeduplicatedSelectionSet r)
(a -> f b)
-> DeduplicatedSelectionSet r a -> f (DeduplicatedSelectionSet r b)
forall r. Functor (DeduplicatedSelectionSet r)
forall r. Foldable (DeduplicatedSelectionSet r)
forall r (m :: * -> *) a.
Monad m =>
DeduplicatedSelectionSet r (m a)
-> m (DeduplicatedSelectionSet r a)
forall r (f :: * -> *) a.
Applicative f =>
DeduplicatedSelectionSet r (f a)
-> f (DeduplicatedSelectionSet r a)
forall r (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> DeduplicatedSelectionSet r a -> m (DeduplicatedSelectionSet r b)
forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> DeduplicatedSelectionSet r a -> f (DeduplicatedSelectionSet r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
DeduplicatedSelectionSet r (m a)
-> m (DeduplicatedSelectionSet r a)
forall (f :: * -> *) a.
Applicative f =>
DeduplicatedSelectionSet r (f a)
-> f (DeduplicatedSelectionSet r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> DeduplicatedSelectionSet r a -> m (DeduplicatedSelectionSet r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> DeduplicatedSelectionSet r a -> f (DeduplicatedSelectionSet r b)
sequence :: DeduplicatedSelectionSet r (m a)
-> m (DeduplicatedSelectionSet r a)
$csequence :: forall r (m :: * -> *) a.
Monad m =>
DeduplicatedSelectionSet r (m a)
-> m (DeduplicatedSelectionSet r a)
mapM :: (a -> m b)
-> DeduplicatedSelectionSet r a -> m (DeduplicatedSelectionSet r b)
$cmapM :: forall r (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> DeduplicatedSelectionSet r a -> m (DeduplicatedSelectionSet r b)
sequenceA :: DeduplicatedSelectionSet r (f a)
-> f (DeduplicatedSelectionSet r a)
$csequenceA :: forall r (f :: * -> *) a.
Applicative f =>
DeduplicatedSelectionSet r (f a)
-> f (DeduplicatedSelectionSet r a)
traverse :: (a -> f b)
-> DeduplicatedSelectionSet r a -> f (DeduplicatedSelectionSet r b)
$ctraverse :: forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> DeduplicatedSelectionSet r a -> f (DeduplicatedSelectionSet r b)
$cp2Traversable :: forall r. Foldable (DeduplicatedSelectionSet r)
$cp1Traversable :: forall r. Functor (DeduplicatedSelectionSet r)
Traversable, (forall x.
 DeduplicatedSelectionSet r var
 -> Rep (DeduplicatedSelectionSet r var) x)
-> (forall x.
    Rep (DeduplicatedSelectionSet r var) x
    -> DeduplicatedSelectionSet r var)
-> Generic (DeduplicatedSelectionSet r var)
forall x.
Rep (DeduplicatedSelectionSet r var) x
-> DeduplicatedSelectionSet r var
forall x.
DeduplicatedSelectionSet r var
-> Rep (DeduplicatedSelectionSet r var) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall r var x.
Rep (DeduplicatedSelectionSet r var) x
-> DeduplicatedSelectionSet r var
forall r var x.
DeduplicatedSelectionSet r var
-> Rep (DeduplicatedSelectionSet r var) x
$cto :: forall r var x.
Rep (DeduplicatedSelectionSet r var) x
-> DeduplicatedSelectionSet r var
$cfrom :: forall r var x.
DeduplicatedSelectionSet r var
-> Rep (DeduplicatedSelectionSet r var) x
Generic)

type ObjectSelectionSet r var = OMap.InsOrdHashMap G.Name (Field r var)

-- | Constructs an 'InterfaceSelectionSet' from a set of interface fields and an
-- association list of the fields. This function ensures that @__typename@ is
-- present in the set of interface fields.
mkInterfaceSelectionSet ::
  -- | Member fields of the interface
  Set.HashSet G.Name ->
  -- | Selection sets for all the member types
  [(G.Name, ObjectSelectionSet r var)] ->
  DeduplicatedSelectionSet r var
mkInterfaceSelectionSet :: HashSet Name
-> [(Name, ObjectSelectionSet r var)]
-> DeduplicatedSelectionSet r var
mkInterfaceSelectionSet HashSet Name
interfaceFields [(Name, ObjectSelectionSet r var)]
selectionSets =
  HashSet Name
-> HashMap Name (ObjectSelectionSet r var)
-> DeduplicatedSelectionSet r var
forall r var.
HashSet Name
-> HashMap Name (ObjectSelectionSet r var)
-> DeduplicatedSelectionSet r var
DeduplicatedSelectionSet
    (Name -> HashSet Name -> HashSet Name
forall a. (Eq a, Hashable a) => a -> HashSet a -> HashSet a
Set.insert Name
GName.___typename HashSet Name
interfaceFields)
    ([(Name, ObjectSelectionSet r var)]
-> HashMap Name (ObjectSelectionSet r var)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
Map.fromList [(Name, ObjectSelectionSet r var)]
selectionSets)

-- | Constructs an 'UnionSelectionSet' from a list of the fields, using a
-- singleton set of @__typename@ for the set of common fields.
mkUnionSelectionSet ::
  -- | Selection sets for all the member types
  [(G.Name, ObjectSelectionSet r var)] ->
  DeduplicatedSelectionSet r var
mkUnionSelectionSet :: [(Name, ObjectSelectionSet r var)]
-> DeduplicatedSelectionSet r var
mkUnionSelectionSet [(Name, ObjectSelectionSet r var)]
selectionSets =
  HashSet Name
-> HashMap Name (ObjectSelectionSet r var)
-> DeduplicatedSelectionSet r var
forall r var.
HashSet Name
-> HashMap Name (ObjectSelectionSet r var)
-> DeduplicatedSelectionSet r var
DeduplicatedSelectionSet
    (Name -> HashSet Name
forall a. Hashable a => a -> HashSet a
Set.singleton Name
GName.___typename)
    ([(Name, ObjectSelectionSet r var)]
-> HashMap Name (ObjectSelectionSet r var)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
Map.fromList [(Name, ObjectSelectionSet r var)]
selectionSets)

-- | Representation of one individual field.
--
-- This particular type is the reason why we need a different representation
-- from the one in 'graphql-parser-hs': we differentiate between selection
-- fields that target the actual remote schema, and fields that, instead, are
-- remote from it and need to be treated differently.
data Field r var
  = FieldGraphQL (GraphQLField r var)
  | FieldRemote (SchemaRemoteRelationshipSelect r)
  deriving (Int -> Field r var -> ShowS
[Field r var] -> ShowS
Field r var -> String
(Int -> Field r var -> ShowS)
-> (Field r var -> String)
-> ([Field r var] -> ShowS)
-> Show (Field r var)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall r var. (Show var, Show r) => Int -> Field r var -> ShowS
forall r var. (Show var, Show r) => [Field r var] -> ShowS
forall r var. (Show var, Show r) => Field r var -> String
showList :: [Field r var] -> ShowS
$cshowList :: forall r var. (Show var, Show r) => [Field r var] -> ShowS
show :: Field r var -> String
$cshow :: forall r var. (Show var, Show r) => Field r var -> String
showsPrec :: Int -> Field r var -> ShowS
$cshowsPrec :: forall r var. (Show var, Show r) => Int -> Field r var -> ShowS
Show, Field r var -> Field r var -> Bool
(Field r var -> Field r var -> Bool)
-> (Field r var -> Field r var -> Bool) -> Eq (Field r var)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall r var. (Eq var, Eq r) => Field r var -> Field r var -> Bool
/= :: Field r var -> Field r var -> Bool
$c/= :: forall r var. (Eq var, Eq r) => Field r var -> Field r var -> Bool
== :: Field r var -> Field r var -> Bool
$c== :: forall r var. (Eq var, Eq r) => Field r var -> Field r var -> Bool
Eq, a -> Field r b -> Field r a
(a -> b) -> Field r a -> Field r b
(forall a b. (a -> b) -> Field r a -> Field r b)
-> (forall a b. a -> Field r b -> Field r a) -> Functor (Field r)
forall a b. a -> Field r b -> Field r a
forall a b. (a -> b) -> Field r a -> Field r b
forall r a b. a -> Field r b -> Field r a
forall r a b. (a -> b) -> Field r a -> Field r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Field r b -> Field r a
$c<$ :: forall r a b. a -> Field r b -> Field r a
fmap :: (a -> b) -> Field r a -> Field r b
$cfmap :: forall r a b. (a -> b) -> Field r a -> Field r b
Functor, Field r a -> Bool
(a -> m) -> Field r a -> m
(a -> b -> b) -> b -> Field r a -> b
(forall m. Monoid m => Field r m -> m)
-> (forall m a. Monoid m => (a -> m) -> Field r a -> m)
-> (forall m a. Monoid m => (a -> m) -> Field r a -> m)
-> (forall a b. (a -> b -> b) -> b -> Field r a -> b)
-> (forall a b. (a -> b -> b) -> b -> Field r a -> b)
-> (forall b a. (b -> a -> b) -> b -> Field r a -> b)
-> (forall b a. (b -> a -> b) -> b -> Field r a -> b)
-> (forall a. (a -> a -> a) -> Field r a -> a)
-> (forall a. (a -> a -> a) -> Field r a -> a)
-> (forall a. Field r a -> [a])
-> (forall a. Field r a -> Bool)
-> (forall a. Field r a -> Int)
-> (forall a. Eq a => a -> Field r a -> Bool)
-> (forall a. Ord a => Field r a -> a)
-> (forall a. Ord a => Field r a -> a)
-> (forall a. Num a => Field r a -> a)
-> (forall a. Num a => Field r a -> a)
-> Foldable (Field r)
forall a. Eq a => a -> Field r a -> Bool
forall a. Num a => Field r a -> a
forall a. Ord a => Field r a -> a
forall m. Monoid m => Field r m -> m
forall a. Field r a -> Bool
forall a. Field r a -> Int
forall a. Field r a -> [a]
forall a. (a -> a -> a) -> Field r a -> a
forall r a. Eq a => a -> Field r a -> Bool
forall r a. Num a => Field r a -> a
forall r a. Ord a => Field r a -> a
forall m a. Monoid m => (a -> m) -> Field r a -> m
forall r m. Monoid m => Field r m -> m
forall r a. Field r a -> Bool
forall r a. Field r a -> Int
forall r a. Field r a -> [a]
forall b a. (b -> a -> b) -> b -> Field r a -> b
forall a b. (a -> b -> b) -> b -> Field r a -> b
forall r a. (a -> a -> a) -> Field r a -> a
forall r m a. Monoid m => (a -> m) -> Field r a -> m
forall r b a. (b -> a -> b) -> b -> Field r a -> b
forall r a b. (a -> b -> b) -> b -> Field r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Field r a -> a
$cproduct :: forall r a. Num a => Field r a -> a
sum :: Field r a -> a
$csum :: forall r a. Num a => Field r a -> a
minimum :: Field r a -> a
$cminimum :: forall r a. Ord a => Field r a -> a
maximum :: Field r a -> a
$cmaximum :: forall r a. Ord a => Field r a -> a
elem :: a -> Field r a -> Bool
$celem :: forall r a. Eq a => a -> Field r a -> Bool
length :: Field r a -> Int
$clength :: forall r a. Field r a -> Int
null :: Field r a -> Bool
$cnull :: forall r a. Field r a -> Bool
toList :: Field r a -> [a]
$ctoList :: forall r a. Field r a -> [a]
foldl1 :: (a -> a -> a) -> Field r a -> a
$cfoldl1 :: forall r a. (a -> a -> a) -> Field r a -> a
foldr1 :: (a -> a -> a) -> Field r a -> a
$cfoldr1 :: forall r a. (a -> a -> a) -> Field r a -> a
foldl' :: (b -> a -> b) -> b -> Field r a -> b
$cfoldl' :: forall r b a. (b -> a -> b) -> b -> Field r a -> b
foldl :: (b -> a -> b) -> b -> Field r a -> b
$cfoldl :: forall r b a. (b -> a -> b) -> b -> Field r a -> b
foldr' :: (a -> b -> b) -> b -> Field r a -> b
$cfoldr' :: forall r a b. (a -> b -> b) -> b -> Field r a -> b
foldr :: (a -> b -> b) -> b -> Field r a -> b
$cfoldr :: forall r a b. (a -> b -> b) -> b -> Field r a -> b
foldMap' :: (a -> m) -> Field r a -> m
$cfoldMap' :: forall r m a. Monoid m => (a -> m) -> Field r a -> m
foldMap :: (a -> m) -> Field r a -> m
$cfoldMap :: forall r m a. Monoid m => (a -> m) -> Field r a -> m
fold :: Field r m -> m
$cfold :: forall r m. Monoid m => Field r m -> m
Foldable, Functor (Field r)
Foldable (Field r)
Functor (Field r)
-> Foldable (Field r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Field r a -> f (Field r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Field r (f a) -> f (Field r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Field r a -> m (Field r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Field r (m a) -> m (Field r a))
-> Traversable (Field r)
(a -> f b) -> Field r a -> f (Field r b)
forall r. Functor (Field r)
forall r. Foldable (Field r)
forall r (m :: * -> *) a. Monad m => Field r (m a) -> m (Field r a)
forall r (f :: * -> *) a.
Applicative f =>
Field r (f a) -> f (Field r a)
forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Field r a -> m (Field r b)
forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Field r a -> f (Field r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Field r (m a) -> m (Field r a)
forall (f :: * -> *) a.
Applicative f =>
Field r (f a) -> f (Field r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Field r a -> m (Field r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Field r a -> f (Field r b)
sequence :: Field r (m a) -> m (Field r a)
$csequence :: forall r (m :: * -> *) a. Monad m => Field r (m a) -> m (Field r a)
mapM :: (a -> m b) -> Field r a -> m (Field r b)
$cmapM :: forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Field r a -> m (Field r b)
sequenceA :: Field r (f a) -> f (Field r a)
$csequenceA :: forall r (f :: * -> *) a.
Applicative f =>
Field r (f a) -> f (Field r a)
traverse :: (a -> f b) -> Field r a -> f (Field r b)
$ctraverse :: forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Field r a -> f (Field r b)
$cp2Traversable :: forall r. Foldable (Field r)
$cp1Traversable :: forall r. Functor (Field r)
Traversable)

-- | Normalized representation of a GraphQL field.
--
-- This type is almost identical to 'G.Field', except for the fact that the
-- selection set is our annotated 'SelectionSet', instead of the original
-- 'G.SelectionSet'. We use this type to represent the fields of a selection
-- that do target the remote schema.
data GraphQLField r var = GraphQLField
  { GraphQLField r var -> Name
_fAlias :: G.Name,
    GraphQLField r var -> Name
_fName :: G.Name,
    GraphQLField r var -> HashMap Name (Value var)
_fArguments :: HashMap G.Name (G.Value var),
    GraphQLField r var -> [Directive var]
_fDirectives :: [G.Directive var],
    GraphQLField r var -> SelectionSet r var
_fSelectionSet :: SelectionSet r var
  }
  deriving (Int -> GraphQLField r var -> ShowS
[GraphQLField r var] -> ShowS
GraphQLField r var -> String
(Int -> GraphQLField r var -> ShowS)
-> (GraphQLField r var -> String)
-> ([GraphQLField r var] -> ShowS)
-> Show (GraphQLField r var)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall r var.
(Show var, Show r) =>
Int -> GraphQLField r var -> ShowS
forall r var. (Show var, Show r) => [GraphQLField r var] -> ShowS
forall r var. (Show var, Show r) => GraphQLField r var -> String
showList :: [GraphQLField r var] -> ShowS
$cshowList :: forall r var. (Show var, Show r) => [GraphQLField r var] -> ShowS
show :: GraphQLField r var -> String
$cshow :: forall r var. (Show var, Show r) => GraphQLField r var -> String
showsPrec :: Int -> GraphQLField r var -> ShowS
$cshowsPrec :: forall r var.
(Show var, Show r) =>
Int -> GraphQLField r var -> ShowS
Show, GraphQLField r var -> GraphQLField r var -> Bool
(GraphQLField r var -> GraphQLField r var -> Bool)
-> (GraphQLField r var -> GraphQLField r var -> Bool)
-> Eq (GraphQLField r var)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall r var.
(Eq var, Eq r) =>
GraphQLField r var -> GraphQLField r var -> Bool
/= :: GraphQLField r var -> GraphQLField r var -> Bool
$c/= :: forall r var.
(Eq var, Eq r) =>
GraphQLField r var -> GraphQLField r var -> Bool
== :: GraphQLField r var -> GraphQLField r var -> Bool
$c== :: forall r var.
(Eq var, Eq r) =>
GraphQLField r var -> GraphQLField r var -> Bool
Eq, a -> GraphQLField r b -> GraphQLField r a
(a -> b) -> GraphQLField r a -> GraphQLField r b
(forall a b. (a -> b) -> GraphQLField r a -> GraphQLField r b)
-> (forall a b. a -> GraphQLField r b -> GraphQLField r a)
-> Functor (GraphQLField r)
forall a b. a -> GraphQLField r b -> GraphQLField r a
forall a b. (a -> b) -> GraphQLField r a -> GraphQLField r b
forall r a b. a -> GraphQLField r b -> GraphQLField r a
forall r a b. (a -> b) -> GraphQLField r a -> GraphQLField r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> GraphQLField r b -> GraphQLField r a
$c<$ :: forall r a b. a -> GraphQLField r b -> GraphQLField r a
fmap :: (a -> b) -> GraphQLField r a -> GraphQLField r b
$cfmap :: forall r a b. (a -> b) -> GraphQLField r a -> GraphQLField r b
Functor, GraphQLField r a -> Bool
(a -> m) -> GraphQLField r a -> m
(a -> b -> b) -> b -> GraphQLField r a -> b
(forall m. Monoid m => GraphQLField r m -> m)
-> (forall m a. Monoid m => (a -> m) -> GraphQLField r a -> m)
-> (forall m a. Monoid m => (a -> m) -> GraphQLField r a -> m)
-> (forall a b. (a -> b -> b) -> b -> GraphQLField r a -> b)
-> (forall a b. (a -> b -> b) -> b -> GraphQLField r a -> b)
-> (forall b a. (b -> a -> b) -> b -> GraphQLField r a -> b)
-> (forall b a. (b -> a -> b) -> b -> GraphQLField r a -> b)
-> (forall a. (a -> a -> a) -> GraphQLField r a -> a)
-> (forall a. (a -> a -> a) -> GraphQLField r a -> a)
-> (forall a. GraphQLField r a -> [a])
-> (forall a. GraphQLField r a -> Bool)
-> (forall a. GraphQLField r a -> Int)
-> (forall a. Eq a => a -> GraphQLField r a -> Bool)
-> (forall a. Ord a => GraphQLField r a -> a)
-> (forall a. Ord a => GraphQLField r a -> a)
-> (forall a. Num a => GraphQLField r a -> a)
-> (forall a. Num a => GraphQLField r a -> a)
-> Foldable (GraphQLField r)
forall a. Eq a => a -> GraphQLField r a -> Bool
forall a. Num a => GraphQLField r a -> a
forall a. Ord a => GraphQLField r a -> a
forall m. Monoid m => GraphQLField r m -> m
forall a. GraphQLField r a -> Bool
forall a. GraphQLField r a -> Int
forall a. GraphQLField r a -> [a]
forall a. (a -> a -> a) -> GraphQLField r a -> a
forall r a. Eq a => a -> GraphQLField r a -> Bool
forall r a. Num a => GraphQLField r a -> a
forall r a. Ord a => GraphQLField r a -> a
forall m a. Monoid m => (a -> m) -> GraphQLField r a -> m
forall r m. Monoid m => GraphQLField r m -> m
forall r a. GraphQLField r a -> Bool
forall r a. GraphQLField r a -> Int
forall r a. GraphQLField r a -> [a]
forall b a. (b -> a -> b) -> b -> GraphQLField r a -> b
forall a b. (a -> b -> b) -> b -> GraphQLField r a -> b
forall r a. (a -> a -> a) -> GraphQLField r a -> a
forall r m a. Monoid m => (a -> m) -> GraphQLField r a -> m
forall r b a. (b -> a -> b) -> b -> GraphQLField r a -> b
forall r a b. (a -> b -> b) -> b -> GraphQLField r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: GraphQLField r a -> a
$cproduct :: forall r a. Num a => GraphQLField r a -> a
sum :: GraphQLField r a -> a
$csum :: forall r a. Num a => GraphQLField r a -> a
minimum :: GraphQLField r a -> a
$cminimum :: forall r a. Ord a => GraphQLField r a -> a
maximum :: GraphQLField r a -> a
$cmaximum :: forall r a. Ord a => GraphQLField r a -> a
elem :: a -> GraphQLField r a -> Bool
$celem :: forall r a. Eq a => a -> GraphQLField r a -> Bool
length :: GraphQLField r a -> Int
$clength :: forall r a. GraphQLField r a -> Int
null :: GraphQLField r a -> Bool
$cnull :: forall r a. GraphQLField r a -> Bool
toList :: GraphQLField r a -> [a]
$ctoList :: forall r a. GraphQLField r a -> [a]
foldl1 :: (a -> a -> a) -> GraphQLField r a -> a
$cfoldl1 :: forall r a. (a -> a -> a) -> GraphQLField r a -> a
foldr1 :: (a -> a -> a) -> GraphQLField r a -> a
$cfoldr1 :: forall r a. (a -> a -> a) -> GraphQLField r a -> a
foldl' :: (b -> a -> b) -> b -> GraphQLField r a -> b
$cfoldl' :: forall r b a. (b -> a -> b) -> b -> GraphQLField r a -> b
foldl :: (b -> a -> b) -> b -> GraphQLField r a -> b
$cfoldl :: forall r b a. (b -> a -> b) -> b -> GraphQLField r a -> b
foldr' :: (a -> b -> b) -> b -> GraphQLField r a -> b
$cfoldr' :: forall r a b. (a -> b -> b) -> b -> GraphQLField r a -> b
foldr :: (a -> b -> b) -> b -> GraphQLField r a -> b
$cfoldr :: forall r a b. (a -> b -> b) -> b -> GraphQLField r a -> b
foldMap' :: (a -> m) -> GraphQLField r a -> m
$cfoldMap' :: forall r m a. Monoid m => (a -> m) -> GraphQLField r a -> m
foldMap :: (a -> m) -> GraphQLField r a -> m
$cfoldMap :: forall r m a. Monoid m => (a -> m) -> GraphQLField r a -> m
fold :: GraphQLField r m -> m
$cfold :: forall r m. Monoid m => GraphQLField r m -> m
Foldable, Functor (GraphQLField r)
Foldable (GraphQLField r)
Functor (GraphQLField r)
-> Foldable (GraphQLField r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> GraphQLField r a -> f (GraphQLField r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    GraphQLField r (f a) -> f (GraphQLField r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> GraphQLField r a -> m (GraphQLField r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    GraphQLField r (m a) -> m (GraphQLField r a))
-> Traversable (GraphQLField r)
(a -> f b) -> GraphQLField r a -> f (GraphQLField r b)
forall r. Functor (GraphQLField r)
forall r. Foldable (GraphQLField r)
forall r (m :: * -> *) a.
Monad m =>
GraphQLField r (m a) -> m (GraphQLField r a)
forall r (f :: * -> *) a.
Applicative f =>
GraphQLField r (f a) -> f (GraphQLField r a)
forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GraphQLField r a -> m (GraphQLField r b)
forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GraphQLField r a -> f (GraphQLField r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
GraphQLField r (m a) -> m (GraphQLField r a)
forall (f :: * -> *) a.
Applicative f =>
GraphQLField r (f a) -> f (GraphQLField r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GraphQLField r a -> m (GraphQLField r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GraphQLField r a -> f (GraphQLField r b)
sequence :: GraphQLField r (m a) -> m (GraphQLField r a)
$csequence :: forall r (m :: * -> *) a.
Monad m =>
GraphQLField r (m a) -> m (GraphQLField r a)
mapM :: (a -> m b) -> GraphQLField r a -> m (GraphQLField r b)
$cmapM :: forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GraphQLField r a -> m (GraphQLField r b)
sequenceA :: GraphQLField r (f a) -> f (GraphQLField r a)
$csequenceA :: forall r (f :: * -> *) a.
Applicative f =>
GraphQLField r (f a) -> f (GraphQLField r a)
traverse :: (a -> f b) -> GraphQLField r a -> f (GraphQLField r b)
$ctraverse :: forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GraphQLField r a -> f (GraphQLField r b)
$cp2Traversable :: forall r. Foldable (GraphQLField r)
$cp1Traversable :: forall r. Functor (GraphQLField r)
Traversable)

mkGraphQLField ::
  Maybe G.Name ->
  G.Name ->
  HashMap G.Name (G.Value var) ->
  [G.Directive var] ->
  SelectionSet r var ->
  GraphQLField r var
mkGraphQLField :: Maybe Name
-> Name
-> HashMap Name (Value var)
-> [Directive var]
-> SelectionSet r var
-> GraphQLField r var
mkGraphQLField Maybe Name
alias Name
name =
  Name
-> Name
-> HashMap Name (Value var)
-> [Directive var]
-> SelectionSet r var
-> GraphQLField r var
forall r var.
Name
-> Name
-> HashMap Name (Value var)
-> [Directive var]
-> SelectionSet r var
-> GraphQLField r var
GraphQLField (Name -> Maybe Name -> Name
forall a. a -> Maybe a -> a
fromMaybe Name
name Maybe Name
alias) Name
name

-------------------------------------------------------------------------------
-- Remote schema entry points

-- | Root entry point for a remote schema.
data RemoteSchemaRootField r var = RemoteSchemaRootField
  { RemoteSchemaRootField r var -> RemoteSchemaInfo
_rfRemoteSchemaInfo :: RQL.RemoteSchemaInfo,
    RemoteSchemaRootField r var -> ResultCustomizer
_rfResultCustomizer :: RQL.ResultCustomizer,
    RemoteSchemaRootField r var -> GraphQLField r var
_rfField :: GraphQLField r var
  }
  deriving (a -> RemoteSchemaRootField r b -> RemoteSchemaRootField r a
(a -> b) -> RemoteSchemaRootField r a -> RemoteSchemaRootField r b
(forall a b.
 (a -> b) -> RemoteSchemaRootField r a -> RemoteSchemaRootField r b)
-> (forall a b.
    a -> RemoteSchemaRootField r b -> RemoteSchemaRootField r a)
-> Functor (RemoteSchemaRootField r)
forall a b.
a -> RemoteSchemaRootField r b -> RemoteSchemaRootField r a
forall a b.
(a -> b) -> RemoteSchemaRootField r a -> RemoteSchemaRootField r b
forall r a b.
a -> RemoteSchemaRootField r b -> RemoteSchemaRootField r a
forall r a b.
(a -> b) -> RemoteSchemaRootField r a -> RemoteSchemaRootField r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RemoteSchemaRootField r b -> RemoteSchemaRootField r a
$c<$ :: forall r a b.
a -> RemoteSchemaRootField r b -> RemoteSchemaRootField r a
fmap :: (a -> b) -> RemoteSchemaRootField r a -> RemoteSchemaRootField r b
$cfmap :: forall r a b.
(a -> b) -> RemoteSchemaRootField r a -> RemoteSchemaRootField r b
Functor, RemoteSchemaRootField r a -> Bool
(a -> m) -> RemoteSchemaRootField r a -> m
(a -> b -> b) -> b -> RemoteSchemaRootField r a -> b
(forall m. Monoid m => RemoteSchemaRootField r m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> RemoteSchemaRootField r a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> RemoteSchemaRootField r a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b)
-> (forall a. (a -> a -> a) -> RemoteSchemaRootField r a -> a)
-> (forall a. (a -> a -> a) -> RemoteSchemaRootField r a -> a)
-> (forall a. RemoteSchemaRootField r a -> [a])
-> (forall a. RemoteSchemaRootField r a -> Bool)
-> (forall a. RemoteSchemaRootField r a -> Int)
-> (forall a. Eq a => a -> RemoteSchemaRootField r a -> Bool)
-> (forall a. Ord a => RemoteSchemaRootField r a -> a)
-> (forall a. Ord a => RemoteSchemaRootField r a -> a)
-> (forall a. Num a => RemoteSchemaRootField r a -> a)
-> (forall a. Num a => RemoteSchemaRootField r a -> a)
-> Foldable (RemoteSchemaRootField r)
forall a. Eq a => a -> RemoteSchemaRootField r a -> Bool
forall a. Num a => RemoteSchemaRootField r a -> a
forall a. Ord a => RemoteSchemaRootField r a -> a
forall m. Monoid m => RemoteSchemaRootField r m -> m
forall a. RemoteSchemaRootField r a -> Bool
forall a. RemoteSchemaRootField r a -> Int
forall a. RemoteSchemaRootField r a -> [a]
forall a. (a -> a -> a) -> RemoteSchemaRootField r a -> a
forall r a. Eq a => a -> RemoteSchemaRootField r a -> Bool
forall r a. Num a => RemoteSchemaRootField r a -> a
forall r a. Ord a => RemoteSchemaRootField r a -> a
forall m a. Monoid m => (a -> m) -> RemoteSchemaRootField r a -> m
forall r m. Monoid m => RemoteSchemaRootField r m -> m
forall r a. RemoteSchemaRootField r a -> Bool
forall r a. RemoteSchemaRootField r a -> Int
forall r a. RemoteSchemaRootField r a -> [a]
forall b a. (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b
forall a b. (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b
forall r a. (a -> a -> a) -> RemoteSchemaRootField r a -> a
forall r m a.
Monoid m =>
(a -> m) -> RemoteSchemaRootField r a -> m
forall r b a. (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b
forall r a b. (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: RemoteSchemaRootField r a -> a
$cproduct :: forall r a. Num a => RemoteSchemaRootField r a -> a
sum :: RemoteSchemaRootField r a -> a
$csum :: forall r a. Num a => RemoteSchemaRootField r a -> a
minimum :: RemoteSchemaRootField r a -> a
$cminimum :: forall r a. Ord a => RemoteSchemaRootField r a -> a
maximum :: RemoteSchemaRootField r a -> a
$cmaximum :: forall r a. Ord a => RemoteSchemaRootField r a -> a
elem :: a -> RemoteSchemaRootField r a -> Bool
$celem :: forall r a. Eq a => a -> RemoteSchemaRootField r a -> Bool
length :: RemoteSchemaRootField r a -> Int
$clength :: forall r a. RemoteSchemaRootField r a -> Int
null :: RemoteSchemaRootField r a -> Bool
$cnull :: forall r a. RemoteSchemaRootField r a -> Bool
toList :: RemoteSchemaRootField r a -> [a]
$ctoList :: forall r a. RemoteSchemaRootField r a -> [a]
foldl1 :: (a -> a -> a) -> RemoteSchemaRootField r a -> a
$cfoldl1 :: forall r a. (a -> a -> a) -> RemoteSchemaRootField r a -> a
foldr1 :: (a -> a -> a) -> RemoteSchemaRootField r a -> a
$cfoldr1 :: forall r a. (a -> a -> a) -> RemoteSchemaRootField r a -> a
foldl' :: (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b
$cfoldl' :: forall r b a. (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b
foldl :: (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b
$cfoldl :: forall r b a. (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b
foldr' :: (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b
$cfoldr' :: forall r a b. (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b
foldr :: (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b
$cfoldr :: forall r a b. (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b
foldMap' :: (a -> m) -> RemoteSchemaRootField r a -> m
$cfoldMap' :: forall r m a.
Monoid m =>
(a -> m) -> RemoteSchemaRootField r a -> m
foldMap :: (a -> m) -> RemoteSchemaRootField r a -> m
$cfoldMap :: forall r m a.
Monoid m =>
(a -> m) -> RemoteSchemaRootField r a -> m
fold :: RemoteSchemaRootField r m -> m
$cfold :: forall r m. Monoid m => RemoteSchemaRootField r m -> m
Foldable, Functor (RemoteSchemaRootField r)
Foldable (RemoteSchemaRootField r)
Functor (RemoteSchemaRootField r)
-> Foldable (RemoteSchemaRootField r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> RemoteSchemaRootField r a -> f (RemoteSchemaRootField r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    RemoteSchemaRootField r (f a) -> f (RemoteSchemaRootField r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> RemoteSchemaRootField r a -> m (RemoteSchemaRootField r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    RemoteSchemaRootField r (m a) -> m (RemoteSchemaRootField r a))
-> Traversable (RemoteSchemaRootField r)
(a -> f b)
-> RemoteSchemaRootField r a -> f (RemoteSchemaRootField r b)
forall r. Functor (RemoteSchemaRootField r)
forall r. Foldable (RemoteSchemaRootField r)
forall r (m :: * -> *) a.
Monad m =>
RemoteSchemaRootField r (m a) -> m (RemoteSchemaRootField r a)
forall r (f :: * -> *) a.
Applicative f =>
RemoteSchemaRootField r (f a) -> f (RemoteSchemaRootField r a)
forall r (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> RemoteSchemaRootField r a -> m (RemoteSchemaRootField r b)
forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> RemoteSchemaRootField r a -> f (RemoteSchemaRootField r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
RemoteSchemaRootField r (m a) -> m (RemoteSchemaRootField r a)
forall (f :: * -> *) a.
Applicative f =>
RemoteSchemaRootField r (f a) -> f (RemoteSchemaRootField r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> RemoteSchemaRootField r a -> m (RemoteSchemaRootField r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> RemoteSchemaRootField r a -> f (RemoteSchemaRootField r b)
sequence :: RemoteSchemaRootField r (m a) -> m (RemoteSchemaRootField r a)
$csequence :: forall r (m :: * -> *) a.
Monad m =>
RemoteSchemaRootField r (m a) -> m (RemoteSchemaRootField r a)
mapM :: (a -> m b)
-> RemoteSchemaRootField r a -> m (RemoteSchemaRootField r b)
$cmapM :: forall r (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> RemoteSchemaRootField r a -> m (RemoteSchemaRootField r b)
sequenceA :: RemoteSchemaRootField r (f a) -> f (RemoteSchemaRootField r a)
$csequenceA :: forall r (f :: * -> *) a.
Applicative f =>
RemoteSchemaRootField r (f a) -> f (RemoteSchemaRootField r a)
traverse :: (a -> f b)
-> RemoteSchemaRootField r a -> f (RemoteSchemaRootField r b)
$ctraverse :: forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> RemoteSchemaRootField r a -> f (RemoteSchemaRootField r b)
$cp2Traversable :: forall r. Foldable (RemoteSchemaRootField r)
$cp1Traversable :: forall r. Functor (RemoteSchemaRootField r)
Traversable)

-- | A remote relationship's selection and fields required for its join condition.
data SchemaRemoteRelationshipSelect r = SchemaRemoteRelationshipSelect
  { -- | The fields on the table that are required for the join condition
    -- of the remote relationship
    SchemaRemoteRelationshipSelect r -> HashMap FieldName Name
_srrsLHSJoinFields :: HashMap FieldName G.Name,
    -- | The field that captures the relationship
    -- r ~ (RemoteRelationshipField UnpreparedValue) when the AST is emitted by the parser.
    -- r ~ Void when an execution tree is constructed so that a backend is
    -- absolved of dealing with remote relationships.
    SchemaRemoteRelationshipSelect r -> r
_srrsRelationship :: r
  }
  deriving (SchemaRemoteRelationshipSelect r
-> SchemaRemoteRelationshipSelect r -> Bool
(SchemaRemoteRelationshipSelect r
 -> SchemaRemoteRelationshipSelect r -> Bool)
-> (SchemaRemoteRelationshipSelect r
    -> SchemaRemoteRelationshipSelect r -> Bool)
-> Eq (SchemaRemoteRelationshipSelect r)
forall r.
Eq r =>
SchemaRemoteRelationshipSelect r
-> SchemaRemoteRelationshipSelect r -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SchemaRemoteRelationshipSelect r
-> SchemaRemoteRelationshipSelect r -> Bool
$c/= :: forall r.
Eq r =>
SchemaRemoteRelationshipSelect r
-> SchemaRemoteRelationshipSelect r -> Bool
== :: SchemaRemoteRelationshipSelect r
-> SchemaRemoteRelationshipSelect r -> Bool
$c== :: forall r.
Eq r =>
SchemaRemoteRelationshipSelect r
-> SchemaRemoteRelationshipSelect r -> Bool
Eq, Int -> SchemaRemoteRelationshipSelect r -> ShowS
[SchemaRemoteRelationshipSelect r] -> ShowS
SchemaRemoteRelationshipSelect r -> String
(Int -> SchemaRemoteRelationshipSelect r -> ShowS)
-> (SchemaRemoteRelationshipSelect r -> String)
-> ([SchemaRemoteRelationshipSelect r] -> ShowS)
-> Show (SchemaRemoteRelationshipSelect r)
forall r.
Show r =>
Int -> SchemaRemoteRelationshipSelect r -> ShowS
forall r. Show r => [SchemaRemoteRelationshipSelect r] -> ShowS
forall r. Show r => SchemaRemoteRelationshipSelect r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SchemaRemoteRelationshipSelect r] -> ShowS
$cshowList :: forall r. Show r => [SchemaRemoteRelationshipSelect r] -> ShowS
show :: SchemaRemoteRelationshipSelect r -> String
$cshow :: forall r. Show r => SchemaRemoteRelationshipSelect r -> String
showsPrec :: Int -> SchemaRemoteRelationshipSelect r -> ShowS
$cshowsPrec :: forall r.
Show r =>
Int -> SchemaRemoteRelationshipSelect r -> ShowS
Show, a
-> SchemaRemoteRelationshipSelect b
-> SchemaRemoteRelationshipSelect a
(a -> b)
-> SchemaRemoteRelationshipSelect a
-> SchemaRemoteRelationshipSelect b
(forall a b.
 (a -> b)
 -> SchemaRemoteRelationshipSelect a
 -> SchemaRemoteRelationshipSelect b)
-> (forall a b.
    a
    -> SchemaRemoteRelationshipSelect b
    -> SchemaRemoteRelationshipSelect a)
-> Functor SchemaRemoteRelationshipSelect
forall a b.
a
-> SchemaRemoteRelationshipSelect b
-> SchemaRemoteRelationshipSelect a
forall a b.
(a -> b)
-> SchemaRemoteRelationshipSelect a
-> SchemaRemoteRelationshipSelect b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a
-> SchemaRemoteRelationshipSelect b
-> SchemaRemoteRelationshipSelect a
$c<$ :: forall a b.
a
-> SchemaRemoteRelationshipSelect b
-> SchemaRemoteRelationshipSelect a
fmap :: (a -> b)
-> SchemaRemoteRelationshipSelect a
-> SchemaRemoteRelationshipSelect b
$cfmap :: forall a b.
(a -> b)
-> SchemaRemoteRelationshipSelect a
-> SchemaRemoteRelationshipSelect b
Functor, SchemaRemoteRelationshipSelect a -> Bool
(a -> m) -> SchemaRemoteRelationshipSelect a -> m
(a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
(forall m. Monoid m => SchemaRemoteRelationshipSelect m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> SchemaRemoteRelationshipSelect a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> SchemaRemoteRelationshipSelect a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> SchemaRemoteRelationshipSelect a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> SchemaRemoteRelationshipSelect a -> b)
-> (forall a.
    (a -> a -> a) -> SchemaRemoteRelationshipSelect a -> a)
-> (forall a.
    (a -> a -> a) -> SchemaRemoteRelationshipSelect a -> a)
-> (forall a. SchemaRemoteRelationshipSelect a -> [a])
-> (forall a. SchemaRemoteRelationshipSelect a -> Bool)
-> (forall a. SchemaRemoteRelationshipSelect a -> Int)
-> (forall a.
    Eq a =>
    a -> SchemaRemoteRelationshipSelect a -> Bool)
-> (forall a. Ord a => SchemaRemoteRelationshipSelect a -> a)
-> (forall a. Ord a => SchemaRemoteRelationshipSelect a -> a)
-> (forall a. Num a => SchemaRemoteRelationshipSelect a -> a)
-> (forall a. Num a => SchemaRemoteRelationshipSelect a -> a)
-> Foldable SchemaRemoteRelationshipSelect
forall a. Eq a => a -> SchemaRemoteRelationshipSelect a -> Bool
forall a. Num a => SchemaRemoteRelationshipSelect a -> a
forall a. Ord a => SchemaRemoteRelationshipSelect a -> a
forall m. Monoid m => SchemaRemoteRelationshipSelect m -> m
forall a. SchemaRemoteRelationshipSelect a -> Bool
forall a. SchemaRemoteRelationshipSelect a -> Int
forall a. SchemaRemoteRelationshipSelect a -> [a]
forall a. (a -> a -> a) -> SchemaRemoteRelationshipSelect a -> a
forall m a.
Monoid m =>
(a -> m) -> SchemaRemoteRelationshipSelect a -> m
forall b a.
(b -> a -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
forall a b.
(a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: SchemaRemoteRelationshipSelect a -> a
$cproduct :: forall a. Num a => SchemaRemoteRelationshipSelect a -> a
sum :: SchemaRemoteRelationshipSelect a -> a
$csum :: forall a. Num a => SchemaRemoteRelationshipSelect a -> a
minimum :: SchemaRemoteRelationshipSelect a -> a
$cminimum :: forall a. Ord a => SchemaRemoteRelationshipSelect a -> a
maximum :: SchemaRemoteRelationshipSelect a -> a
$cmaximum :: forall a. Ord a => SchemaRemoteRelationshipSelect a -> a
elem :: a -> SchemaRemoteRelationshipSelect a -> Bool
$celem :: forall a. Eq a => a -> SchemaRemoteRelationshipSelect a -> Bool
length :: SchemaRemoteRelationshipSelect a -> Int
$clength :: forall a. SchemaRemoteRelationshipSelect a -> Int
null :: SchemaRemoteRelationshipSelect a -> Bool
$cnull :: forall a. SchemaRemoteRelationshipSelect a -> Bool
toList :: SchemaRemoteRelationshipSelect a -> [a]
$ctoList :: forall a. SchemaRemoteRelationshipSelect a -> [a]
foldl1 :: (a -> a -> a) -> SchemaRemoteRelationshipSelect a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> SchemaRemoteRelationshipSelect a -> a
foldr1 :: (a -> a -> a) -> SchemaRemoteRelationshipSelect a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> SchemaRemoteRelationshipSelect a -> a
foldl' :: (b -> a -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
$cfoldl' :: forall b a.
(b -> a -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
foldl :: (b -> a -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
$cfoldl :: forall b a.
(b -> a -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
foldr' :: (a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
$cfoldr' :: forall a b.
(a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
foldr :: (a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
$cfoldr :: forall a b.
(a -> b -> b) -> b -> SchemaRemoteRelationshipSelect a -> b
foldMap' :: (a -> m) -> SchemaRemoteRelationshipSelect a -> m
$cfoldMap' :: forall m a.
Monoid m =>
(a -> m) -> SchemaRemoteRelationshipSelect a -> m
foldMap :: (a -> m) -> SchemaRemoteRelationshipSelect a -> m
$cfoldMap :: forall m a.
Monoid m =>
(a -> m) -> SchemaRemoteRelationshipSelect a -> m
fold :: SchemaRemoteRelationshipSelect m -> m
$cfold :: forall m. Monoid m => SchemaRemoteRelationshipSelect m -> m
Foldable, Functor SchemaRemoteRelationshipSelect
Foldable SchemaRemoteRelationshipSelect
Functor SchemaRemoteRelationshipSelect
-> Foldable SchemaRemoteRelationshipSelect
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> SchemaRemoteRelationshipSelect a
    -> f (SchemaRemoteRelationshipSelect b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    SchemaRemoteRelationshipSelect (f a)
    -> f (SchemaRemoteRelationshipSelect a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> SchemaRemoteRelationshipSelect a
    -> m (SchemaRemoteRelationshipSelect b))
-> (forall (m :: * -> *) a.
    Monad m =>
    SchemaRemoteRelationshipSelect (m a)
    -> m (SchemaRemoteRelationshipSelect a))
-> Traversable SchemaRemoteRelationshipSelect
(a -> f b)
-> SchemaRemoteRelationshipSelect a
-> f (SchemaRemoteRelationshipSelect b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
SchemaRemoteRelationshipSelect (m a)
-> m (SchemaRemoteRelationshipSelect a)
forall (f :: * -> *) a.
Applicative f =>
SchemaRemoteRelationshipSelect (f a)
-> f (SchemaRemoteRelationshipSelect a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> SchemaRemoteRelationshipSelect a
-> m (SchemaRemoteRelationshipSelect b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> SchemaRemoteRelationshipSelect a
-> f (SchemaRemoteRelationshipSelect b)
sequence :: SchemaRemoteRelationshipSelect (m a)
-> m (SchemaRemoteRelationshipSelect a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
SchemaRemoteRelationshipSelect (m a)
-> m (SchemaRemoteRelationshipSelect a)
mapM :: (a -> m b)
-> SchemaRemoteRelationshipSelect a
-> m (SchemaRemoteRelationshipSelect b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> SchemaRemoteRelationshipSelect a
-> m (SchemaRemoteRelationshipSelect b)
sequenceA :: SchemaRemoteRelationshipSelect (f a)
-> f (SchemaRemoteRelationshipSelect a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
SchemaRemoteRelationshipSelect (f a)
-> f (SchemaRemoteRelationshipSelect a)
traverse :: (a -> f b)
-> SchemaRemoteRelationshipSelect a
-> f (SchemaRemoteRelationshipSelect b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> SchemaRemoteRelationshipSelect a
-> f (SchemaRemoteRelationshipSelect b)
$cp2Traversable :: Foldable SchemaRemoteRelationshipSelect
$cp1Traversable :: Functor SchemaRemoteRelationshipSelect
Traversable)

data RemoteFieldArgument = RemoteFieldArgument
  { RemoteFieldArgument -> Name
_rfaArgument :: G.Name,
    RemoteFieldArgument -> InputValue RemoteSchemaVariable
_rfaValue :: InputValue RemoteSchemaVariable
  }
  deriving (RemoteFieldArgument -> RemoteFieldArgument -> Bool
(RemoteFieldArgument -> RemoteFieldArgument -> Bool)
-> (RemoteFieldArgument -> RemoteFieldArgument -> Bool)
-> Eq RemoteFieldArgument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RemoteFieldArgument -> RemoteFieldArgument -> Bool
$c/= :: RemoteFieldArgument -> RemoteFieldArgument -> Bool
== :: RemoteFieldArgument -> RemoteFieldArgument -> Bool
$c== :: RemoteFieldArgument -> RemoteFieldArgument -> Bool
Eq, Int -> RemoteFieldArgument -> ShowS
[RemoteFieldArgument] -> ShowS
RemoteFieldArgument -> String
(Int -> RemoteFieldArgument -> ShowS)
-> (RemoteFieldArgument -> String)
-> ([RemoteFieldArgument] -> ShowS)
-> Show RemoteFieldArgument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RemoteFieldArgument] -> ShowS
$cshowList :: [RemoteFieldArgument] -> ShowS
show :: RemoteFieldArgument -> String
$cshow :: RemoteFieldArgument -> String
showsPrec :: Int -> RemoteFieldArgument -> ShowS
$cshowsPrec :: Int -> RemoteFieldArgument -> ShowS
Show)

data RemoteSchemaSelect r = RemoteSchemaSelect
  { RemoteSchemaSelect r -> [RemoteFieldArgument]
_rselArgs :: [RemoteFieldArgument],
    RemoteSchemaSelect r -> ResultCustomizer
_rselResultCustomizer :: ResultCustomizer,
    RemoteSchemaSelect r -> SelectionSet r RemoteSchemaVariable
_rselSelection :: SelectionSet r RemoteSchemaVariable,
    RemoteSchemaSelect r -> NonEmpty FieldCall
_rselFieldCall :: NonEmpty FieldCall,
    RemoteSchemaSelect r -> RemoteSchemaInfo
_rselRemoteSchema :: RemoteSchemaInfo
  }

-------------------------------------------------------------------------------
-- Conversion back to a GraphQL document

-- | Converts a normalized selection set back into a selection set as defined in
-- GraphQL spec, in order to send it to a remote server.
--
-- This function expects a 'SelectionSet' for which @r@ is 'Void', which
-- guarantees that there is no longer any remote join field in the selection
-- set.
convertSelectionSet ::
  forall var.
  Eq var =>
  SelectionSet Void var ->
  G.SelectionSet G.NoFragments var
convertSelectionSet :: SelectionSet Void var -> SelectionSet NoFragments var
convertSelectionSet = \case
  SelectionSetObject ObjectSelectionSet Void var
s -> ObjectSelectionSet Void var -> SelectionSet NoFragments var
convertObjectSelectionSet ObjectSelectionSet Void var
s
  SelectionSetUnion DeduplicatedSelectionSet Void var
s -> DeduplicatedSelectionSet Void var -> SelectionSet NoFragments var
convertAbstractTypeSelectionSet DeduplicatedSelectionSet Void var
s
  SelectionSetInterface DeduplicatedSelectionSet Void var
s -> DeduplicatedSelectionSet Void var -> SelectionSet NoFragments var
convertAbstractTypeSelectionSet DeduplicatedSelectionSet Void var
s
  SelectionSet Void var
SelectionSetNone -> SelectionSet NoFragments var
forall a. Monoid a => a
mempty
  where
    convertField :: Field Void var -> G.Field G.NoFragments var
    convertField :: Field Void var -> Field NoFragments var
convertField = \case
      FieldGraphQL GraphQLField Void var
f -> GraphQLField Void var -> Field NoFragments var
forall var.
Eq var =>
GraphQLField Void var -> Field NoFragments var
convertGraphQLField GraphQLField Void var
f

    convertObjectSelectionSet :: ObjectSelectionSet Void var -> SelectionSet NoFragments var
convertObjectSelectionSet =
      ((Name, Field Void var) -> Selection NoFragments var)
-> [(Name, Field Void var)] -> SelectionSet NoFragments var
forall a b. (a -> b) -> [a] -> [b]
map (Field NoFragments var -> Selection NoFragments var
forall (frag :: * -> *) var. Field frag var -> Selection frag var
G.SelectionField (Field NoFragments var -> Selection NoFragments var)
-> ((Name, Field Void var) -> Field NoFragments var)
-> (Name, Field Void var)
-> Selection NoFragments var
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Field Void var -> Field NoFragments var
convertField (Field Void var -> Field NoFragments var)
-> ((Name, Field Void var) -> Field Void var)
-> (Name, Field Void var)
-> Field NoFragments var
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, Field Void var) -> Field Void var
forall a b. (a, b) -> b
snd) ([(Name, Field Void var)] -> SelectionSet NoFragments var)
-> (ObjectSelectionSet Void var -> [(Name, Field Void var)])
-> ObjectSelectionSet Void var
-> SelectionSet NoFragments var
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjectSelectionSet Void var -> [(Name, Field Void var)]
forall k v. InsOrdHashMap k v -> [(k, v)]
OMap.toList

    convertAbstractTypeSelectionSet :: DeduplicatedSelectionSet Void var -> SelectionSet NoFragments var
convertAbstractTypeSelectionSet DeduplicatedSelectionSet Void var
abstractSelectionSet =
      let (ObjectSelectionSet Void var
base, HashMap Name (ObjectSelectionSet Void var)
members) = DeduplicatedSelectionSet Void var
-> (ObjectSelectionSet Void var,
    HashMap Name (ObjectSelectionSet Void var))
forall var.
Eq var =>
DeduplicatedSelectionSet Void var
-> (ObjectSelectionSet Void var,
    HashMap Name (ObjectSelectionSet Void var))
reduceAbstractTypeSelectionSet DeduplicatedSelectionSet Void var
abstractSelectionSet
          commonFields :: SelectionSet NoFragments var
commonFields = ObjectSelectionSet Void var -> SelectionSet NoFragments var
convertObjectSelectionSet ObjectSelectionSet Void var
base
          concreteTypeSelectionSets :: [InlineFragment NoFragments var]
concreteTypeSelectionSets =
            HashMap Name (ObjectSelectionSet Void var)
-> [(Name, ObjectSelectionSet Void var)]
forall k v. HashMap k v -> [(k, v)]
Map.toList HashMap Name (ObjectSelectionSet Void var)
members [(Name, ObjectSelectionSet Void var)]
-> ((Name, ObjectSelectionSet Void var)
    -> InlineFragment NoFragments var)
-> [InlineFragment NoFragments var]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(Name
concreteType, ObjectSelectionSet Void var
selectionSet) ->
              InlineFragment :: forall (frag :: * -> *) var.
Maybe Name
-> [Directive var]
-> SelectionSet frag var
-> InlineFragment frag var
G.InlineFragment
                { _ifTypeCondition :: Maybe Name
G._ifTypeCondition = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
concreteType,
                  _ifDirectives :: [Directive var]
G._ifDirectives = [Directive var]
forall a. Monoid a => a
mempty,
                  _ifSelectionSet :: SelectionSet NoFragments var
G._ifSelectionSet = ObjectSelectionSet Void var -> SelectionSet NoFragments var
convertObjectSelectionSet ObjectSelectionSet Void var
selectionSet
                }
       in -- The base selection set first and then the more specific member
          -- selection sets. Note that the rendering strategy here should be
          -- inline with the strategy used in `mkAbstractTypeSelectionSet`
          SelectionSet NoFragments var
commonFields SelectionSet NoFragments var
-> SelectionSet NoFragments var -> SelectionSet NoFragments var
forall a. Semigroup a => a -> a -> a
<> (InlineFragment NoFragments var -> Selection NoFragments var)
-> [InlineFragment NoFragments var] -> SelectionSet NoFragments var
forall a b. (a -> b) -> [a] -> [b]
map InlineFragment NoFragments var -> Selection NoFragments var
forall (frag :: * -> *) var.
InlineFragment frag var -> Selection frag var
G.SelectionInlineFragment [InlineFragment NoFragments var]
concreteTypeSelectionSets

convertGraphQLField :: Eq var => GraphQLField Void var -> G.Field G.NoFragments var
convertGraphQLField :: GraphQLField Void var -> Field NoFragments var
convertGraphQLField GraphQLField {[Directive var]
HashMap Name (Value var)
Name
SelectionSet Void var
_fSelectionSet :: SelectionSet Void var
_fDirectives :: [Directive var]
_fArguments :: HashMap Name (Value var)
_fName :: Name
_fAlias :: Name
_fSelectionSet :: forall r var. GraphQLField r var -> SelectionSet r var
_fDirectives :: forall r var. GraphQLField r var -> [Directive var]
_fArguments :: forall r var. GraphQLField r var -> HashMap Name (Value var)
_fName :: forall r var. GraphQLField r var -> Name
_fAlias :: forall r var. GraphQLField r var -> Name
..} =
  Field :: forall (frag :: * -> *) var.
Maybe Name
-> Name
-> HashMap Name (Value var)
-> [Directive var]
-> SelectionSet frag var
-> Field frag var
G.Field
    { -- add the alias only if it is different from the field name. This
      -- keeps the outbound request more readable
      _fAlias :: Maybe Name
G._fAlias = if Name
_fAlias Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
/= Name
_fName then Name -> Maybe Name
forall a. a -> Maybe a
Just Name
_fAlias else Maybe Name
forall a. Maybe a
Nothing,
      _fName :: Name
G._fName = Name
_fName,
      _fArguments :: HashMap Name (Value var)
G._fArguments = HashMap Name (Value var)
_fArguments,
      _fDirectives :: [Directive var]
G._fDirectives = [Directive var]
forall a. Monoid a => a
mempty,
      _fSelectionSet :: SelectionSet NoFragments var
G._fSelectionSet = SelectionSet Void var -> SelectionSet NoFragments var
forall var.
Eq var =>
SelectionSet Void var -> SelectionSet NoFragments var
convertSelectionSet SelectionSet Void var
_fSelectionSet
    }

-- | Builds the selection set for an abstract type.
--
-- Let's consider this query on starwars API:
-- The type `Node` an interface is implemented by `Film`, `Species`, `Planet`,
-- `Person`, `Starship`, `Vehicle`
--
-- query f {
--   node(id: "ZmlsbXM6MQ==") {
--     __typename
--     id
--     ... on Film {
--       title
--     }
--     ... on Species {
--       name
--     }
--   }
-- }
--
-- When we parse this, it gets normalized into this query:
--
-- query f {
--   node(id: "ZmlsbXM6MQ==") {
--     ... on Film {
--       __typename: __typename
--       id
--       title
--     }
--     ... on Species {
--       __typename: __typename
--       id
--       name
--     }
--     ... on Planet {
--       __typename: __typename
--       id
--     }
--     ... on Person {
--       __typename: __typename
--       id
--     }
--     ... on Starship {
--       __typename: __typename
--       id
--     }
--     ... on Vehicle {
--       __typename: __typename
--       id
--     }
--   }
-- }
--
-- `__typename` and `id` get pushed to each of the member types. From the above
-- normalized selection set, we want to costruct a query as close to the
-- original as possible. We do this as follows:
--
-- 1. find the longest common set of fields that each selection set starts with
--    (in the above case, they are `__typename` and `id`)
-- 2. from the above list of fields, find the first field that cannot be
--    defined on the abstract type. The fields that can be defined on the
--    abstract type are all the fields that occur before the first non abstract
--    type field (in the above case, both` __typename` and `id` can be defined
--    on the `Node` type)
-- 3. Strip the base selection set fields from all the member selection sets and
--    filter out the member type selection sets that are subsumed by the base
--    selection set
--
-- The above query now translates to this:
--
-- query f {
--   node(id: "ZmlsbXM6MQ==") {
--     __typename: __typename
--     id
--     ... on Film {
--       title
--     }
--     ... on Species {
--       name
--     }
--   }
-- }
--
-- Note that it is not always possible to get the same shape as the original
-- query and there is more than one approach to this. For example, we could
-- have picked the selection set (that can be defined on the abstract type)
-- that is common across all the member selection sets and used that as the
-- base selection.
reduceAbstractTypeSelectionSet ::
  (Eq var) =>
  DeduplicatedSelectionSet Void var ->
  (ObjectSelectionSet Void var, Map.HashMap G.Name (ObjectSelectionSet Void var))
reduceAbstractTypeSelectionSet :: DeduplicatedSelectionSet Void var
-> (ObjectSelectionSet Void var,
    HashMap Name (ObjectSelectionSet Void var))
reduceAbstractTypeSelectionSet (DeduplicatedSelectionSet HashSet Name
baseMemberFields HashMap Name (ObjectSelectionSet Void var)
selectionSets) =
  (ObjectSelectionSet Void var
baseSelectionSet, [(Name, ObjectSelectionSet Void var)]
-> HashMap Name (ObjectSelectionSet Void var)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
Map.fromList [(Name, ObjectSelectionSet Void var)]
memberSelectionSets)
  where
    sharedSelectionSetPrefix :: [(Name, Field Void var)]
sharedSelectionSetPrefix = [[(Name, Field Void var)]] -> [(Name, Field Void var)]
forall a. Eq a => [[a]] -> [a]
longestCommonPrefix ([[(Name, Field Void var)]] -> [(Name, Field Void var)])
-> [[(Name, Field Void var)]] -> [(Name, Field Void var)]
forall a b. (a -> b) -> a -> b
$ ((Name, ObjectSelectionSet Void var) -> [(Name, Field Void var)])
-> [(Name, ObjectSelectionSet Void var)]
-> [[(Name, Field Void var)]]
forall a b. (a -> b) -> [a] -> [b]
map (ObjectSelectionSet Void var -> [(Name, Field Void var)]
forall k v. InsOrdHashMap k v -> [(k, v)]
OMap.toList (ObjectSelectionSet Void var -> [(Name, Field Void var)])
-> ((Name, ObjectSelectionSet Void var)
    -> ObjectSelectionSet Void var)
-> (Name, ObjectSelectionSet Void var)
-> [(Name, Field Void var)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, ObjectSelectionSet Void var) -> ObjectSelectionSet Void var
forall a b. (a, b) -> b
snd) ([(Name, ObjectSelectionSet Void var)]
 -> [[(Name, Field Void var)]])
-> [(Name, ObjectSelectionSet Void var)]
-> [[(Name, Field Void var)]]
forall a b. (a -> b) -> a -> b
$ HashMap Name (ObjectSelectionSet Void var)
-> [(Name, ObjectSelectionSet Void var)]
forall k v. HashMap k v -> [(k, v)]
Map.toList HashMap Name (ObjectSelectionSet Void var)
selectionSets

    baseSelectionSet :: ObjectSelectionSet Void var
baseSelectionSet = [(Name, Field Void var)] -> ObjectSelectionSet Void var
forall k v. (Eq k, Hashable k) => [(k, v)] -> InsOrdHashMap k v
OMap.fromList ([(Name, Field Void var)] -> ObjectSelectionSet Void var)
-> [(Name, Field Void var)] -> ObjectSelectionSet Void var
forall a b. (a -> b) -> a -> b
$ ((Name, Field Void var) -> Bool)
-> [(Name, Field Void var)] -> [(Name, Field Void var)]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Field Void var -> Bool
shouldAddToBase (Field Void var -> Bool)
-> ((Name, Field Void var) -> Field Void var)
-> (Name, Field Void var)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, Field Void var) -> Field Void var
forall a b. (a, b) -> b
snd) [(Name, Field Void var)]
sharedSelectionSetPrefix

    shouldAddToBase :: Field Void var -> Bool
shouldAddToBase = \case
      FieldGraphQL GraphQLField Void var
f -> Name -> HashSet Name -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
Set.member (GraphQLField Void var -> Name
forall r var. GraphQLField r var -> Name
_fName GraphQLField Void var
f) HashSet Name
baseMemberFields

    memberSelectionSets :: [(Name, ObjectSelectionSet Void var)]
memberSelectionSets =
      -- remove member selection sets that are subsumed by base selection set
      ((Name, ObjectSelectionSet Void var) -> Bool)
-> [(Name, ObjectSelectionSet Void var)]
-> [(Name, ObjectSelectionSet Void var)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> ((Name, ObjectSelectionSet Void var) -> Bool)
-> (Name, ObjectSelectionSet Void var)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjectSelectionSet Void var -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (ObjectSelectionSet Void var -> Bool)
-> ((Name, ObjectSelectionSet Void var)
    -> ObjectSelectionSet Void var)
-> (Name, ObjectSelectionSet Void var)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, ObjectSelectionSet Void var) -> ObjectSelectionSet Void var
forall a b. (a, b) -> b
snd) ([(Name, ObjectSelectionSet Void var)]
 -> [(Name, ObjectSelectionSet Void var)])
-> [(Name, ObjectSelectionSet Void var)]
-> [(Name, ObjectSelectionSet Void var)]
forall a b. (a -> b) -> a -> b
$
        -- remove the common prefix from member selection sets
        ((Name, ObjectSelectionSet Void var)
 -> (Name, ObjectSelectionSet Void var))
-> [(Name, ObjectSelectionSet Void var)]
-> [(Name, ObjectSelectionSet Void var)]
forall a b. (a -> b) -> [a] -> [b]
map ((ObjectSelectionSet Void var -> ObjectSelectionSet Void var)
-> (Name, ObjectSelectionSet Void var)
-> (Name, ObjectSelectionSet Void var)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ([(Name, Field Void var)] -> ObjectSelectionSet Void var
forall k v. (Eq k, Hashable k) => [(k, v)] -> InsOrdHashMap k v
OMap.fromList ([(Name, Field Void var)] -> ObjectSelectionSet Void var)
-> (ObjectSelectionSet Void var -> [(Name, Field Void var)])
-> ObjectSelectionSet Void var
-> ObjectSelectionSet Void var
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [(Name, Field Void var)] -> [(Name, Field Void var)]
forall a. Int -> [a] -> [a]
drop (ObjectSelectionSet Void var -> Int
forall k v. InsOrdHashMap k v -> Int
OMap.size ObjectSelectionSet Void var
baseSelectionSet) ([(Name, Field Void var)] -> [(Name, Field Void var)])
-> (ObjectSelectionSet Void var -> [(Name, Field Void var)])
-> ObjectSelectionSet Void var
-> [(Name, Field Void var)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ObjectSelectionSet Void var -> [(Name, Field Void var)]
forall k v. InsOrdHashMap k v -> [(k, v)]
OMap.toList)) ([(Name, ObjectSelectionSet Void var)]
 -> [(Name, ObjectSelectionSet Void var)])
-> [(Name, ObjectSelectionSet Void var)]
-> [(Name, ObjectSelectionSet Void var)]
forall a b. (a -> b) -> a -> b
$ HashMap Name (ObjectSelectionSet Void var)
-> [(Name, ObjectSelectionSet Void var)]
forall k v. HashMap k v -> [(k, v)]
Map.toList HashMap Name (ObjectSelectionSet Void var)
selectionSets

-------------------------------------------------------------------------------
-- TH lens generation

$(makePrisms ''Field)
$(makeLenses ''GraphQLField)
$(makeLenses ''DeduplicatedSelectionSet)