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:

Use TypeScript Instead Of Python For ETL Pipelines

Use TypeScript instead of Python for ETL pipelines

Build a TypeScript ETL pipeline that extracts, transforms, and loads data using Prisma, node-cron, and modern async/await practices.

Muhammed Ali
Apr 17, 2025 ⋅ 6 min read
best react charts libraries

Best React chart libraries (2025 update): Features, performance & use cases

Looking for the best React charting library? Compare the latest options, from Recharts to MUI X Charts, and see which one fits your project best.

Hafsah Emekoma
Apr 16, 2025 ⋅ 10 min read
TypeScript Is Going Go: Why It's The Pragmatic Choice

TypeScript is going Go: Why it’s the pragmatic choice

Explore why the TypeScript team is porting the compiler to Go in TypeScript 7. Learn how this shift impacts performance, tooling, and the future of the TypeScript ecosystem.

John Reilly
Apr 16, 2025 ⋅ 9 min read
six RAG types you should know

6 retrieval augmented generation (RAG) techniques you should know

Explore six powerful RAG techniques to enhance LLMs with external data for smarter, real-time AI-driven web applications.

Rosario De Chiara
Apr 16, 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