Shopify / Shopify/shopify-app-template-node
GraphQL api query by tag not working
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 434
- PR merge metrics
- No merged PRs in 30d
Description
Issue summary
When i make a GraphQL query to retrieve orders with a query filter on tag, it returns no results. Using the same query in the Shopify GraphQL app in the store returns results. Removing the query:"tag:Ship" from query results in orders being returned.
My code was adapted from the QR Code example app - https://shopify.dev/docs/apps/getting-started/build-app-example
My code adds a new endpoint middleware to express and makes a simple graphql query -
import express from "express";
import shopify from "../shopify.js";
const ORDERS_QUERY = `
query {
orders(first:100, query:"tag:Ship") {
edges {
node {
id
name
tags
}
}
}
}
`;
export default function applyOrdersApiEndpoints(app) {
app.use(express.json());
app.get("/api/weekorders", async (req, res) => {
const client = new shopify.api.clients.Graphql({
session: res.locals.shopify.session,
});
const orders = await client.query({
data: {
query: ORDERS_QUERY
},
});
res.send(orders.body.data);
});
}
app setup in shopify.js (unchanged from QR Code example app):
import { LATEST_API_VERSION } from "@shopify/shopify-api";
import { shopifyApp } from "@shopify/shopify-app-express";
import { LogSeverity } from "@shopify/shopify-api"
import { SQLiteSessionStorage } from "@shopify/shopify-app-session-storage-sqlite";
import { restResources } from "@shopify/shopify-api/rest/admin/2023-01";
import sqlite3 from "sqlite3";
import { join } from "path";
import { QRCodesDB } from "./qr-codes-db.js";
const database = new sqlite3.Database(join(process.cwd(), "database.sqlite"));
// Initialize SQLite DB
QRCodesDB.db = database;
QRCodesDB.init();
const shopify = shopifyApp({
api: {
apiVersion: LATEST_API_VERSION,
restResources,
billing: undefined, // or replace with billingConfig above to enable example billing
logger: {
level: LogSeverity.Debug,
httpRequests: true, // if the error seems to be related to requests
}
},
auth: {
path: "/api/auth",
callbackPath: "/api/auth/callback",
},
webhooks: {
path: "/api/webhooks",
},
sessionStorage: new SQLiteSessionStorage(database),
});
export default shopify;
@shopify/shopify-app-*package and version:
"@shopify/shopify-app-express": "^1.1.0",
"@shopify/shopify-app-session-storage-sqlite": "^1.0.0",
- Node version: v18.15.0
- Operating system: Ubuntu 5.10.16.3-microsoft-standard-WSL2
023-03-17 23:28:31 | backend | [shopify-api/INFO] version 6.2.0, environment Node v18.15.0
2023-03-17 23:28:48 | backend | [shopify-app/INFO] Running ensureInstalledOnShop
2023-03-17 23:28:48 | backend | [shopify-app/DEBUG] Checking if shop has installed the app | {shop: anna-cake-couture.myshopify.com}
2023-03-17 23:28:48 | backend | [shopify-app/INFO] App is installed and ready to load | {shop: anna-cake-couture.myshopify.com}
2023-03-17 23:28:52 | backend | [shopify-app/INFO] Running validateAuthenticatedSession
2023-03-17 23:28:52 | backend | [shopify-api/DEBUG] App is embedded, looking for session id in JWT payload | {isOnline: false}
2023-03-17 23:28:52 | backend | [shopify-api/DEBUG] Found valid JWT payload | {shop: anna-cake-couture.myshopify.com, isOnline: false}
2023-03-17 23:28:52 | backend | [shopify-app/DEBUG] Request session found and loaded | {shop: anna-cake-couture.myshopify.com}
2023-03-17 23:28:52 | backend | [shopify-app/DEBUG] Request session exists and is active | {shop: anna-cake-couture.myshopify.com}
2023-03-17 23:28:52 | backend | [shopify-api/DEBUG] Making HTTP request - POST https://anna-cake-couture.myshopify.com/admin/api/2023-01/graphql.json - Headers:
{"X-Shopify-Access-Token":["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"],"User-Agent":["Shopify Express Library v1.2.2 | Shopify API Library v6.2.0 | Node
v18.15.0"],"Content-Type":["application/graphql"],"Content-Length":["26"]} - Body: "\n{\n shop {\n name\n }\n}"
2023-03-17 23:28:53 | backend | [shopify-api/DEBUG] Completed HTTP request, received 200 OK
2023-03-17 23:28:53 | backend | [shopify-app/INFO] Request session has a valid access token | {shop: anna-cake-couture.myshopify.com}
2023-03-17 23:28:53 | backend | [shopify-api/DEBUG] Making HTTP request - POST https://anna-cake-couture.myshopify.com/admin/api/2023-01/graphql.json - Headers:
{"X-Shopify-Access-Token":["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"],"User-Agent":["Shopify Express Library v1.2.2 | Shopify API Library v6.2.0 | Node
v18.15.0"],"Content-Type":["application/json"],"Content-Length":["159"]} - Body: "{\"query\":\"\\nquery {\\n orders(first:100, query:\\\"tag:Ship\\\") {\\n edges
{\\n node {\\n id\\n name\\n tags\\n }\\n }\\n }\\n}\\n \"}"
2023-03-17 23:28:53 | backend | [shopify-api/DEBUG] Completed HTTP request, received 200 OK
Expected behavior
The GraphQL query should return orders tagged with 'Ship'
Actual behavior
No results are returned
Steps to reproduce the problem
Run the query above using the GraphQL client as shown above
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the endpoint middleware shown in the issue and shopify.js, then inspect the GraphQL request body sent by the client. Reproduce the tagged-order query and compare its response with the Shopify GraphQL app; done means the endpoint returns orders tagged Ship and the cause of the discrepancy is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, graphql, javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100