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

Hasura.RQL.IR.RemoteSchema

Description

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.

Synopsis

Documentation

data SelectionSet r var Source #

Custom representation of a selection set.

Similarly to other parts of the IR, the r argument is used for remote relationships.

Instances

Instances details
Functor (SelectionSet r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fmap :: (a -> b) -> SelectionSet r a -> SelectionSet r b #

(<$) :: a -> SelectionSet r b -> SelectionSet r a #

Foldable (SelectionSet r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fold :: Monoid m => SelectionSet r m -> m #

foldMap :: Monoid m => (a -> m) -> SelectionSet r a -> m #

foldMap' :: Monoid m => (a -> m) -> SelectionSet r a -> m #

foldr :: (a -> b -> b) -> b -> SelectionSet r a -> b #

foldr' :: (a -> b -> b) -> b -> SelectionSet r a -> b #

foldl :: (b -> a -> b) -> b -> SelectionSet r a -> b #

foldl' :: (b -> a -> b) -> b -> SelectionSet r a -> b #

foldr1 :: (a -> a -> a) -> SelectionSet r a -> a #

foldl1 :: (a -> a -> a) -> SelectionSet r a -> a #

toList :: SelectionSet r a -> [a] #

null :: SelectionSet r a -> Bool #

length :: SelectionSet r a -> Int #

elem :: Eq a => a -> SelectionSet r a -> Bool #

maximum :: Ord a => SelectionSet r a -> a #

minimum :: Ord a => SelectionSet r a -> a #

sum :: Num a => SelectionSet r a -> a #

product :: Num a => SelectionSet r a -> a #

Traversable (SelectionSet r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

traverse :: Applicative f => (a -> f b) -> SelectionSet r a -> f (SelectionSet r b) #

sequenceA :: Applicative f => SelectionSet r (f a) -> f (SelectionSet r a) #

mapM :: Monad m => (a -> m b) -> SelectionSet r a -> m (SelectionSet r b) #

sequence :: Monad m => SelectionSet r (m a) -> m (SelectionSet r a) #

(Eq var, Eq r) => Eq (SelectionSet r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

(==) :: SelectionSet r var -> SelectionSet r var -> Bool #

(/=) :: SelectionSet r var -> SelectionSet r var -> Bool #

(Show var, Show r) => Show (SelectionSet r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

showsPrec :: Int -> SelectionSet r var -> ShowS #

show :: SelectionSet r var -> String #

showList :: [SelectionSet r var] -> ShowS #

data DeduplicatedSelectionSet r var Source #

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.

Constructors

DeduplicatedSelectionSet 

Fields

Instances

Instances details
Functor (DeduplicatedSelectionSet r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Foldable (DeduplicatedSelectionSet r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fold :: Monoid m => DeduplicatedSelectionSet r m -> m #

foldMap :: Monoid m => (a -> m) -> DeduplicatedSelectionSet r a -> m #

foldMap' :: Monoid m => (a -> m) -> DeduplicatedSelectionSet r a -> m #

foldr :: (a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b #

foldr' :: (a -> b -> b) -> b -> DeduplicatedSelectionSet r a -> b #

foldl :: (b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b #

foldl' :: (b -> a -> b) -> b -> DeduplicatedSelectionSet r a -> b #

foldr1 :: (a -> a -> a) -> DeduplicatedSelectionSet r a -> a #

foldl1 :: (a -> a -> a) -> DeduplicatedSelectionSet r a -> a #

toList :: DeduplicatedSelectionSet r a -> [a] #

null :: DeduplicatedSelectionSet r a -> Bool #

length :: DeduplicatedSelectionSet r a -> Int #

elem :: Eq a => a -> DeduplicatedSelectionSet r a -> Bool #

maximum :: Ord a => DeduplicatedSelectionSet r a -> a #

minimum :: Ord a => DeduplicatedSelectionSet r a -> a #

sum :: Num a => DeduplicatedSelectionSet r a -> a #

product :: Num a => DeduplicatedSelectionSet r a -> a #

Traversable (DeduplicatedSelectionSet r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

(Eq var, Eq r) => Eq (DeduplicatedSelectionSet r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

(Show var, Show r) => Show (DeduplicatedSelectionSet r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Generic (DeduplicatedSelectionSet r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Associated Types

type Rep (DeduplicatedSelectionSet r var) :: Type -> Type #

type Rep (DeduplicatedSelectionSet r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

type Rep (DeduplicatedSelectionSet r var) = D1 ('MetaData "DeduplicatedSelectionSet" "Hasura.RQL.IR.RemoteSchema" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "DeduplicatedSelectionSet" 'PrefixI 'True) (S1 ('MetaSel ('Just "_dssCommonFields") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashSet Name)) :*: S1 ('MetaSel ('Just "_dssMemberSelectionSets") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashMap Name (ObjectSelectionSet r var)))))

type ObjectSelectionSet r var = InsOrdHashMap Name (Field r var) Source #

mkInterfaceSelectionSet Source #

Arguments

:: HashSet Name

Member fields of the interface

-> [(Name, ObjectSelectionSet r var)]

Selection sets for all the member types

-> DeduplicatedSelectionSet 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.

mkUnionSelectionSet Source #

Arguments

:: [(Name, ObjectSelectionSet r var)]

Selection sets for all the member types

-> DeduplicatedSelectionSet r var 

Constructs an UnionSelectionSet from a list of the fields, using a singleton set of __typename for the set of common fields.

data Field r var Source #

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.

Instances

Instances details
Functor (Field r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fmap :: (a -> b) -> Field r a -> Field r b #

(<$) :: a -> Field r b -> Field r a #

Foldable (Field r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fold :: Monoid m => Field r m -> m #

foldMap :: Monoid m => (a -> m) -> Field r a -> m #

foldMap' :: Monoid m => (a -> m) -> Field r a -> m #

foldr :: (a -> b -> b) -> b -> Field r a -> b #

foldr' :: (a -> b -> b) -> b -> Field r a -> b #

foldl :: (b -> a -> b) -> b -> Field r a -> b #

foldl' :: (b -> a -> b) -> b -> Field r a -> b #

foldr1 :: (a -> a -> a) -> Field r a -> a #

foldl1 :: (a -> a -> a) -> Field r a -> a #

toList :: Field r a -> [a] #

null :: Field r a -> Bool #

length :: Field r a -> Int #

elem :: Eq a => a -> Field r a -> Bool #

maximum :: Ord a => Field r a -> a #

minimum :: Ord a => Field r a -> a #

sum :: Num a => Field r a -> a #

product :: Num a => Field r a -> a #

Traversable (Field r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

traverse :: Applicative f => (a -> f b) -> Field r a -> f (Field r b) #

sequenceA :: Applicative f => Field r (f a) -> f (Field r a) #

mapM :: Monad m => (a -> m b) -> Field r a -> m (Field r b) #

sequence :: Monad m => Field r (m a) -> m (Field r a) #

(Eq var, Eq r) => Eq (Field r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

(==) :: Field r var -> Field r var -> Bool #

(/=) :: Field r var -> Field r var -> Bool #

(Show var, Show r) => Show (Field r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

showsPrec :: Int -> Field r var -> ShowS #

show :: Field r var -> String #

showList :: [Field r var] -> ShowS #

data GraphQLField r var Source #

Normalized representation of a GraphQL field.

This type is almost identical to Field, except for the fact that the selection set is our annotated SelectionSet, instead of the original SelectionSet. We use this type to represent the fields of a selection that do target the remote schema.

Constructors

GraphQLField 

Fields

Instances

Instances details
Functor (GraphQLField r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fmap :: (a -> b) -> GraphQLField r a -> GraphQLField r b #

(<$) :: a -> GraphQLField r b -> GraphQLField r a #

Foldable (GraphQLField r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fold :: Monoid m => GraphQLField r m -> m #

foldMap :: Monoid m => (a -> m) -> GraphQLField r a -> m #

foldMap' :: Monoid m => (a -> m) -> GraphQLField r a -> m #

foldr :: (a -> b -> b) -> b -> GraphQLField r a -> b #

foldr' :: (a -> b -> b) -> b -> GraphQLField r a -> b #

foldl :: (b -> a -> b) -> b -> GraphQLField r a -> b #

foldl' :: (b -> a -> b) -> b -> GraphQLField r a -> b #

foldr1 :: (a -> a -> a) -> GraphQLField r a -> a #

foldl1 :: (a -> a -> a) -> GraphQLField r a -> a #

toList :: GraphQLField r a -> [a] #

null :: GraphQLField r a -> Bool #

length :: GraphQLField r a -> Int #

elem :: Eq a => a -> GraphQLField r a -> Bool #

maximum :: Ord a => GraphQLField r a -> a #

minimum :: Ord a => GraphQLField r a -> a #

sum :: Num a => GraphQLField r a -> a #

product :: Num a => GraphQLField r a -> a #

Traversable (GraphQLField r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

traverse :: Applicative f => (a -> f b) -> GraphQLField r a -> f (GraphQLField r b) #

sequenceA :: Applicative f => GraphQLField r (f a) -> f (GraphQLField r a) #

mapM :: Monad m => (a -> m b) -> GraphQLField r a -> m (GraphQLField r b) #

sequence :: Monad m => GraphQLField r (m a) -> m (GraphQLField r a) #

(Eq var, Eq r) => Eq (GraphQLField r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

(==) :: GraphQLField r var -> GraphQLField r var -> Bool #

(/=) :: GraphQLField r var -> GraphQLField r var -> Bool #

(Show var, Show r) => Show (GraphQLField r var) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

showsPrec :: Int -> GraphQLField r var -> ShowS #

show :: GraphQLField r var -> String #

showList :: [GraphQLField r var] -> ShowS #

mkGraphQLField :: Maybe Name -> Name -> HashMap Name (Value var) -> [Directive var] -> SelectionSet r var -> GraphQLField r var Source #

data RemoteSchemaRootField r var Source #

Root entry point for a remote schema.

Instances

Instances details
Functor (RemoteSchemaRootField r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Foldable (RemoteSchemaRootField r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Methods

fold :: Monoid m => RemoteSchemaRootField r m -> m #

foldMap :: Monoid m => (a -> m) -> RemoteSchemaRootField r a -> m #

foldMap' :: Monoid m => (a -> m) -> RemoteSchemaRootField r a -> m #

foldr :: (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b #

foldr' :: (a -> b -> b) -> b -> RemoteSchemaRootField r a -> b #

foldl :: (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b #

foldl' :: (b -> a -> b) -> b -> RemoteSchemaRootField r a -> b #

foldr1 :: (a -> a -> a) -> RemoteSchemaRootField r a -> a #

foldl1 :: (a -> a -> a) -> RemoteSchemaRootField r a -> a #

toList :: RemoteSchemaRootField r a -> [a] #

null :: RemoteSchemaRootField r a -> Bool #

length :: RemoteSchemaRootField r a -> Int #

elem :: Eq a => a -> RemoteSchemaRootField r a -> Bool #

maximum :: Ord a => RemoteSchemaRootField r a -> a #

minimum :: Ord a => RemoteSchemaRootField r a -> a #

sum :: Num a => RemoteSchemaRootField r a -> a #

product :: Num a => RemoteSchemaRootField r a -> a #

Traversable (RemoteSchemaRootField r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

data SchemaRemoteRelationshipSelect r Source #

A remote relationship's selection and fields required for its join condition.

Constructors

SchemaRemoteRelationshipSelect 

Fields

  • _srrsLHSJoinFields :: HashMap FieldName Name

    The fields on the table that are required for the join condition of the remote relationship

  • _srrsRelationship :: r

    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.

Instances

Instances details
Functor SchemaRemoteRelationshipSelect Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Foldable SchemaRemoteRelationshipSelect Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Traversable SchemaRemoteRelationshipSelect Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Eq r => Eq (SchemaRemoteRelationshipSelect r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

Show r => Show (SchemaRemoteRelationshipSelect r) Source # 
Instance details

Defined in Hasura.RQL.IR.RemoteSchema

convertSelectionSet :: forall var. Eq var => SelectionSet Void var -> SelectionSet NoFragments var Source #

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.

convertGraphQLField :: Eq var => GraphQLField Void var -> Field NoFragments var Source #

reduceAbstractTypeSelectionSet :: Eq var => DeduplicatedSelectionSet Void var -> (ObjectSelectionSet Void var, HashMap Name (ObjectSelectionSet Void var)) Source #

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.

_FieldRemote :: forall r var. Prism' (Field r var) (SchemaRemoteRelationshipSelect r) Source #

_FieldGraphQL :: forall r var var. Prism (Field r var) (Field r var) (GraphQLField r var) (GraphQLField r var) Source #

fSelectionSet :: forall r var r. Lens (GraphQLField r var) (GraphQLField r var) (SelectionSet r var) (SelectionSet r var) Source #

fName :: forall r var. Lens' (GraphQLField r var) Name Source #

fDirectives :: forall r var. Lens' (GraphQLField r var) [Directive var] Source #

fArguments :: forall r var. Lens' (GraphQLField r var) (HashMap Name (Value var)) Source #

fAlias :: forall r var. Lens' (GraphQLField r var) Name Source #

dssMemberSelectionSets :: forall r var r var. Lens (DeduplicatedSelectionSet r var) (DeduplicatedSelectionSet r var) (HashMap Name (ObjectSelectionSet r var)) (HashMap Name (ObjectSelectionSet r var)) Source #

dssCommonFields :: forall r var. Lens' (DeduplicatedSelectionSet r var) (HashSet Name) Source #