From 5e17f33f7fa255f67dba3c8448a0475c0bf94a10 Mon Sep 17 00:00:00 2001 From: Rory Campbell Date: Thu, 7 Dec 2023 19:31:45 +0530 Subject: [PATCH] format --- src/GraphQL/Client/Alias.purs | 3 +- src/GraphQL/Client/Alias/Dynamic.purs | 6 +- src/GraphQL/Client/Args.purs | 2 +- src/GraphQL/Client/Args/AllowedMismatch.purs | 3 - .../Client/BaseClients/Affjax/Internal.purs | 21 ++-- .../Client/BaseClients/Affjax/Node.purs | 7 +- .../Client/BaseClients/Affjax/Web.purs | 7 +- .../BaseClients/Apollo/ErrorPolicy.purs | 2 +- .../BaseClients/Apollo/FetchPolicy.purs | 3 +- src/GraphQL/Client/BaseClients/Urql.purs | 100 ++++++++++-------- src/GraphQL/Client/Directive/Definition.purs | 13 ++- src/GraphQL/Client/Directive/Location.purs | 10 +- src/GraphQL/Client/ErrorBoundary.purs | 3 +- src/GraphQL/Client/GqlError.purs | 1 - src/GraphQL/Client/ID.purs | 4 +- src/GraphQL/Client/NullArray.purs | 1 - src/GraphQL/Client/Operation.purs | 11 +- src/GraphQL/Client/Union.purs | 18 +++- src/GraphQL/Client/Variable.purs | 4 +- src/GraphQL/Hasura/ComparisonExp.purs | 2 +- src/GraphQL/Hasura/Decode.purs | 76 +++++++------ src/GraphQL/Hasura/DecodeLiberal.purs | 3 +- src/GraphQL/Hasura/Encode.purs | 3 +- 23 files changed, 148 insertions(+), 155 deletions(-) diff --git a/src/GraphQL/Client/Alias.purs b/src/GraphQL/Client/Alias.purs index 5777c2c8..15ae967c 100644 --- a/src/GraphQL/Client/Alias.purs +++ b/src/GraphQL/Client/Alias.purs @@ -1,6 +1,5 @@ module GraphQL.Client.Alias where -data Alias al t - = Alias al t +data Alias al t = Alias al t infixr 6 Alias as : diff --git a/src/GraphQL/Client/Alias/Dynamic.purs b/src/GraphQL/Client/Alias/Dynamic.purs index 73eceaa0..942bdcbb 100644 --- a/src/GraphQL/Client/Alias/Dynamic.purs +++ b/src/GraphQL/Client/Alias/Dynamic.purs @@ -27,13 +27,11 @@ import GraphQL.Hasura.Encode (class EncodeHasura, encodeHasura) -- | _3: update_users(where: {id : 3}, _set: { value: 20 }) { affected_rows } -- | } -- | ``` -data Spread alias args fields - = Spread alias (Array args) fields +data Spread alias args fields = Spread alias (Array args) fields -- | The return type of a query made with a dynamic alias spread -- | This type has encodes/decodes as an object with "_n" as a key -newtype SpreadRes a - = SpreadRes (Array a) +newtype SpreadRes a = SpreadRes (Array a) derive instance genericSpreadRes :: Generic (SpreadRes a) _ diff --git a/src/GraphQL/Client/Args.purs b/src/GraphQL/Client/Args.purs index 77ca4513..e2bfc742 100644 --- a/src/GraphQL/Client/Args.purs +++ b/src/GraphQL/Client/Args.purs @@ -81,7 +81,7 @@ else instance argToGqlArray :: ArgGqlAt at param arg => ArgGqlAt at (Array param else instance argToGqlArrayOne :: ArgGqlAt at param arg => ArgGqlAt at (Array param) arg else instance argToGqlRecord :: RecordArg p a u => ArgGqlAt at { | p } { | a } else instance allowedArgMismatchSame :: ArgGqlAt at p (AllowedMismatch p a) -else instance allowedArgMismatchNested :: ArgGqlAt at p a => ArgGqlAt at p (AllowedMismatch schema a) +else instance allowedArgMismatchNested :: ArgGqlAt at p a => ArgGqlAt at p (AllowedMismatch schema a) else instance argGqlIdentity :: ArgGqlAt at a a else instance argToGqlNewtypeRecord :: (Newtype n { | p }, RecordArg p a u) => ArgGqlAt at n { | a } else instance argMismatch :: diff --git a/src/GraphQL/Client/Args/AllowedMismatch.purs b/src/GraphQL/Client/Args/AllowedMismatch.purs index 11b82b7a..718018b2 100644 --- a/src/GraphQL/Client/Args/AllowedMismatch.purs +++ b/src/GraphQL/Client/Args/AllowedMismatch.purs @@ -8,12 +8,10 @@ import Data.Newtype (class Newtype) import GraphQL.Hasura.Decode (class DecodeHasura) import GraphQL.Hasura.Encode (class EncodeHasura) - -- | Allow a type does not match the schema to be used in a query as an argument. newtype AllowedMismatch :: forall k. k -> Type -> Type newtype AllowedMismatch schemaType arg = AllowedMismatch arg - derive instance Newtype (AllowedMismatch schemaType arg) _ derive newtype instance DecodeJson arg => DecodeJson (AllowedMismatch schemaType arg) @@ -22,4 +20,3 @@ derive newtype instance DecodeHasura arg => DecodeHasura (AllowedMismatch schema derive newtype instance EncodeHasura arg => EncodeHasura (AllowedMismatch schemaType arg) derive newtype instance Eq arg => Eq (AllowedMismatch schemaType arg) - diff --git a/src/GraphQL/Client/BaseClients/Affjax/Internal.purs b/src/GraphQL/Client/BaseClients/Affjax/Internal.purs index 0a06c0b7..de8e3d19 100644 --- a/src/GraphQL/Client/BaseClients/Affjax/Internal.purs +++ b/src/GraphQL/Client/BaseClients/Affjax/Internal.purs @@ -2,7 +2,6 @@ module GraphQL.Client.BaseClients.Affjax.Internal where import Prelude - import Affjax (Error, Request, URL, defaultRequest, printError) import Affjax.RequestBody as RequestBody import Affjax.RequestHeader (RequestHeader(..)) @@ -20,15 +19,15 @@ throwLeft = case _ of Left err -> throwError $ error $ printError err Right { body } -> pure body -makeAffjaxGqlRequest :: - String -> URL -> Array RequestHeader -> String -> String -> Json -> Request Json +makeAffjaxGqlRequest + :: String -> URL -> Array RequestHeader -> String -> String -> Json -> Request Json makeAffjaxGqlRequest opStr url headers queryName q vars = - defaultRequest - { withCredentials = true - , url = url - , method = Left Method.POST - , responseFormat = ResponseFormat.json - , content = + defaultRequest + { withCredentials = true + , url = url + , method = Left Method.POST + , responseFormat = ResponseFormat.json + , content = Just $ RequestBody.Json $ encodeJson @@ -36,5 +35,5 @@ makeAffjaxGqlRequest opStr url headers queryName q vars = , variables: vars , operationName: queryName } - , headers = headers <> [ ContentType applicationJSON ] - } + , headers = headers <> [ ContentType applicationJSON ] + } diff --git a/src/GraphQL/Client/BaseClients/Affjax/Node.purs b/src/GraphQL/Client/BaseClients/Affjax/Node.purs index 92d6defb..35634fa4 100644 --- a/src/GraphQL/Client/BaseClients/Affjax/Node.purs +++ b/src/GraphQL/Client/BaseClients/Affjax/Node.purs @@ -10,8 +10,7 @@ import Effect.Aff (Aff) import GraphQL.Client.BaseClients.Affjax.Internal (makeAffjaxGqlRequest, throwLeft) import GraphQL.Client.Types (class QueryClient) -data AffjaxNodeClient - = AffjaxNodeClient URL (Array RequestHeader) +data AffjaxNodeClient = AffjaxNodeClient URL (Array RequestHeader) instance queryClient :: QueryClient AffjaxNodeClient Unit Unit where clientQuery _ (AffjaxNodeClient url headers) name q vars = throwLeft =<< queryPostForeign "query" url headers name q vars @@ -19,7 +18,7 @@ instance queryClient :: QueryClient AffjaxNodeClient Unit Unit where defQueryOpts = const unit defMutationOpts = const unit -queryPostForeign :: - String -> URL -> Array RequestHeader -> String -> String -> Json -> Aff (Either Error (Response Json)) +queryPostForeign + :: String -> URL -> Array RequestHeader -> String -> String -> Json -> Aff (Either Error (Response Json)) queryPostForeign opStr url headers queryName q vars = request (makeAffjaxGqlRequest opStr url headers queryName q vars) \ No newline at end of file diff --git a/src/GraphQL/Client/BaseClients/Affjax/Web.purs b/src/GraphQL/Client/BaseClients/Affjax/Web.purs index 98933cff..0e09837a 100644 --- a/src/GraphQL/Client/BaseClients/Affjax/Web.purs +++ b/src/GraphQL/Client/BaseClients/Affjax/Web.purs @@ -10,8 +10,7 @@ import Effect.Aff (Aff) import GraphQL.Client.BaseClients.Affjax.Internal (makeAffjaxGqlRequest, throwLeft) import GraphQL.Client.Types (class QueryClient) -data AffjaxWebClient - = AffjaxWebClient URL (Array RequestHeader) +data AffjaxWebClient = AffjaxWebClient URL (Array RequestHeader) instance queryClient :: QueryClient AffjaxWebClient Unit Unit where clientQuery _ (AffjaxWebClient url headers) name q vars = throwLeft =<< queryPostForeign "query" url headers name q vars @@ -19,7 +18,7 @@ instance queryClient :: QueryClient AffjaxWebClient Unit Unit where defQueryOpts = const unit defMutationOpts = const unit -queryPostForeign :: - String -> URL -> Array RequestHeader -> String -> String -> Json -> Aff (Either Error (Response Json)) +queryPostForeign + :: String -> URL -> Array RequestHeader -> String -> String -> Json -> Aff (Either Error (Response Json)) queryPostForeign opStr url headers queryName q vars = request (makeAffjaxGqlRequest opStr url headers queryName q vars) \ No newline at end of file diff --git a/src/GraphQL/Client/BaseClients/Apollo/ErrorPolicy.purs b/src/GraphQL/Client/BaseClients/Apollo/ErrorPolicy.purs index 150679f8..2eb3d094 100644 --- a/src/GraphQL/Client/BaseClients/Apollo/ErrorPolicy.purs +++ b/src/GraphQL/Client/BaseClients/Apollo/ErrorPolicy.purs @@ -11,7 +11,7 @@ data ErrorPolicy derive instance eqErrorPolicy :: Eq ErrorPolicy -instance encodeJsonErrorPolicy :: EncodeJson ErrorPolicy where +instance encodeJsonErrorPolicy :: EncodeJson ErrorPolicy where encodeJson = errorPolicyToForeign >>> encodeJson errorPolicyToForeign :: ErrorPolicy -> String diff --git a/src/GraphQL/Client/BaseClients/Apollo/FetchPolicy.purs b/src/GraphQL/Client/BaseClients/Apollo/FetchPolicy.purs index 41d4f47b..a411a139 100644 --- a/src/GraphQL/Client/BaseClients/Apollo/FetchPolicy.purs +++ b/src/GraphQL/Client/BaseClients/Apollo/FetchPolicy.purs @@ -4,7 +4,6 @@ import Prelude import Data.Argonaut.Encode (class EncodeJson, encodeJson) - data FetchPolicy = CacheFirst | CacheOnly @@ -15,7 +14,7 @@ data FetchPolicy derive instance eqFetchPolicy :: Eq FetchPolicy -instance encodeJsonFetchPolicy :: EncodeJson FetchPolicy where +instance encodeJsonFetchPolicy :: EncodeJson FetchPolicy where encodeJson = fetchPolicyToForeign >>> encodeJson fetchPolicyToForeign :: FetchPolicy -> String diff --git a/src/GraphQL/Client/BaseClients/Urql.purs b/src/GraphQL/Client/BaseClients/Urql.purs index 0aebc37b..84eaac0e 100644 --- a/src/GraphQL/Client/BaseClients/Urql.purs +++ b/src/GraphQL/Client/BaseClients/Urql.purs @@ -23,16 +23,16 @@ import Foreign.Object (Object) import Foreign.Object as Object import GraphQL.Client.Types (class QueryClient, class SubscriptionClient, Client(..)) -type UrqlClientOptions - = { url :: URL - , headers :: Array RequestHeader - } +type UrqlClientOptions = + { url :: URL + , headers :: Array RequestHeader + } -type UrqlSubClientOptions - = { url :: URL - , websocketUrl :: URL - , headers :: Array RequestHeader - } +type UrqlSubClientOptions = + { url :: URL + , websocketUrl :: URL + , headers :: Array RequestHeader + } -- | A client to make graphQL queries and mutations. -- | From the @urql/core npm module @@ -45,30 +45,32 @@ foreign import data UrqlClient :: Type -- | See https://github.com/enisdenjo/graphql-ws details foreign import data UrqlSubClient :: Type -createClient :: - forall schema. - UrqlClientOptions -> Effect (Client UrqlClient schema) +createClient + :: forall schema + . UrqlClientOptions + -> Effect (Client UrqlClient schema) createClient = clientOptsToForeign >>> createClientImpl >>> map Client -createGlobalClientUnsafe :: - forall schema. - UrqlClientOptions -> Effect (Client UrqlClient schema) +createGlobalClientUnsafe + :: forall schema + . UrqlClientOptions + -> Effect (Client UrqlClient schema) createGlobalClientUnsafe = clientOptsToForeign >>> createGlobalClientUnsafeImpl >>> map Client -createSubscriptionClient :: - forall schema. - UrqlSubClientOptions -> - Effect (Client UrqlSubClient schema) +createSubscriptionClient + :: forall schema + . UrqlSubClientOptions + -> Effect (Client UrqlSubClient schema) createSubscriptionClient = clientOptsToForeign >>> createSubscriptionClientImpl >>> map Client -clientOptsToForeign :: - forall r. - { headers :: Array RequestHeader - | r - } -> - { headers :: Object String - | r - } +clientOptsToForeign + :: forall r + . { headers :: Array RequestHeader + | r + } + -> { headers :: Object String + | r + } clientOptsToForeign opts = opts { headers = Object.fromFoldable $ map toTup opts.headers @@ -76,16 +78,16 @@ clientOptsToForeign opts = where toTup header = Tuple (name header) (value header) -type UrqlClientOptionsForeign - = { url :: URL - , headers :: Object String - } +type UrqlClientOptionsForeign = + { url :: URL + , headers :: Object String + } -type UrqlSubUrqlClientOptionsForeign - = { url :: URL - , websocketUrl :: URL - , headers :: Object String - } +type UrqlSubUrqlClientOptionsForeign = + { url :: URL + , websocketUrl :: URL + , headers :: Object String + } foreign import createClientImpl :: UrqlClientOptionsForeign -> Effect UrqlClient @@ -105,10 +107,15 @@ instance queryClientSubscription :: QueryClient UrqlSubClient Unit Unit where defQueryOpts = const unit defMutationOpts = const unit -queryForeign :: - forall client o. - QueryClient client o o => - Boolean -> client -> String -> String -> Json -> Aff Json +queryForeign + :: forall client o + . QueryClient client o o + => Boolean + -> client + -> String + -> String + -> Json + -> Aff Json queryForeign isMutation client name q_ vars = fromEffectFnAff $ fn (unsafeToForeign client) q vars where fn = if isMutation then mutationImpl else queryImpl @@ -124,9 +131,10 @@ foreign import mutationImpl :: Foreign -> String -> Json -> EffectFnAff Json instance subcriptionClient :: SubscriptionClient UrqlSubClient Unit where clientSubscription _ = subscriptionImpl defSubOpts _ = unit -foreign import subscriptionImpl :: - UrqlSubClient -> - String -> - Json -> - (Json -> Effect Unit) -> - Effect (Effect Unit) + +foreign import subscriptionImpl + :: UrqlSubClient + -> String + -> Json + -> (Json -> Effect Unit) + -> Effect (Effect Unit) diff --git a/src/GraphQL/Client/Directive/Definition.purs b/src/GraphQL/Client/Directive/Definition.purs index 928ba14d..3f28644a 100644 --- a/src/GraphQL/Client/Directive/Definition.purs +++ b/src/GraphQL/Client/Directive/Definition.purs @@ -4,12 +4,11 @@ import Data.Symbol (class IsSymbol) -- | A directive definition data Directive :: forall k1 k2 k3 k4. k1 -> k2 -> k3 -> k4 -> Type -data Directive name description arguments locations - = Directive +data Directive name description arguments locations = Directive -directive :: - forall name description arguments location. - IsSymbol name => - Directive name description { | arguments } location +directive + :: forall name description arguments location + . IsSymbol name + => Directive name description { | arguments } location directive = - Directive + Directive diff --git a/src/GraphQL/Client/Directive/Location.purs b/src/GraphQL/Client/Directive/Location.purs index 53d14c16..4a07d068 100644 --- a/src/GraphQL/Client/Directive/Location.purs +++ b/src/GraphQL/Client/Directive/Location.purs @@ -1,20 +1,16 @@ module GraphQL.Client.Directive.Location where - class ExecutableDirectiveLocation :: forall k. k -> Constraint class ExecutableDirectiveLocation a -data QUERY - = QUERY +data QUERY = QUERY instance executableDirectiveLocationQUERY :: ExecutableDirectiveLocation QUERY -data MUTATION - = MUTATION +data MUTATION = MUTATION instance executableDirectiveLocationMUTATION :: ExecutableDirectiveLocation MUTATION -data SUBSCRIPTION - = SUBSCRIPTION +data SUBSCRIPTION = SUBSCRIPTION instance executableDirectiveLocationSUBSCRIPTION :: ExecutableDirectiveLocation SUBSCRIPTION diff --git a/src/GraphQL/Client/ErrorBoundary.purs b/src/GraphQL/Client/ErrorBoundary.purs index 1205ffec..ced59603 100644 --- a/src/GraphQL/Client/ErrorBoundary.purs +++ b/src/GraphQL/Client/ErrorBoundary.purs @@ -7,8 +7,7 @@ module GraphQL.Client.ErrorBoundary , putErrorsInPaths , putErrorsInPathsImpl , toEither - ) - where + ) where import Prelude diff --git a/src/GraphQL/Client/GqlError.purs b/src/GraphQL/Client/GqlError.purs index 93c668c7..fc8dc969 100644 --- a/src/GraphQL/Client/GqlError.purs +++ b/src/GraphQL/Client/GqlError.purs @@ -5,7 +5,6 @@ import Data.Either (Either) import Data.Maybe (Maybe) import Foreign.Object (Object) - type GqlError = { message :: String , locations :: ErrorLocations diff --git a/src/GraphQL/Client/ID.purs b/src/GraphQL/Client/ID.purs index 51dcb39a..d14e825f 100644 --- a/src/GraphQL/Client/ID.purs +++ b/src/GraphQL/Client/ID.purs @@ -13,10 +13,10 @@ import GraphQL.Hasura.Encode (class EncodeHasura) newtype ID = ID String derive instance eqID :: Eq ID -derive instance ordID :: Ord ID +derive instance ordID :: Ord ID derive instance newtypeID :: Newtype ID _ derive instance genericID :: Generic ID _ -derive newtype instance showID :: Show ID +derive newtype instance showID :: Show ID derive newtype instance gqlArgStringID :: GqlArgString ID derive newtype instance decodeHasuraID :: DecodeHasura ID derive newtype instance encodeHasuraID :: EncodeHasura ID diff --git a/src/GraphQL/Client/NullArray.purs b/src/GraphQL/Client/NullArray.purs index 5e31c8d3..24af6252 100644 --- a/src/GraphQL/Client/NullArray.purs +++ b/src/GraphQL/Client/NullArray.purs @@ -1,5 +1,4 @@ module GraphQL.Client.NullArray where - -- | An empty array that can be used as an argument in a GraphQL query. Useful when you dont want to add type annotations data NullArray = NullArray \ No newline at end of file diff --git a/src/GraphQL/Client/Operation.purs b/src/GraphQL/Client/Operation.purs index 5987d06f..1a783620 100644 --- a/src/GraphQL/Client/Operation.purs +++ b/src/GraphQL/Client/Operation.purs @@ -1,17 +1,16 @@ -module GraphQL.Client.Operation where - +module GraphQL.Client.Operation where class GqlOperation :: forall k. k -> Constraint -class GqlOperation a +class GqlOperation a -data OpQuery = OpQuery +data OpQuery = OpQuery instance GqlOperation OpQuery -data OpMutation = OpMutation +data OpMutation = OpMutation instance GqlOperation OpMutation -data OpSubscription = OpSubscription +data OpSubscription = OpSubscription instance GqlOperation OpSubscription \ No newline at end of file diff --git a/src/GraphQL/Client/Union.purs b/src/GraphQL/Client/Union.purs index 5b59b159..594f83e9 100644 --- a/src/GraphQL/Client/Union.purs +++ b/src/GraphQL/Client/Union.purs @@ -80,9 +80,19 @@ decodeJsonUnionWith decode = Just ty' -> map UnionReturned $ decode ty' (fromObject obj) (Proxy :: Proxy rl) -decodeUnionWith :: forall r rl l ty r' rd. IsSymbol l => Cons l ty r r' => Cons l ty () rd => Union r rd r' => - (String -> Json -> Proxy rl -> Either JsonDecodeError (Variant r)) -> (Json -> Either JsonDecodeError ty) -> String -> Json -> Proxy (RL.Cons l ty rl) -> Either JsonDecodeError (Variant r') -decodeUnionWith decodeUnion' decodeJson' ty json _ = +decodeUnionWith + :: forall r rl l ty r' rd + . IsSymbol l + => Cons l ty r r' + => Cons l ty () rd + => Union r rd r' + => (String -> Json -> Proxy rl -> Either JsonDecodeError (Variant r)) + -> (Json -> Either JsonDecodeError ty) + -> String + -> Json + -> Proxy (RL.Cons l ty rl) + -> Either JsonDecodeError (Variant r') +decodeUnionWith decodeUnion' decodeJson' ty json _ = if reflectSymbol l == ty then map (inj l) $ decodeJson' json else map expand (decodeUnion' ty json (Proxy :: Proxy rl) :: Either JsonDecodeError (Variant r)) where @@ -90,7 +100,7 @@ decodeUnionWith decodeUnion' decodeJson' ty json _ = l = Proxy failedAtTypename :: forall x y a. String -> x -> y -> Either JsonDecodeError a -failedAtTypename ty _ _ = Left $ AtKey __typename $ UnexpectedValue $ fromString ty +failedAtTypename ty _ _ = Left $ AtKey __typename $ UnexpectedValue $ fromString ty __typename :: String __typename = "__typename" diff --git a/src/GraphQL/Client/Variable.purs b/src/GraphQL/Client/Variable.purs index b04b6c23..5c644f62 100644 --- a/src/GraphQL/Client/Variable.purs +++ b/src/GraphQL/Client/Variable.purs @@ -1,7 +1,5 @@ module GraphQL.Client.Variable where - -- | A graphql variable data Var :: Symbol -> Type -> Type -data Var name a - = Var \ No newline at end of file +data Var name a = Var \ No newline at end of file diff --git a/src/GraphQL/Hasura/ComparisonExp.purs b/src/GraphQL/Hasura/ComparisonExp.purs index e9f21f14..6378c644 100644 --- a/src/GraphQL/Hasura/ComparisonExp.purs +++ b/src/GraphQL/Hasura/ComparisonExp.purs @@ -1,6 +1,6 @@ module GraphQL.Hasura.ComparisonExp where -type ComparisonExp t = +type ComparisonExp t = { _eq :: t , _gt :: t , _gte :: t diff --git a/src/GraphQL/Hasura/Decode.purs b/src/GraphQL/Hasura/Decode.purs index 6cba687c..892e1852 100644 --- a/src/GraphQL/Hasura/Decode.purs +++ b/src/GraphQL/Hasura/Decode.purs @@ -31,8 +31,7 @@ import StringParser.CodeUnits (anyDigit, char, eof) import StringParser.Combinators (many1, optionMaybe) import Type.Proxy (Proxy(..)) -type Err a - = Either JsonDecodeError a +type Err a = Either JsonDecodeError a class DecodeHasura a where decodeHasura :: Json -> Either JsonDecodeError a @@ -70,11 +69,11 @@ instance decodeHasuraTime :: DecodeHasura Time where runJsonParser :: forall a. Parser a -> Json -> Either JsonDecodeError a runJsonParser p = decodeJson >=> runParser p >>> lmap (show >>> TypeMismatch) -instance decodeRecord - :: ( DecodeHasuraFields row list - , RL.RowToList row list - ) - => DecodeHasura (Record row) where +instance decodeRecord :: + ( DecodeHasuraFields row list + , RL.RowToList row list + ) => + DecodeHasura (Record row) where decodeHasura json = case toObject json of Just object -> decodeHasuraFields object (Proxy :: Proxy list) @@ -86,44 +85,43 @@ class DecodeHasuraFields (row :: Row Type) (list :: RL.RowList Type) | list -> r instance decodeHasuraFieldsNil :: DecodeHasuraFields () RL.Nil where decodeHasuraFields _ _ = Right {} -instance decodeHasuraFieldsCons - :: ( DecodeHasuraField value - , DecodeHasuraFields rowTail tail - , IsSymbol field - , Row.Cons field value rowTail row - , Row.Lacks field rowTail - ) - => DecodeHasuraFields row (RL.Cons field value tail) where - decodeHasuraFields object _ = do - let - _field = Proxy :: Proxy field - fieldName = reflectSymbol _field - fieldValue = Object.lookup fieldName object - - case decodeHasuraField fieldValue of - Just fieldVal -> do - val <- lmap (AtKey fieldName) fieldVal - rest <- decodeHasuraFields object (Proxy :: Proxy tail) - Right $ Record.insert _field val rest - - Nothing -> - Left $ AtKey fieldName MissingValue +instance decodeHasuraFieldsCons :: + ( DecodeHasuraField value + , DecodeHasuraFields rowTail tail + , IsSymbol field + , Row.Cons field value rowTail row + , Row.Lacks field rowTail + ) => + DecodeHasuraFields row (RL.Cons field value tail) where + decodeHasuraFields object _ = do + let + _field = Proxy :: Proxy field + fieldName = reflectSymbol _field + fieldValue = Object.lookup fieldName object + + case decodeHasuraField fieldValue of + Just fieldVal -> do + val <- lmap (AtKey fieldName) fieldVal + rest <- decodeHasuraFields object (Proxy :: Proxy tail) + Right $ Record.insert _field val rest + + Nothing -> + Left $ AtKey fieldName MissingValue class DecodeHasuraField a where decodeHasuraField :: Maybe Json -> Maybe (Either JsonDecodeError a) -instance decodeFieldMaybe - :: DecodeHasura a - => DecodeHasuraField (Maybe a) where +instance decodeFieldMaybe :: + DecodeHasura a => + DecodeHasuraField (Maybe a) where decodeHasuraField Nothing = Just $ Right Nothing decodeHasuraField (Just j) = Just $ decodeHasura j -else instance decodeFieldId - :: DecodeHasura a - => DecodeHasuraField a where +else instance decodeFieldId :: + DecodeHasura a => + DecodeHasuraField a where decodeHasuraField j = decodeHasura <$> j - isoDateTime :: Parser DateTime isoDateTime = do date <- isoDate @@ -134,7 +132,7 @@ isoDateTime = do resWoTz = DateTime date time pure $ fromMaybe resWoTz $ tzMay >>= \tz -> - adjust tz resWoTz + adjust tz resWoTz isoDate :: Parser Date isoDate = do @@ -184,8 +182,8 @@ digitsToInt :: forall f. Foldable f => f Char -> Parser Int digitsToInt = foldl (\s c -> s <> singleton c) "" >>> \str -> case Int.fromString str of - Nothing -> fail $ "Failed to parse Int from: " <> str - Just i -> pure i + Nothing -> fail $ "Failed to parse Int from: " <> str + Just i -> pure i maybeFail :: forall a. String -> Maybe a -> Parser a maybeFail str = maybe (P.fail str) pure diff --git a/src/GraphQL/Hasura/DecodeLiberal.purs b/src/GraphQL/Hasura/DecodeLiberal.purs index 6ae7d1b5..50628318 100644 --- a/src/GraphQL/Hasura/DecodeLiberal.purs +++ b/src/GraphQL/Hasura/DecodeLiberal.purs @@ -22,8 +22,7 @@ import StringParser (Parser) import StringParser as P import Type.Proxy (Proxy(..)) -type DecodeLiberalOptions - = { strict :: Boolean } +type DecodeLiberalOptions = { strict :: Boolean } -- | Decode json, with silent errors when possible class DecodeHasuraLiberal a where diff --git a/src/GraphQL/Hasura/Encode.purs b/src/GraphQL/Hasura/Encode.purs index 22c15643..cda616fd 100644 --- a/src/GraphQL/Hasura/Encode.purs +++ b/src/GraphQL/Hasura/Encode.purs @@ -70,8 +70,7 @@ instance encodeHasuraRecord :: HMap EncodeHasuraProp { | r } jsonRecord => Encod unsafeToJson :: forall a. a -> Json unsafeToJson = unsafeCoerce -data EncodeHasuraProp - = EncodeHasuraProp +data EncodeHasuraProp = EncodeHasuraProp instance addOneAndShow :: EncodeHasura a =>