Skip to content

Instantly share code, notes, and snippets.

@theoomoregbee
Last active November 10, 2020 13:58
Show Gist options
  • Save theoomoregbee/72e02d3262f6f0ed01cdaaa1381f536f to your computer and use it in GitHub Desktop.
Save theoomoregbee/72e02d3262f6f0ed01cdaaa1381f536f to your computer and use it in GitHub Desktop.
Graphql explorer nodejs server
const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { loadSchema } = require('@graphql-tools/load');
const { JsonFileLoader } = require('@graphql-tools/json-file-loader');
const app = express();
// yarn codegen (with introspection plugin) must run first so ./graphql.schema.json is available to use here
loadSchema('./graphql.schema.json', {
loaders: [new JsonFileLoader()],
})
.then(async (schema) => {
app.use(
'/graphql',
graphqlHTTP({
schema,
graphiql: true,
}),
);
app.listen(4000);
console.log(
'Running a GraphQL API server at http://localhost:4000/graphql',
);
})
.catch((err) => {
console.error('Unable to load schema definitions', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment