mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 09:51:59 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
85 lines
1.7 KiB
Haskell
85 lines
1.7 KiB
Haskell
module Data.Text.Extended
|
|
( ToTxt (..),
|
|
bquote,
|
|
squote,
|
|
dquote,
|
|
dquoteList,
|
|
commaSeparated,
|
|
paren,
|
|
parenB,
|
|
(<~>),
|
|
(<>>),
|
|
(<<>),
|
|
)
|
|
where
|
|
|
|
import Data.Text as DT
|
|
import Database.ODBC.SQLServer qualified as ODBC
|
|
import Hasura.Prelude
|
|
import Language.GraphQL.Draft.Printer qualified as G
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
|
import Text.Builder qualified as TB
|
|
|
|
class ToTxt a where
|
|
toTxt :: a -> Text
|
|
|
|
instance ToTxt Text where
|
|
toTxt = id
|
|
{-# INLINE toTxt #-}
|
|
|
|
instance ToTxt Char where
|
|
toTxt = DT.singleton
|
|
|
|
instance ToTxt G.Name where
|
|
toTxt = G.unName
|
|
|
|
deriving instance ToTxt G.EnumValue
|
|
|
|
instance ToTxt () where
|
|
toTxt = tshow
|
|
|
|
instance ToTxt Void where
|
|
toTxt = absurd
|
|
|
|
instance ToTxt (G.Value Void) where
|
|
toTxt = TB.run . G.value
|
|
|
|
instance ToTxt ODBC.Query where
|
|
toTxt = ODBC.renderQuery
|
|
|
|
bquote :: ToTxt t => t -> Text
|
|
bquote t = DT.singleton '`' <> toTxt t <> DT.singleton '`'
|
|
|
|
squote :: ToTxt t => t -> Text
|
|
squote t = DT.singleton '\'' <> toTxt t <> DT.singleton '\''
|
|
|
|
dquote :: ToTxt t => t -> Text
|
|
dquote t = DT.singleton '"' <> toTxt t <> DT.singleton '"'
|
|
|
|
paren :: ToTxt t => t -> Text
|
|
paren t = "(" <> toTxt t <> ")"
|
|
|
|
parenB :: TB.Builder -> TB.Builder
|
|
parenB t = TB.char '(' <> t <> TB.char ')'
|
|
|
|
dquoteList :: (ToTxt t, Foldable f) => f t -> Text
|
|
dquoteList = DT.intercalate ", " . fmap dquote . toList
|
|
|
|
commaSeparated :: (ToTxt t, Foldable f) => f t -> Text
|
|
commaSeparated = DT.intercalate ", " . fmap toTxt . toList
|
|
|
|
infixr 6 <>>
|
|
|
|
(<>>) :: ToTxt t => Text -> t -> Text
|
|
(<>>) lTxt a = lTxt <> dquote a
|
|
|
|
infixr 6 <<>
|
|
|
|
(<<>) :: ToTxt t => t -> Text -> Text
|
|
(<<>) a rTxt = dquote a <> rTxt
|
|
|
|
infixr 6 <~>
|
|
|
|
(<~>) :: TB.Builder -> TB.Builder -> TB.Builder
|
|
(<~>) l r = l <> TB.char ' ' <> r
|