@gql-tools/hypergraph-express-middleware v0.1.0-alpha.4
Hypergraph Express Middleware
Fastest way to create Graphql Server with Express
Installation
yarn add @gql-tools/hypergraph-express-middleware
Usage
middleware
- Add Middleware
import { middleware } from ' @gql-tools/hypergraph-express-middleware';
const context = { dbConnection, otherGlobals };
app.use('/graphql', middleware(context));Now place your Resolvers in
graphs/resolvers.js.And your types in
graphs/types.You can change default locations by defining new paths in
.hypergraphrcin your project root.
{
"types": "some/other/graphs",
"resolvers": "src/other/resolvers"
}playground
import { playground } from ' @gql-tools/hypergraph-express-middleware';
app.use('/graphiql', playground(/* graphql route*/ '/graphql'));merge
- Merges two graphql resolvers, useful if you want to divide resolver to different files
Why Hypergraph? or Hot-ish Reloading of Resolvers
Hypergraph seperates your main node application with the graphql resolvers. You can have separate Dev Servers for your resolvers and Node Server so whenever there are changes in Resolvers only the resolver server is reloaded.
Hypergraph does cache invalidation during development in order to achieve
hot-ish reloadingfor Resolvers, so it relies onNODE_ENVenvironment variable. Server reloading will not work if there's noNODE_ENVvar present.Hot Reloading can be achieved with any server, nodemon or webpack-dev-server or both(Required that only one does reloading).
eg with Nodemon
const resolverReload = nodemon({
script: 'path to root resolver',
watch: ['root resolver', 'types dir if you want'],
nodeArgs: process.argv.slice(2),
}).on('quit', process.exit);
const expressReload = nodemon({
script: 'path to express app',
watch: ['express dir'],
nodeArgs: process.argv.slice(2),
}).on('quit', process.exit);