Skip to content

Commit 32edfdd

Browse files
committed
Fix GraphQL query error: extract item from path instead of querying non-existent field
- Remove 'item' field from GraphQL query in Index.vue (not available in schema) - Extract item ID from path field (path format: /:item) - Add paintingItem computed property in ActionBar.vue - Add getPaintingWithItem() method in Index.vue to add item property - Update tests to use path instead of item field - Fix test mocks for g-link and eventBus Fixes GitHub Action build failure: Error: Cannot query field "item" on type "Painting" Build now completes successfully.
1 parent 572ed79 commit 32edfdd

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
lines changed

src/components/ActionBar.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
:data-favorite="isFavorite"
1010
role="button"
1111
aria-label="Toggle favorite"
12-
@click.prevent="toggleFavorite(painting.item)"
12+
@click.prevent="toggleFavorite(paintingItem)"
1313
>
1414
<svg
1515
xmlns="http://www.w3.org/2000/svg"
@@ -79,12 +79,20 @@ export default {
7979
};
8080
},
8181
computed: {
82+
/**
83+
* Gets the Wikidata item ID from the painting's path
84+
* @returns {string} The Wikidata item ID (e.g., "Q12345")
85+
*/
86+
paintingItem() {
87+
// Extract item from path (path format: /:item)
88+
return this.painting.path ? this.painting.path.replace(/^\//, "") : null;
89+
},
8290
/**
8391
* Gets the Wikidata URL for the current painting
8492
* @returns {string} The full Wikidata URL
8593
*/
8694
getWikidataLink() {
87-
return "https://www.wikidata.org/wiki/" + this.painting.item;
95+
return "https://www.wikidata.org/wiki/" + this.paintingItem;
8896
}
8997
},
9098
methods: {

src/components/__tests__/ActionBar.spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { mount } from "@vue/test-utils";
22
import ActionBar from "../ActionBar.vue";
3+
import Vue from "vue";
4+
5+
// Mock Gridsome's g-link component globally
6+
Vue.component("g-link", { template: "<a><slot /></a>" });
7+
// Mock the global event bus
8+
Vue.prototype.$eventBus = new Vue();
39

410
describe("ActionBar", () => {
511
const mockPainting = {
6-
item: "Q12345",
12+
path: "/Q12345",
713
title: "Test Painting",
814
image: "https://example.com/image.jpg",
915
cover_image: "https://example.com/cover.jpg"
@@ -18,7 +24,8 @@ describe("ActionBar", () => {
1824

1925
const buttons = wrapper.findAll("button");
2026
expect(buttons.length).toBe(2); // Favorite and download buttons
21-
expect(wrapper.find("g-link").exists()).toBe(true); // Wikidata link
27+
// g-link is mocked as <a>, so check for that
28+
expect(wrapper.find("a").exists()).toBe(true); // Wikidata link
2229
});
2330

2431
it("gets correct Wikidata link", () => {

src/pages/Index.vue

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ query {
5050
node {
5151
id
5252
path
53-
item
5453
title: paintingLabel
5554
image
5655
cover_image: image (width: 770, height: 380, blur: 10)
@@ -230,9 +229,13 @@ export default {
230229
// ... in case of favorite view
231230
if (this.view === FAVORITES && this.favorites.length > 0) {
232231
// filter matching cards
233-
return this.$page.paintings.edges.filter(edge =>
234-
includes(this.favorites, edge.node.item)
235-
);
232+
return this.$page.paintings.edges.filter(edge => {
233+
// Extract item from path (path format: /:item)
234+
const item = edge.node.path
235+
? edge.node.path.replace(/^\//, "")
236+
: null;
237+
return includes(this.favorites, item);
238+
});
236239
}
237240
// otherwise show standard dashboard ...
238241
return this.$page.paintings.edges.filter(edge => {
@@ -248,6 +251,19 @@ export default {
248251
}
249252
},
250253
methods: {
254+
/**
255+
* Extracts the item ID from a painting's path
256+
* @param {Object} painting - The painting node
257+
* @returns {Object} Painting object with item property added
258+
*/
259+
getPaintingWithItem(painting) {
260+
// Extract item from path (path format: /:item)
261+
const item = painting.path ? painting.path.replace(/^\//, "") : null;
262+
return {
263+
...painting,
264+
item: item
265+
};
266+
},
251267
/**
252268
* Clears all active filters
253269
*/

src/templates/Painting.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ query painting ($id: ID!) {
113113
title: paintingLabel
114114
image
115115
year: date (format: "YYYY")
116-
location: locationLabel
116+
location: locationLabel
117117
materials
118118
depicts
119119
}

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,10 +1017,10 @@
10171017
minimatch "^3.1.2"
10181018
strip-json-comments "^3.1.1"
10191019

1020-
"@eslint/js@9.39.1":
1021-
version "9.39.1"
1022-
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.39.1.tgz#0dd59c3a9f40e3f1882975c321470969243e0164"
1023-
integrity sha512-S26Stp4zCy88tH94QbBv3XCuzRQiZ9yXofEILmglYTh/Ug/a9/umqvgFtYBAo3Lp0nsI/5/qH1CCrbdK3AP1Tw==
1020+
"@eslint/js@9.39.2":
1021+
version "9.39.2"
1022+
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.39.2.tgz#2d4b8ec4c3ea13c1b3748e0c97ecd766bdd80599"
1023+
integrity sha512-q1mjIoW1VX4IvSocvM/vbTiveKC4k9eLrajNEuSsmjymSDEbpGddtpfOoN7YGAqBK3NG+uqo8ia4PDTt8buCYA==
10241024

10251025
"@eslint/object-schema@^2.1.7":
10261026
version "2.1.7"
@@ -5114,17 +5114,17 @@ eslint-visitor-keys@^4.2.0, eslint-visitor-keys@^4.2.1:
51145114
integrity sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==
51155115

51165116
eslint@^9.39.1:
5117-
version "9.39.1"
5118-
resolved "https://registry.yarnpkg.com/eslint/-/eslint-9.39.1.tgz#be8bf7c6de77dcc4252b5a8dcb31c2efff74a6e5"
5119-
integrity sha512-BhHmn2yNOFA9H9JmmIVKJmd288g9hrVRDkdoIgRCRuSySRUHH7r/DI6aAXW9T1WwUuY3DFgrcaqB+deURBLR5g==
5117+
version "9.39.2"
5118+
resolved "https://registry.yarnpkg.com/eslint/-/eslint-9.39.2.tgz#cb60e6d16ab234c0f8369a3fe7cc87967faf4b6c"
5119+
integrity sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==
51205120
dependencies:
51215121
"@eslint-community/eslint-utils" "^4.8.0"
51225122
"@eslint-community/regexpp" "^4.12.1"
51235123
"@eslint/config-array" "^0.21.1"
51245124
"@eslint/config-helpers" "^0.4.2"
51255125
"@eslint/core" "^0.17.0"
51265126
"@eslint/eslintrc" "^3.3.1"
5127-
"@eslint/js" "9.39.1"
5127+
"@eslint/js" "9.39.2"
51285128
"@eslint/plugin-kit" "^0.4.1"
51295129
"@humanfs/node" "^0.16.6"
51305130
"@humanwhocodes/module-importer" "^1.0.1"

0 commit comments

Comments
 (0)