Skip to content

Fix post-jdbc.core-migration problems (column names, upsert, position… #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2020

Conversation

brdloush
Copy link
Contributor

Hi, after reading the tutorial up to Testing, Phase 1part (so far well-written IMO!), I gave this clojure-game-geek repository a try in order to be able to play with GraphiQL a bit.

Unfortunately, the codebase didn't really work for me and I had to fix a few issues in order to be able to successfully use GraphiQL with all the subgraph fetches & mutations working. I'm not sure if the changes are correct and complete, but they worked for me, so I'm sharing them.

Here's what I had to fix:

  1. db.clj : some SQL queries used parameters such as $1. According to git log, is seems that postgres.async was used in the past and it supports such form of positional query parameters. But in java.jdbc, one has to use simpler ? form (and pass the same value multiple times if present multiple times in statement, such as in case of rating in upsert-game-rating).

  2. cgg-schema.edn: had to change :member_name to :name in :Member object, as the column in member table is called just name, not member_name

  3. db.clj : had to add execute! function and use it inside upsert-game-rating instead of query. Otherwise (when query function was used) the update part of the statement would actually be executed successfully, but since it returned no result, the query function itself would then immediately fail.

  4. schema.clj : had to modify (:id board-game) to (:game_id board-game) etc as columns in db are called game_id, designer_id etc.

  5. setup-db.sh : had to add unique constraint on combination of columns game_id+member_id of game_rating table. Otherwise the on conflict (game_id, member_id) do update set rating = ? part of upsert-game-rating function would crash due to missing uniqe constraint.

After mentioned changes, I'm able to perform following GraphQL mutation...

Request:

mutation {
  rate_game(game_id:1234, member_id: 37, rating: 5) {
    description
    max_players
    min_players
    play_time
    summary
  }
}

Response:

{
  "data": {
    "rate_game": {
      "description": null,
      "max_players": 2,
      "min_players": 2,
      "play_time": null,
      "summary": "Two player abstract with forced moves and shrinking board"
    }
  }
}

... and also following query:

Request:

{
  game_by_id(id: 1234) {
    game_id
    name
    min_players
    max_players
    play_time
    summary
    designers {
      name
      url
      games {
        name
      }
    }
    rating_summary {
      count
      average
    }
  }
  member_by_id(id: 37) {
    member_id
    name
    ratings {
      game {
        game_id
        name
      }
      rating
    }
  }
}

Response:
{
  "data": {
    "game_by_id": {
      "game_id": 1234,
      "name": "Zertz",
      "min_players": 2,
      "max_players": 2,
      "play_time": null,
      "summary": "Two player abstract with forced moves and shrinking board",
      "designers": [
        {
          "name": "Kris Burm",
          "url": null,
          "games": [
            {
              "name": "Zertz"
            }
          ]
        }
      ],
      "rating_summary": {
        "count": 2,
        "average": 5
      }
    },
    "member_by_id": {
      "member_id": 37,
      "name": "curiousattemptbunny",
      "ratings": [
        {
          "game": {
            "game_id": 1234,
            "name": "Zertz"
          },
          "rating": 5
        }
      ]
    }
  }
}

@CLAassistant
Copy link

CLA assistant check
All committers have signed the CLA.

@hlship
Copy link
Member

hlship commented Sep 5, 2020

Thanks! My high ambitions on the tutorial have fallen prey to work load (and home life!) so I really appreciate the help.

@hlship hlship merged commit 73d0232 into walmartlabs:master Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants