Created
May 11, 2020 23:48
-
-
Save srobertson/4b38b927202cd44975c4dae15fce4b63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string :: Name -> ResModel o e m | |
string = ResScalar . Data.Morpheus.Types.String | |
prompt :: String -> IO Text | |
prompt msg = | |
putStr (msg ++ ": ") | |
>> hFlush stdout -- Send output to terminal now | |
>> pack <$> getLine -- Get string from User and convert to Text | |
getSchema :: Monad m => ResponseStream e m Data.Morpheus.Types.Internal.AST.Schema | |
getSchema = | |
schemaFromTypeDefinitions | |
[dsl| | |
type Query { | |
deity(name: String): Deity! | |
} | |
type Deity { | |
name: String! | |
power: [String!]! | |
} | |
|] | |
resolver :: MonadIO m => RootResModel e m | |
resolver = | |
RootResModel | |
{ query = | |
pure $ | |
ResObject | |
( ObjectResModel | |
{ __typename = "Query", | |
objectFields = | |
[ ( "deity", | |
pure | |
$ ResObject | |
$ ObjectResModel | |
{ __typename = "Deity", | |
objectFields = | |
[ ( "name", | |
liftIO $ prompt "Name" >>= pure . string | |
), | |
( "power", | |
pure $ | |
ResList | |
[string "Shapeshifting"] | |
) | |
] | |
} | |
) | |
] | |
} | |
), | |
mutation = pure ResNull, | |
subscription = pure ResNull | |
} | |
main :: IO () | |
main = Web.scotty 3000 $ Web.post "/api" $ Web.raw =<< (liftIO . api =<< Web.body) | |
apiD :: MonadIO m => GQLRequest -> m GQLResponse | |
apiD req = | |
renderResponse <$> runResultT app | |
where | |
app = do | |
schema <- getSchema | |
runApi schema resolver req | |
api :: L.ByteString -> IO L.ByteString | |
api = mapAPI apiD | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you mean like: https://www.apollographql.com/docs/apollo-server/federation/introduction/
Where you can derive resolvers and schema from swagger and merge with api of motpheus?
Yeah. I am considering that too.
morpheusDerivedApi <:> swaggerApi.