{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude #-}

module Data.Morpheus.Client.CodeGen.Interpreting.Local
  ( toLocalDefinitions,
  )
where

import Control.Monad.Except (MonadError (throwError))
import Data.Morpheus.Client.CodeGen.AST
  ( ClientDeclaration,
    ClientPreDeclaration (..),
    ClientTypeDefinition (..),
    RequestTypeDefinition (..),
  )
import Data.Morpheus.Client.CodeGen.Interpreting.Core (Converter (..), compileError, deprecationWarning, getType, toClientDeclarations, toCodeGenField, typeFrom)
import Data.Morpheus.Client.CodeGen.Interpreting.PreDeclarations
  ( mapPreDeclarations,
  )
import Data.Morpheus.CodeGen.Internal.AST (CodeGenConstructor (..), CodeGenTypeName (..), fromTypeName)
import Data.Morpheus.Core (Config (..), VALIDATION_MODE (WITHOUT_VARIABLES), validateRequest)
import Data.Morpheus.Internal.Ext
  ( GQLResult,
  )
import Data.Morpheus.Internal.Utils
  ( empty,
    keyOf,
    selectBy,
  )
import Data.Morpheus.Types.Internal.AST
  ( ANY,
    ExecutableDocument (..),
    FieldDefinition (..),
    FieldName,
    OUT,
    Operation (..),
    RAW,
    Ref (..),
    Schema (..),
    Selection (..),
    SelectionContent (..),
    SelectionSet,
    TRUE,
    TypeContent (..),
    TypeDefinition (..),
    TypeKind (..),
    TypeName,
    TypeRef (..),
    UnionTag (..),
    VALID,
    Variable (..),
    VariableDefinitions,
    getOperationDataType,
    getOperationName,
    mkTypeRef,
    msg,
    toAny,
  )
import qualified Data.Text as T
import Relude hiding (empty, show)
import Prelude (show)

clientConfig :: Config
clientConfig :: Config
clientConfig =
  Config
    { debug :: Bool
debug = Bool
False,
      validationMode :: VALIDATION_MODE
validationMode = VALIDATION_MODE
WITHOUT_VARIABLES
    }

toLocalDefinitions :: (Text, ExecutableDocument) -> Schema VALID -> GQLResult [ClientDeclaration]
toLocalDefinitions :: (Text, ExecutableDocument)
-> Schema VALID -> GQLResult [ClientDeclaration]
toLocalDefinitions (Text
query, ExecutableDocument
request) Schema VALID
schema = do
  Operation VALID
validOperation <- Config
-> Schema VALID
-> ExecutableDocument
-> GQLResult (Operation VALID)
validateRequest Config
clientConfig Schema VALID
schema ExecutableDocument
request
  [ClientPreDeclaration]
x <- forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (Schema VALID
schema, forall (s :: Stage). Operation s -> VariableDefinitions s
operationArguments forall a b. (a -> b) -> a -> b
$ ExecutableDocument -> Operation RAW
operation ExecutableDocument
request) forall a b. (a -> b) -> a -> b
$ forall a.
Converter a
-> ReaderT
     (Schema VALID, VariableDefinitions RAW) (Result GQLError) a
runConverter forall a b. (a -> b) -> a -> b
$ Text -> Operation VALID -> Converter [ClientPreDeclaration]
genLocalDeclarations Text
query Operation VALID
validOperation
  forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall (m :: * -> *).
MonadFail m =>
ClientPreDeclaration -> m ClientDeclaration
mapPreDeclarations [ClientPreDeclaration]
x

genLocalDeclarations :: Text -> Operation VALID -> Converter [ClientPreDeclaration]
genLocalDeclarations :: Text -> Operation VALID -> Converter [ClientPreDeclaration]
genLocalDeclarations Text
query op :: Operation VALID
op@Operation {Maybe FieldName
operationName :: forall (s :: Stage). Operation s -> Maybe FieldName
operationName :: Maybe FieldName
operationName, SelectionSet VALID
operationSelection :: forall (s :: Stage). Operation s -> SelectionSet s
operationSelection :: SelectionSet VALID
operationSelection, OperationType
operationType :: forall (s :: Stage). Operation s -> OperationType
operationType :: OperationType
operationType} = do
  (Schema VALID
schema, VariableDefinitions RAW
varDefs) <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks forall a. a -> a
id
  TypeDefinition OBJECT VALID
datatype <- forall (m :: * -> *) (s :: Stage).
MonadError GQLError m =>
Operation s -> Schema VALID -> m (TypeDefinition OBJECT VALID)
getOperationDataType Operation VALID
op Schema VALID
schema
  let argumentsType :: Maybe ClientTypeDefinition
argumentsType = CodeGenTypeName
-> VariableDefinitions RAW -> Maybe ClientTypeDefinition
toArgumentsType (TypeName -> CodeGenTypeName
fromTypeName forall a b. (a -> b) -> a -> b
$ Maybe FieldName -> TypeName
getOperationName Maybe FieldName
operationName forall a. Semigroup a => a -> a -> a
<> TypeName
"Args") VariableDefinitions RAW
varDefs
  (ClientTypeDefinition
rootType :| [ClientTypeDefinition]
localTypes) <-
    [FieldName]
-> TypeName
-> TypeDefinition ANY VALID
-> SelectionSet VALID
-> Converter (NonEmpty ClientTypeDefinition)
genLocalTypes
      []
      (Maybe FieldName -> TypeName
getOperationName Maybe FieldName
operationName)
      (forall (a :: TypeCategory -> Stage -> *) (k :: TypeCategory)
       (s :: Stage).
ToCategory a k ANY =>
a k s -> a ANY s
toAny TypeDefinition OBJECT VALID
datatype)
      SelectionSet VALID
operationSelection
  forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ( RequestTypeDefinition -> ClientPreDeclaration
RequestTypeClass
        RequestTypeDefinition
          { requestArgs :: TypeName
requestArgs = forall b a. b -> (a -> b) -> Maybe a -> b
maybe TypeName
"()" (CodeGenTypeName -> TypeName
typename forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClientTypeDefinition -> CodeGenTypeName
clientTypeName) Maybe ClientTypeDefinition
argumentsType,
            requestName :: TypeName
requestName = CodeGenTypeName -> TypeName
typename (ClientTypeDefinition -> CodeGenTypeName
clientTypeName ClientTypeDefinition
rootType),
            requestType :: OperationType
requestType = OperationType
operationType,
            requestQuery :: String
requestQuery = Text -> String
T.unpack Text
query
          }
        forall a. a -> [a] -> [a]
: forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ClientTypeDefinition -> [ClientPreDeclaration]
toClientDeclarations (ClientTypeDefinition
rootType forall a. a -> [a] -> [a]
: ([ClientTypeDefinition]
localTypes forall a. Semigroup a => a -> a -> a
<> forall a. Maybe a -> [a]
maybeToList Maybe ClientTypeDefinition
argumentsType))
    )

-------------------------------------------------------------------------
-- generates selection Object Types
genLocalTypes ::
  [FieldName] ->
  TypeName ->
  TypeDefinition ANY VALID ->
  SelectionSet VALID ->
  Converter (NonEmpty ClientTypeDefinition)
genLocalTypes :: [FieldName]
-> TypeName
-> TypeDefinition ANY VALID
-> SelectionSet VALID
-> Converter (NonEmpty ClientTypeDefinition)
genLocalTypes [FieldName]
namespace TypeName
tName TypeDefinition ANY VALID
dataType SelectionSet VALID
recordSelSet = do
  let clientTypeName :: CodeGenTypeName
clientTypeName = CodeGenTypeName {[FieldName]
namespace :: [FieldName]
namespace :: [FieldName]
namespace, typeParameters :: [Text]
typeParameters = [], typename :: TypeName
typename = TypeName
tName}
  (CodeGenConstructor
con, [ClientTypeDefinition]
subTypes) <- [FieldName]
-> CodeGenTypeName
-> TypeDefinition ANY VALID
-> SelectionSet VALID
-> Converter (CodeGenConstructor, [ClientTypeDefinition])
toConstructorDefinition (if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FieldName]
namespace then [coerce :: forall a b. Coercible a b => a -> b
coerce TypeName
tName] else [FieldName]
namespace) CodeGenTypeName
clientTypeName TypeDefinition ANY VALID
dataType SelectionSet VALID
recordSelSet
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
    ClientTypeDefinition
      { CodeGenTypeName
clientTypeName :: CodeGenTypeName
clientTypeName :: CodeGenTypeName
clientTypeName,
        clientCons :: [CodeGenConstructor]
clientCons = [CodeGenConstructor
con],
        clientKind :: TypeKind
clientKind = Maybe OperationType -> TypeKind
KindObject forall a. Maybe a
Nothing
      }
      forall a. a -> [a] -> NonEmpty a
:| [ClientTypeDefinition]
subTypes

toConstructorDefinition ::
  [FieldName] ->
  CodeGenTypeName ->
  TypeDefinition ANY VALID ->
  SelectionSet VALID ->
  Converter (CodeGenConstructor, [ClientTypeDefinition])
toConstructorDefinition :: [FieldName]
-> CodeGenTypeName
-> TypeDefinition ANY VALID
-> SelectionSet VALID
-> Converter (CodeGenConstructor, [ClientTypeDefinition])
toConstructorDefinition [FieldName]
path CodeGenTypeName
name TypeDefinition ANY VALID
datatype SelectionSet VALID
selSet = do
  ([FieldDefinition ANY VALID]
fields, [[ClientTypeDefinition]]
subTypes) <- forall a b. [(a, b)] -> ([a], [b])
unzip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Selection VALID
-> Converter (FieldDefinition ANY VALID, [ClientTypeDefinition])
genField (forall (t :: * -> *) a. Foldable t => t a -> [a]
toList SelectionSet VALID
selSet)
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (CodeGenConstructor {constructorName :: CodeGenTypeName
constructorName = CodeGenTypeName
name, constructorFields :: [CodeGenField]
constructorFields = forall a b. (a -> b) -> [a] -> [b]
map forall (a :: TypeCategory) (b :: Stage).
FieldDefinition a b -> CodeGenField
toCodeGenField [FieldDefinition ANY VALID]
fields}, forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ClientTypeDefinition]]
subTypes)
  where
    genField :: Selection VALID -> Converter (FieldDefinition ANY VALID, [ClientTypeDefinition])
    genField :: Selection VALID
