I use graphql-express to create an endpoint where I can execute graphql queries. Although I use Sequelize with an SQL database, it is embarrassing to use it directly from the server outside of my graphql functions resolve. How do I access my graphql API from the same server as in it?
This is how I set the graphql endpoint:
const express = require('express');
const router = express.Router();
const graphqlHTTP = require('express-graphql');
const gqlOptions = {
schema: require('./schema')
};
router.use('/', graphqlHTTP(gqlOptions));
modules.exports = router;
Basically, I want to be able to do something like this:
query(`
{
user(id: ${id}) {
name
}
}
`)
How do I create this function query?
source
share