Last active
November 10, 2020 13:58
-
-
Save theoomoregbee/72e02d3262f6f0ed01cdaaa1381f536f to your computer and use it in GitHub Desktop.
Graphql explorer nodejs server
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
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