-> Converter (FieldDefinition ANY VALID, [ClientTypeDefinition])
genField Selection VALID
sel = do
      let fieldName :: FieldName
fieldName = forall k a. KeyOf k a => a -> k
keyOf Selection VALID
sel
      let fieldPath :: [FieldName]
fieldPath = [FieldName]
path forall a. Semigroup a => a -> a -> a
<> [FieldName
fieldName]
      (TypeDefinition ANY VALID
fieldDataType, TypeRef
fieldType) <- [FieldName]
-> TypeDefinition ANY VALID
-> Selection VALID
-> Converter (TypeDefinition ANY VALID, TypeRef)
getFieldType [FieldName]
fieldPath TypeDefinition ANY VALID
datatype Selection VALID
sel
      [ClientTypeDefinition]
subTypes <- [FieldName]
-> TypeDefinition ANY VALID
-> Selection VALID
-> Converter [ClientTypeDefinition]
subTypesBySelection [FieldName]
fieldPath TypeDefinition ANY VALID
fieldDataType Selection VALID
sel
      forall (f :: * -> *) a. Applicative f => a -> f a
pure
        ( FieldDefinition
            { FieldName
fieldName :: FieldName
fieldName :: FieldName
fieldName,
              TypeRef
fieldType :: TypeRef
fieldType :: TypeRef
fieldType,
              fieldContent :: Maybe (FieldContent TRUE ANY VALID)
fieldContent = forall a. Maybe a
Nothing,
              fieldDescription :: Maybe Text
fieldDescription = forall a. Maybe a
Nothing,
              fieldDirectives :: Directives VALID
fieldDirectives = forall coll. Empty coll => coll
empty
            },
          [ClientTypeDefinition]
subTypes
        )

------------------------------------------
subTypesBySelection ::
  [FieldName] ->
  TypeDefinition ANY VALID ->
  Selection VALID ->
  Converter [ClientTypeDefinition]
