diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-07-14 19:37:56 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-07-14 19:37:56 +0200 |
| commit | ae2210f6598f166116abebc1163e1523d3bc627c (patch) | |
| tree | 02b18f29d0b025a702366e70405dbcc203092c96 /src/Language/GraphQL.hs | |
| parent | 840e129c4496b4e8145480d2b3c3cb34f505702e (diff) | |
| download | graphql-ae2210f6598f166116abebc1163e1523d3bc627c.tar.gz | |
Support subscriptions
This is experimental support.
The implementation is based on conduit and is boring. There is a new
resolver data constructor that should create a source event stream. The
executor receives the events, pipes them through the normal execution
and puts them into the response stream which is returned to the user.
- Tests are missing.
- The executor should check field value resolver on subscription types.
- The graphql function should probably return (Either
ResponseEventStream Response), but I'm not sure about this. It will
make the usage more complicated if no subscriptions are involved, but
with the current API implementing subscriptions is more
difficult than it should be.
Diffstat (limited to 'src/Language/GraphQL.hs')
| -rw-r--r-- | src/Language/GraphQL.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Language/GraphQL.hs b/src/Language/GraphQL.hs index 845d5cf..6ee2dd7 100644 --- a/src/Language/GraphQL.hs +++ b/src/Language/GraphQL.hs @@ -9,6 +9,7 @@ module Language.GraphQL import qualified Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson +import Data.Either (fromRight) import qualified Data.Sequence as Seq import Data.Text (Text) import Language.GraphQL.AST @@ -34,10 +35,14 @@ graphqlSubs :: Monad m -> Aeson.Object -- ^ Variable substitution function. -> Text -- ^ Text representing a @GraphQL@ request document. -> m Aeson.Value -- ^ Response. -graphqlSubs schema operationName variableValues document' = - either parseError executeRequest parsed >>= formatResponse +graphqlSubs schema operationName variableValues document' + = either parseError executeRequest (parse document "" document') + >>= formatResponse where - parsed = parse document "" document' + executeRequest parsed + = fromRight streamReturned + <$> execute schema operationName variableValues parsed + streamReturned = singleError "This service does not support subscriptions." formatResponse (Response data'' Seq.Empty) = pure $ Aeson.object [("data", data'')] formatResponse (Response data'' errors') = pure $ Aeson.object @@ -54,4 +59,3 @@ graphqlSubs schema operationName variableValues document' = [ ("line", Aeson.toJSON line) , ("column", Aeson.toJSON column) ] - executeRequest = execute schema operationName variableValues |
