Moprheus GraphQL supports the import of GQL schemas directly into Haskell code based on Template Haskell.
for client you can use
for server you can use
Moprheus GraphQL also supports generating code from GraphQL
documents. To do this, you should first install
morpheus-graphql-code-gen package from
hackage or dowload built binary from
releases. to get a correct result,
make sure that the package versions match.
the package provides
morpheus cli with commands
build command generates files from the GQL source files
contained in the
code-gen.yaml configuration for the specified project root.
check command only checks if the generated files match the existing GQL documents,
which is quite handy to check if the files are outdated.
Let's take a look at the following project. where we have different
posts and users and want to develop an application for client and server.
files are defined as follows.
./src/Server/Blog.gql & ./src/Client/Blog.gql
to generate files from it, we should now configure
now we are ready to generate types.
command will lookup
code-gen.yaml and generate coresponding Haskell modules.
it will also print out the processed documents listed in these services.
the generated files are.
Now you can import types and write your own handlers or client queries based on them. For the full implementation of the example, see code-gen-docs.