subTypesBySelection :: [FieldName]
-> TypeDefinition ANY VALID
-> Selection VALID
-> Converter [ClientTypeDefinition]
subTypesBySelection [FieldName]
_ TypeDefinition ANY VALID
_ Selection {selectionContent :: forall (s :: Stage). Selection s -> SelectionContent s
selectionContent = SelectionContent VALID
SelectionField} = forall (f :: * -> *) a. Applicative f => a -> f a
pure []
subTypesBySelection [FieldName]
path TypeDefinition ANY VALID
dType Selection {selectionContent :: forall (s :: Stage). Selection s -> SelectionContent s
selectionContent = SelectionSet SelectionSet VALID
selectionSet} =
  forall (t :: * -> *) a. Foldable t => t a -> [a]
toList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FieldName]
-> TypeName
-> TypeDefinition ANY VALID
-> SelectionSet VALID
-> Converter (NonEmpty ClientTypeDefinition)
genLocalTypes [FieldName]
path (forall (a :: TypeCategory).
[FieldName] -> TypeDefinition a VALID -> TypeName
typeFrom [] TypeDefinition ANY VALID
dType) TypeDefinition ANY VALID
dType SelectionSet VALID
selectionSet
subTypesBySelection [FieldName]
namespace TypeDefinition ANY VALID
dType Selection {selectionContent :: forall (s :: Stage). Selection s -> SelectionContent s
selectionContent = UnionSelection SelectionSet VALID
interface UnionSelection VALID
unionSelections} =
  do
    let variants :: [UnionTag]
variants = TypeName -> SelectionSet VALID -> UnionTag
UnionTag (forall (a :: TypeCategory) (s :: Stage).
TypeDefinition a s -> TypeName
typeName TypeDefinition ANY VALID
dType) SelectionSet VALID
interface forall a. a -> [a] -> [a]
: forall (t :: * -> *) a. Foldable t => t a -> [a]
toList UnionSelection VALID
unionSelections
    ([CodeGenConstructor]
clientCons, [[ClientTypeDefinition]]
subTypes) <- forall a b. [(a, b)] -> ([a], [b])
unzip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ([FieldName]
-> UnionTag
-> Converter (CodeGenConstructor, [ClientTypeDefinition])
getVariantType [FieldName]
namespace) [UnionTag]
variants
    forall (f :: * -> *) a. Applicative f => a -> f a
pure
      ( ClientTypeDefinition
          { clientTypeName :: CodeGenTypeName
clientTypeName = CodeGenTypeName {[FieldName]
namespace :: [FieldName]
namespace :: [FieldName]
namespace, typeParameters :: [Text]
typeParameters = [], typename :: TypeName
typename = forall (a :: TypeCategory).
[FieldName] -> TypeDefinition a VALID -> TypeName
typeFrom [] TypeDefinition ANY VALID
dType},
            [CodeGenConstructor]
clientCons :: [CodeGenConstructor]
clientCons :: [CodeGenConstructor]
clientCons,
            clientKind :: TypeKind
clientKind = TypeKind
KindUnion
          }
          forall a. a -> [a] -> [a]
: forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ClientTypeDefinition]]
subTypes
      )

getVariantType :: [FieldName] -> UnionTag -> Converter (CodeGenConstructor, [ClientTypeDefinition])
getVariantType :: [FieldName]
-> UnionTag
-> Converter (CodeGenConstructor, [ClientTypeDefinition])
getVariantType [FieldName]
path (UnionTag TypeName
selectedTyName SelectionSet VALID
selectionVariant) = do
  TypeDefinition ANY VALID
conDatatype <- TypeName -> Converter (TypeDefinition ANY VALID)
getType TypeName
selectedTyName
  [FieldName]
-> CodeGenTypeName
-> TypeDefinition ANY VALID
-> SelectionSet VALID
-> Converter (CodeGenConstructor, [ClientTypeDefinition])
toConstructorDefinition [FieldName]
path ([FieldName] -> [Text] -> TypeName -> CodeGenTypeName
CodeGenTypeName [FieldName]
path [] TypeName
selectedTyName) TypeDefinition ANY VALID
conDatatype SelectionSet VALID
selectionVariant

getFieldType ::
  [FieldName] ->
  TypeDefinition ANY VALID ->
  Selection VALID ->
  Converter (TypeDefinition ANY VALID, TypeRef)
