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:

Vue logo over a brown background.

A guide to two-way binding in Vue

Learn how to implement one-way and two-way data binding in Vue.js, using v-model and advanced techniques like defineModel for better apps.

David Omotayo
Nov 22, 2024 ⋅ 10 min read
TypeScript logo over a pink and white background.

Drizzle vs. Prisma: Which ORM is best for your project?

Compare Prisma and Drizzle ORMs to learn their differences, strengths, and weaknesses for data access and migrations.

Temitope Oyedele
Nov 21, 2024 ⋅ 10 min read
Practical Implementation Of The Rule Of Least Power For Developers

Practical implementation of the Rule of Least Power for developers

It’s easy for devs to default to JavaScript to fix every problem. Let’s use the RoLP to find simpler alternatives with HTML and CSS.

Timonwa Akintokun
Nov 21, 2024 ⋅ 8 min read
Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 ⋅ 4 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