2021-08-16
2851
#apollo#graphql
Dirk Wolthuis
4016
Aug 16, 2021 ⋅ 10 min read

Creating a scalable GraphQL API with MySQL, Node.js, and Apollo

Dirk Wolthuis Hi, I’m Dirk. I’m a writer, designer, developer, manager, and everything in between. Follow me as I figure these things out.

Recent posts:

Build A React AI Image Generator With Hugging Face Diffusers

Build a React AI image generator with Hugging Face Diffusers

Build a React-based AI image generator app offline using the Hugging Face Diffusers library and Stable Diffusion XL.

Andrew Baisden
May 29, 2025 ⋅ 10 min read
Gemini 2.5 and the future of AI reasoning for frontend devs

Gemini 2.5 and the future of AI reasoning for frontend devs

Get up to speed on Google’s latest breakthrough with the Gemini 2.5 model and what it means for the future of frontend AI tools.

Chizaram Ken
May 29, 2025 ⋅ 5 min read
Exploring The Top Rust Web Frameworks

Exploring the top Rust web frameworks

In this article, we’ll explore the best Rust frameworks for web development, including Actix Web, Rocket, Axum, warp, Leptos, Cot, and Loco.

Abiodun Solomon
May 28, 2025 ⋅ 11 min read
How To Use The CSS Cursor Property

How to use the CSS cursor property

A single line of CSS can change how users feel about your UI. Learn how to leverage the cursor property to signal intent, improve interaction flow, and elevate accessibility.

Chizaram Ken
May 28, 2025 ⋅ 6 min read
View all posts

12 Replies to "Creating a scalable GraphQL API with MySQL, Node.js, and Apollo"

  1. For me I had to change the sequelize-auto-settings.json from
    {
    “additional”: {
    “timestamps”: false
    }
    }

    to

    {
    “timestamps”: false
    }

    Maybe Sequelize has updated the way the config works.
    Mine is “sequelize”: “^5.8.9”,

  2. The modules option is really interesting due to the modularity it permits.. but how do you use context for this? For example, if I wanted to implement authentication using this format.. how would you do it?

  3. Hey There,
    i followed your instructions, and everything works so far.
    But I’m a bit in struggle.
    I want to provide the to query for different fields. And Stuff like where Priority “isGreaterThan”.

    Could you point me where i have to look for this features?

  4. For those looking for a mutation:

    in the resolver:

    Mutation: {
    addAttendant: async (obj, args, context, info) => db.attendant.create(args.input),
    },

    in the schema:

    type Mutation {
    addAttendant(input: addObj!): attendant
    }

    input addObj {
    FirstName: String
    LastName: String
    Age: Int
    FoodPreference: String
    JobTile: String
    TabelId: Int
    }

    playground:

    mutation{
    addAttendant(input:
    {
    FirstName: “Perica test22323”
    LastName: “IvkovicTest2”
    Age: 32
    FoodPreference: “Food me2”
    JobTile: “cool guye yuay2”
    TabelId: 222
    })

    { FirstName }
    }

    Obviously I have my own models but should work the same with ticket example above.

  5. Please note that this never creates any associations:
    Object.keys(db).forEach(key => {
    if (‘associate’ in db[key]) {
    db[key].associate(db);
    }
    });

    It goes through every model but sequalize-auto never creates an association.

  6. Great little tutorial here! I started a my own app to tie to my database and learn. I am having some issues app.js

    const server = new ApolloServer({
    modules: [
    require(‘./GraphQL/tickets’),
    require(‘./GraphQL/status’),
    require(‘./GraphQL/users’),
    require(‘./GraphQL/priorities’),
    ],
    })

    get ‘ReferenceError: require is not defined’ defined when I made my practice project. Google this error there are several ways that I have tried to fix this issue but no luck and non of them as elegant as your. My .babelrc, webpack.config.js and my package.json are the same except for the project names. Although my package.json does contain new entry “type”: “module” and the your project doesn’t have that entry and still runs. I’m pulling my hair out trying figure this out. Any suggestion or hints how to get rid of this darn error as clean this tutorial? Thanks any help would be greatly appreciated.

    package.json
    {
    “name”: “gqla”,
    “version”: “1.0.0”,
    “description”: “GraphQL, Apollo, MySQL”,
    “main”: “src/index.js”,
    “type”: “module”,
    “scripts”: {
    “startZ”: “nodemon src/index.js”,
    “start”: “npm-run-all –parallel build:watch run:watch”,
    “test”: “echo \”Error: no test specified\” && exit 1″,
    “build”: “webpack”,
    “build:watch”: “webpack –watch”,
    “run”: “node ./dist/app.js”,
    “run:watch”: “nodemon ./dist/app.js”
    },
    “author”: “Dan”,
    “license”: “ISC”,
    “dependencies”: {
    “@babel/core”: “^7.12.10”,
    “@babel/polyfill”: “^7.12.1”,
    “apollo-server-express”: “^2.19.1”,
    “babel-loader”: “^8.2.2”,
    “body-parser”: “^1.19.0”,
    “cors”: “^2.8.5”,
    “dotenv”: “^8.2.0”,
    “express”: “^4.17.1”,
    “graphql”: “^15.4.0”,
    “mysql2”: “^2.2.5”,
    “nodemon”: “^2.0.6”,
    “npm-run-all”: “^4.1.5”,
    “sequelize”: “^6.3.5”,
    “webpack-cli”: “^4.3.0”
    },
    “devDependencies”: {
    “path”: “^0.12.7”,
    “@babel/preset-env”: “^7.12.11”,
    “webpack”: “^5.11.0”,
    “webpack-node-externals”: “^2.5.2”
    }
    }

    webpack.config.js
    var path = require(‘path’)
    var nodeExternals = require(‘webpack-node-externals’)

    module.exports = {
    node: {
    fs: ’empty’,
    net: ’empty’,
    },
    target: ‘node’,
    externals: [nodeExternals()],
    mode: ‘development’,
    devtool: ‘inline-source-map’,
    entry: ‘./src/index.js’,
    output: {
    path: path.resolve(__dirname, ‘dist’),
    filename: ‘index_bundle.js’,
    },
    resolve: {
    // Add `.ts` and `.tsx` as a resolvable extension.
    extensions: [‘.graphql’, ‘.jsx’, ‘.js’],
    },
    module: {
    rules: [
    // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
    {
    test: /\.jsx?$/,
    loader: ‘babel-loader’,
    exclude: [/node_modules/],
    options: {
    presets: [‘@babel/preset-env’],
    // targets: {
    // node: true,
    // },
    },
    },
    ],
    },
    }

  7. I received error: WARNING in ./app/GraphQL/tickets.js 20:49-59
    “export ‘tickets’ (imported as ‘db’) was not found in ‘../database’
    @ ./app/app.js

    WARNING in ./app/GraphQL/tickets.js 42:50-60
    “export ‘tickets’ (imported as ‘db’) was not found in ‘../database’
    @ ./app/app.js

    Which is the error here?

  8. The tutorial doesnt work for me. Cant fetch data via graphql. I think because of this error:

    WARNING in ./app/GraphQL/tickets.js 20:49-59
    “export ‘tickets’ was not found in ‘../database’@ ./app/app.js’

Leave a Reply