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 Micro-Frontend Application With React

Build a micro-frontend application with React

Learn to build scalable micro-frontend applications using React, discussing their advantages over monolithic frontend applications.

Harsh Patel
Nov 4, 2024 ⋅ 8 min read
Building A Real-Time Chat App Using Laravel Reverb And Vue

Building a real-time chat app using Laravel Reverb and Vue

Build a fully functional, real-time chat application using Laravel Reverb’s backend and Vue’s reactive frontend.

Rosario De Chiara
Nov 4, 2024 ⋅ 12 min read
Solving The Node.js Console.Time Is Not A Function Error

Solving the Node.js console.time is not a function error

Explore the two variants of the `console.time is not a function` error, their possible causes, and how to debug.

Joseph Mawa
Nov 1, 2024 ⋅ 6 min read
Why jQuery 4 Is A Good Reminder To Stop Using jQuery

Why jQuery 4 is a good reminder to stop using jQuery

jQuery 4 proves that jQuery’s time is over for web developers. Here are some ways to avoid jQuery and decrease your web bundle size.

Shalitha Suranga
Oct 31, 2024 ⋅ 11 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