getFieldType :: [FieldName]
-> TypeDefinition ANY VALID
-> Selection VALID
-> Converter (TypeDefinition ANY VALID, TypeRef)
getFieldType
  [FieldName]
path
  TypeDefinition {TypeContent TRUE ANY VALID
typeContent :: forall (a :: TypeCategory) (s :: Stage).
TypeDefinition a s -> TypeContent TRUE a s
typeContent :: TypeContent TRUE ANY VALID
typeContent, TypeName
typeName :: TypeName
typeName :: forall (a :: TypeCategory) (s :: Stage).
TypeDefinition a s -> TypeName
typeName}
  Selection
    { FieldName
selectionName :: forall (s :: Stage). Selection s -> FieldName
selectionName :: FieldName
selectionName,
      Position
selectionPosition :: forall (s :: Stage). Selection s -> Position
selectionPosition :: Position
selectionPosition
    } = TypeContent TRUE ANY VALID -> Converter (FieldDefinition OUT VALID)
toFieldDef TypeContent TRUE ANY VALID
typeContent forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FieldDefinition OUT VALID
-> Converter (TypeDefinition ANY VALID, TypeRef)
processFieldDefinition
    where
      toFieldDef :: TypeContent TRUE ANY VALID -> Converter (FieldDefinition OUT VALID)
      toFieldDef :: TypeContent TRUE ANY VALID -> Converter (FieldDefinition OUT VALID)
toFieldDef TypeContent TRUE ANY VALID
_
        | FieldName
selectionName forall a. Eq a => a -> a -> Bool
== FieldName
"__typename" =
            forall (f :: * -> *) a. Applicative f => a -> f a
pure
              FieldDefinition
                { fieldName :: FieldName
fieldName = FieldName
"__typename",
                  fieldDescription :: Maybe Text
fieldDescription = forall a. Maybe a
Nothing,
                  fieldType :: TypeRef
fieldType = TypeName -> TypeRef
mkTypeRef TypeName
"String",
                  fieldDirectives :: Directives VALID
fieldDirectives = forall coll. Empty coll => coll
empty,
                  fieldContent :: Maybe (FieldContent TRUE OUT VALID)
fieldContent = forall a. Maybe a
Nothing
                }
      toFieldDef DataObject {FieldsDefinition OUT VALID
objectFields :: forall (s :: Stage) (a :: TypeCategory).
CondTypeContent OBJECT a s -> FieldsDefinition OUT s
objectFields :: FieldsDefinition OUT VALID
objectFields} = forall e (m :: * -> *) k (c :: * -> *) a.
(MonadError e m, IsMap k c, Monad m) =>
e -> k -> c a -> m a
selectBy GQLError
selError FieldName
selectionName FieldsDefinition OUT VALID
objectFields
      toFieldDef DataInterface {FieldsDefinition OUT VALID
interfaceFields :: forall (s :: Stage) (a :: TypeCategory).
CondTypeContent IMPLEMENTABLE a s -> FieldsDefinition OUT s
interfaceFields :: FieldsDefinition OUT VALID
interfaceFields} = forall e (m :: * -> *) k (c :: * -> *) a.
(MonadError e m, IsMap k c, Monad m) =>
e -> k -> c a -> m a
selectBy GQLError
selError FieldName
selectionName FieldsDefinition OUT VALID
interfaceFields
      toFieldDef TypeContent TRUE ANY VALID
dt = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (GQLError -> GQLError
compileError forall a b. (a -> b) -> a -> b
$ GQLError
"Type should be output Object \"" forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg (forall a. Show a => a -> String
show TypeContent TRUE ANY VALID
dt))
      selError :: GQLError
selError = GQLError -> GQLError
compileError forall a b. (a -> b) -> a -> b
$ GQLError
"can't find field " forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg FieldName
selectionName forall a. Semigroup a => a -> a -> a
<> GQLError
" on type: " forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg (forall a. Show a => a -> String
show TypeContent TRUE ANY VALID
typeContent)
      --
      processFieldDefinition :: FieldDefinition OUT VALID
