Skip to content

Commit

Permalink
Support graphql-ws protocol, breaks existing subscriptions-transport-…
Browse files Browse the repository at this point in the history
…ws protocol (#805)
  • Loading branch information
ropwareJB authored May 11, 2023
1 parent 5c5473e commit 1218c91
Show file tree
Hide file tree
Showing 37 changed files with 1,002 additions and 67 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Just open an issue here on GitHub, or join [our Slack channel](https://morpheus-

Please note that this readme file provides only a brief introduction to the library. If you are interested in more advanced topics, visit [Docs](https://morpheusgraphql.com/).

Since version v0.28.0, Morpheus GraphQL implements the [https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md](graphql-ws GraphQL over WebSocket Protocol), and *no longer* uses the [https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md](subscriptions-transport-ws) protocol.

## Getting Started

### Setup
Expand All @@ -33,14 +35,14 @@ _stack.yml_
resolver: lts-16.2

extra-deps:
- morpheus-graphql-0.27.0
- morpheus-graphql-core-0.27.0
- morpheus-graphql-app-0.27.0
- morpheus-graphql-code-gen-0.27.0
- morpheus-graphql-code-gen-utils-0.27.0
- morpheus-graphql-server-0.27.0
- morpheus-graphql-client-0.27.0
- morpheus-graphql-subscriptions-0.27.0
- morpheus-graphql-0.28.0
- morpheus-graphql-core-0.28.0
- morpheus-graphql-app-0.28.0
- morpheus-graphql-code-gen-0.28.0
- morpheus-graphql-code-gen-utils-0.28.0
- morpheus-graphql-server-0.28.0
- morpheus-graphql-client-0.28.0
- morpheus-graphql-subscriptions-0.28.0
```
### Building your first GraphQL API
Expand Down
1 change: 1 addition & 0 deletions config/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ examples:
- scotty-haxl
- scotty-freer-simple
- servant
- yesod-pubsub
packages:
- morpheus-graphql-tests
- morpheus-graphql-core
Expand Down
2 changes: 1 addition & 1 deletion examples/client/src/Client/NewUsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ args :: NewUsersArgs
args = NewUsersArgs {loc = Coordinates {longitude = [], latitude = Euro 1 2}}

newUsers :: GQLClient -> IO (ResponseStream NewUsers)
newUsers = (`request` args)
newUsers = (`request` args)
2 changes: 1 addition & 1 deletion examples/code-gen-docs/src/Scalars.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ instance FromJSON Markdown where
parseJSON = scalarFromJSON

instance ToJSON Markdown where
toJSON = scalarToJSON
toJSON = scalarToJSON
2 changes: 1 addition & 1 deletion examples/code-gen/src/Domains/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ import Operation.API ()
import Prelude (Monad)

domainsApp :: (Typeable m, Monad m) => App () m
domainsApp = P.app <> U.app
domainsApp = P.app <> U.app
2 changes: 1 addition & 1 deletion examples/code-gen/src/Globals/GQLScalars.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ instance FromJSON Euro where
parseJSON = scalarFromJSON

instance ToJSON Euro where
toJSON = scalarToJSON
toJSON = scalarToJSON
2 changes: 1 addition & 1 deletion examples/code-gen/src/Namespaces/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module Namespaces.API where
import Namespaces.Mutation ()
import Namespaces.Query ()
import Namespaces.Sophisticated ()
import Namespaces.Subscription ()
import Namespaces.Subscription ()
2 changes: 1 addition & 1 deletion examples/code-gen/src/Operation/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module Operation.API where

import Operation.Mutation ()
import Operation.Query ()
import Operation.Subscription ()
import Operation.Subscription ()
27 changes: 13 additions & 14 deletions examples/scotty/src/Server/Subscription/SimpleSubscription.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
Expand All @@ -10,20 +10,19 @@ module Server.Subscription.SimpleSubscription where
import Data.Kind (Type)
import Data.Morpheus.Subscriptions (Event (..))
import Data.Morpheus.Types
( Resolver
, RootResolver (..)
, SubscriptionField
, WithOperation
, GQLType(..)
, publish
, subscribe
( GQLType (..),
Resolver,
RootResolver (..),
SubscriptionField,
WithOperation,
publish,
subscribe,
)
import Data.Text (Text)
import GHC.Generics (Generic)

import Server.Mythology.Character
( Deity
, someDeity
( Deity,
someDeity,
)

data Channel
Expand All @@ -37,17 +36,17 @@ data Content
newtype Query m = Query
{ deity :: m Deity
}
deriving (Generic,GQLType)
deriving (Generic, GQLType)

newtype Mutation m = Mutation
{ createDeity :: m Deity
}
deriving (Generic,GQLType)
deriving (Generic, GQLType)

newtype Subscription (m :: Type -> Type) = Subscription
{ newDeity :: SubscriptionField (m Deity)
}
deriving (Generic,GQLType)
deriving (Generic, GQLType)

type APIEvent = Event Channel Content

Expand Down
3 changes: 3 additions & 0 deletions examples/yesod-pubsub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.stack-work/
*~
client_session_key.aes
Empty file.
30 changes: 30 additions & 0 deletions examples/yesod-pubsub/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright ROPWARE (c) 2021

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Empty file added examples/yesod-pubsub/README.md
Empty file.
3 changes: 3 additions & 0 deletions examples/yesod-pubsub/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Distribution.Simple

main = defaultMain
7 changes: 7 additions & 0 deletions examples/yesod-pubsub/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Main where

import qualified Lib

main :: IO ()
main = do
Lib.main
1 change: 1 addition & 0 deletions examples/yesod-pubsub/client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
166 changes: 166 additions & 0 deletions examples/yesod-pubsub/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions examples/yesod-pubsub/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"type": "module",
"scripts": {
"start": "node src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"graphql-client": "^2.0.1",
"graphql-ws": "^5.11.2",
"https-proxy-agent": "^5.0.1",
"ws": "^8.11.0"
}
}
Loading

0 comments on commit 1218c91

Please sign in to comment.