diff --git a/morpheus-graphql-server/morpheus-graphql-server.cabal b/morpheus-graphql-server/morpheus-graphql-server.cabal index 7d4f1b6d0..12a3389e7 100644 --- a/morpheus-graphql-server/morpheus-graphql-server.cabal +++ b/morpheus-graphql-server/morpheus-graphql-server.cabal @@ -20,6 +20,7 @@ build-type: Simple extra-source-files: README.md changelog.md + src/Data/Morpheus/Server/Playground/index.html data-files: test/Feature/Collision/category-collision-fail/query.gql test/Feature/Collision/category-collision-success/query.gql @@ -360,6 +361,7 @@ library , base >=4.7.0 && <5.0.0 , bytestring >=0.10.4 && <1.0.0 , containers >=0.4.2.1 && <1.0.0 + , file-embed >=0.0.10 && <1.0.0 , morpheus-graphql-app >=0.28.0 && <0.29.0 , morpheus-graphql-core >=0.28.0 && <0.29.0 , mtl >=2.0.0 && <3.0.0 diff --git a/morpheus-graphql-server/package.yaml b/morpheus-graphql-server/package.yaml index fa65c8f48..dc78082a7 100644 --- a/morpheus-graphql-server/package.yaml +++ b/morpheus-graphql-server/package.yaml @@ -21,6 +21,7 @@ dependencies: - base >= 4.7.0 && < 5.0.0 - bytestring >= 0.10.4 && < 1.0.0 - containers >= 0.4.2.1 && < 1.0.0 +- file-embed >= 0.0.10 && < 1.0.0 - morpheus-graphql-app >= 0.28.0 && < 0.29.0 - morpheus-graphql-core >= 0.28.0 && < 0.29.0 - mtl >= 2.0.0 && < 3.0.0 diff --git a/morpheus-graphql-server/src/Data/Morpheus/Server/Playground.hs b/morpheus-graphql-server/src/Data/Morpheus/Server/Playground.hs index 2eb13c6ae..1dc532275 100644 --- a/morpheus-graphql-server/src/Data/Morpheus/Server/Playground.hs +++ b/morpheus-graphql-server/src/Data/Morpheus/Server/Playground.hs @@ -1,72 +1,12 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE TemplateHaskell #-} module Data.Morpheus.Server.Playground ( httpPlayground, ) where -import Data.ByteString.Lazy.Char8 (ByteString) -import Data.Functor (fmap) -import Data.Semigroup ((<>)) -import Prelude - ( mconcat, - (.), - ) - -link :: ByteString -> ByteString -> ByteString -link rel href = " rel <> "\" href=\"" <> href <> "\" />" - -meta :: [(ByteString, ByteString)] -> ByteString -meta attr = t "meta" attr [] - -tag :: ByteString -> [ByteString] -> ByteString -tag tagName = t tagName [] - -t :: ByteString -> [(ByteString, ByteString)] -> [ByteString] -> ByteString -t tagName attr children = - "<" <> tagName <> " " <> mconcat (fmap renderAttr attr) <> " >" <> mconcat children <> "" <> tagName <> ">" - where - renderAttr (name, value) = name <> "=\"" <> value <> "\" " - -script :: [(ByteString, ByteString)] -> [ByteString] -> ByteString -script = t "script" - -html :: [ByteString] -> ByteString -html = docType . t "html" [] - -docType :: ByteString -> ByteString -docType x = "" <> x +import Data.ByteString.Lazy.Char8 (ByteString, fromStrict) +import Data.FileEmbed (embedFile, makeRelativeToProject) httpPlayground :: ByteString -httpPlayground = - html - [ tag - "head" - [ meta [("charset", "utf-8")], - meta - [ ("name", "viewport"), - ("content", "user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui") - ], - tag "title" ["GraphQL Playground"], - link "stylesheet" "//cdn.jsdelivr.net/npm/graphql-playground-react/build/static/css/index.css", - link "shortcut icon" "//cdn.jsdelivr.net/npm/graphql-playground-react/build/favicon.png", - script - [("src", "//cdn.jsdelivr.net/npm/graphql-playground-react/build/static/js/middleware.js")] - [] - ], - tag - "body" - [ t "div" [("id", "root")] [], - script - [] - [ " window.addEventListener('load', (_) => \ - \ GraphQLPlayground.init(document.getElementById('root'), {}) \ - \ );" - ] - ] - ] +httpPlayground = fromStrict $(embedFile =<< makeRelativeToProject "src/Data/Morpheus/Server/Playground/index.html") diff --git a/morpheus-graphql-server/src/Data/Morpheus/Server/Playground/index.html b/morpheus-graphql-server/src/Data/Morpheus/Server/Playground/index.html new file mode 100644 index 000000000..217c1de9c --- /dev/null +++ b/morpheus-graphql-server/src/Data/Morpheus/Server/Playground/index.html @@ -0,0 +1,123 @@ + + +
+ + +