diff --git a/spago.dhall b/spago.dhall index 8efaaaf..df7a943 100644 --- a/spago.dhall +++ b/spago.dhall @@ -17,13 +17,16 @@ to generate this file without the comments in this block. , "console" , "effect" , "either" + , "foreign" , "http-methods" + , "lists" , "maybe" , "media-types" , "prelude" , "psci-support" , "simple-json" , "strings" + , "transformers" ] , packages = ./packages.dhall , sources = [ "src/**/*.purs" ] diff --git a/src/GraphQL.purs b/src/GraphQL.purs index a94b9cc..e6acad2 100644 --- a/src/GraphQL.purs +++ b/src/GraphQL.purs @@ -50,7 +50,7 @@ type ParsingErrorInfo = , jsonParsingError :: NonEmptyList ForeignError } -type GraphQLClient' +type GraphQLClient'' (operation :: GraphQL) (gql :: Symbol) (i :: Row Type) @@ -72,7 +72,27 @@ type GraphQLClient' type GraphQLClient = forall (operation :: GraphQL) (gql :: Symbol) (i :: Row Type) (o :: Row Type) (m :: Type -> Type) (e :: Type) - . GraphQLClient' operation gql i o m e + . GraphQLReqRes operation gql i o + => IsSymbol gql + => JSON.WriteForeign { | i } + => JSON.ReadForeign { | o } + => MonadAff m + => MonadThrow e m + => (NetworkErrorInfo -> e) + -> (ParsingErrorInfo -> e) + -> Gql operation + -> Record i + -> m { | o } + +type GraphQLClientAff = + forall (operation :: GraphQL) (gql :: Symbol) (i :: Row Type) (o :: Row Type) + . GraphQLReqRes operation gql i o + => IsSymbol gql + => JSON.WriteForeign { | i } + => JSON.ReadForeign { | o } + => Gql operation + -> Record i + -> Aff { | o } graphQL :: Endpoint diff --git a/test/Main.purs b/test/Main.purs index 0a035b3..ae29621 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,12 +1,13 @@ module Test.Main where import Prelude + import Data.Foldable (for_) import Data.Maybe (Maybe(..)) import Effect (Effect) import Effect.Aff (Milliseconds(..), launchAff_) import Effect.Class.Console as Log -import GraphQL.FunDeps (class GraphQLReqRes, Gql(..), GraphQL, GraphQLClient, graphQL) +import GraphQL.FunDeps (class GraphQLReqRes, Gql(..), GraphQL, GraphQLClientAff, graphQL) import Test.Spec (describe, it) import Test.Spec.Reporter.Console (consoleReporter) import Test.Spec.Runner (defaultConfig, runSpec') @@ -48,7 +49,7 @@ instance graphqlReactFinlandConference :: } ) -client :: GraphQLClient +client :: GraphQLClientAff client = graphQL "https://api.react-finland.fi/graphql" [] main ∷ Effect Unit