I am writing an application which uses apollo-express-server and GraphQL to query a MySQL server. Mostly it works, but I want to remove this very verbose output:
Executing (default): SELECT `id`, `name`, `description`, `image` FROM `units_topics` AS `units_topics` WHERE `units_topics`.`id` = 21;
So every query produces something like that, and for big queries it goes on for quite sometime.
My server set up is this, and uses Serialize for the database structure...
server.js
const app = require("./app");
const apollo = require("apollo-server-express");
async function startApolloServer(typeDefs, resolvers) {
const apolloServer = new apollo.ApolloServer({
modules: [
require('./GraphQL/users'),
require('./GraphQL/units_topics'),
require('./GraphQL/a_flashcards'),
require('./GraphQL/a_flashcards_performed')
]
})
await apolloServer.start();
apolloServer.applyMiddleware({ app });
await new Promise(resolve => app.listen({ port: 5000 }, resolve));
console.log(`🚀 Server ready at http://localhost:5000`);
}
startApolloServer();
app.js
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
module.exports = app;
database.js
const Sequelize = require('sequelize');
var db = {};
const sequelize = new Sequelize.Sequelize(
'xxx',
'xxx',
'xxx',
{
host: 'xxx',
port: 'xxx',
dialect: 'mysql',
define: {
freezeTableName: true,
},
pool: {
max: 1,
min: 0,
acquire: 30000,
idle: 10000,
},
// <http://docs.sequelizejs.com/manual/tutorial/querying.html#operators>
operatorsAliases: false,
},
)
let models = [
require("./models/a_flashcards"),
require("./models/a_flashcards_performed"),
require("./models/a_flashcards_points"),
require("./models/units_topics"),
require("./models/users")
];
models.forEach(model => {
const seqModel = model(sequelize, Sequelize.Sequelize);
db[seqModel.name] = seqModel;
})
Object.keys(db).forEach(key => {
if('associate' in db[key]) {
db[key].associate(db);
}
})
db.sequelize = sequelize;
db.Sequelize = Sequelize.Sequelize;
module.exports = db;
Can anybody advise on how I get rid of this verbose output?
This is a sequelize problem, thus in the constructor for the sequelize db call, add the new line for logging:
const sequelize = new Sequelize.Sequelize(
'xxx',
'xxx',
'xxx',
{
logging: false,
host: 'xxx',
port: 'xxx',
dialect: 'mysql',
...
},
)
Thanks to Michael Floyd who posted in the comments: How to disable logging in sequelize