-> Converter (TypeDefinition ANY VALID, TypeRef)
processFieldDefinition
        FieldDefinition
          { fieldType :: forall (cat :: TypeCategory) (s :: Stage).
FieldDefinition cat s -> TypeRef
fieldType = TypeRef {TypeWrapper
TypeName
typeConName :: TypeRef -> TypeName
typeWrappers :: TypeRef -> TypeWrapper
typeWrappers :: TypeWrapper
typeConName :: TypeName
..},
            Directives VALID
fieldDirectives :: Directives VALID
fieldDirectives :: forall (cat :: TypeCategory) (s :: Stage).
FieldDefinition cat s -> Directives s
fieldDirectives
          } =
          Converter ()
checkDeprecated forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (TypeDefinition ANY VALID -> (TypeDefinition ANY VALID, TypeRef)
trans forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TypeName -> Converter (TypeDefinition ANY VALID)
getType TypeName
typeConName)
          where
            trans :: TypeDefinition ANY VALID -> (TypeDefinition ANY VALID, TypeRef)
trans TypeDefinition ANY VALID
x = (TypeDefinition ANY VALID
x, TypeRef {typeConName :: TypeName
typeConName = forall (a :: TypeCategory).
[FieldName] -> TypeDefinition a VALID -> TypeName
typeFrom [FieldName]
path TypeDefinition ANY VALID
x, TypeWrapper
typeWrappers :: TypeWrapper
typeWrappers :: TypeWrapper
..})
            ------------------------------------------------------------------
            checkDeprecated :: Converter ()
            checkDeprecated :: Converter ()
checkDeprecated = Directives VALID -> (FieldName, Ref FieldName) -> Converter ()
deprecationWarning Directives VALID
fieldDirectives (coerce :: forall a b. Coercible a b => a -> b
coerce TypeName
typeName, forall name. name -> Position -> Ref name
Ref FieldName
selectionName Position
selectionPosition)

toArgumentsType ::
  CodeGenTypeName ->
  VariableDefinitions RAW ->
  Maybe ClientTypeDefinition
toArgumentsType :: CodeGenTypeName
-> VariableDefinitions RAW -> Maybe ClientTypeDefinition
toArgumentsType CodeGenTypeName
clientTypeName VariableDefinitions RAW
variables
  | forall (t :: * -> *) a. Foldable t => t a -> Bool
null VariableDefinitions RAW
variables = forall a. Maybe a
Nothing
  | Bool
otherwise =
      forall a. a -> Maybe a
Just
        ClientTypeDefinition
          { CodeGenTypeName
clientTypeName :: CodeGenTypeName
clientTypeName :: CodeGenTypeName
clientTypeName,
            clientKind :: TypeKind
clientKind = TypeKind
KindInputObject,
            clientCons :: [CodeGenConstructor]
clientCons =
              [ CodeGenConstructor
                  { constructorName :: CodeGenTypeName
constructorName = CodeGenTypeName
clientTypeName,
                    constructorFields :: [CodeGenField]
constructorFields = forall (a :: TypeCategory) (b :: Stage).
FieldDefinition a b -> CodeGenField
toCodeGenField forall b c a. (b -> c) -> (a -> b) -> a -> c
. Variable RAW -> FieldDefinition ANY VALID
toFieldDefinition forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) a. Foldable t => t a -> [a]
toList VariableDefinitions RAW
variables
                  }
              ]
          }

toFieldDefinition :: Variable RAW -> FieldDefinition ANY VALID
toFieldDefinition :: Variable RAW -> FieldDefinition ANY VALID
toFieldDefinition Variable {FieldName
variableName :: forall (stage :: Stage). Variable stage -> FieldName
variableName :: FieldName
variableName, TypeRef
variableType :: forall (stage :: Stage). Variable stage -> TypeRef
variableType :: TypeRef
variableType} =
  FieldDefinition
    { fieldName :: FieldName
fieldName = FieldName
variableName,
      fieldContent :: Maybe (FieldContent TRUE ANY VALID)
fieldContent = forall a. Maybe a
Nothing,
      fieldType :: TypeRef
fieldType = TypeRef
variableType,
      fieldDescription :: Maybe Text
fieldDescription = forall a. Maybe a
Nothing,
      fieldDirectives :: Directives VALID
fieldDirectives = forall coll. Empty coll => coll
empty
    }