Im using the Graphql Admin API along with Webhooks in a node.js app to process bulk queries. I am able to successfully create the mutation to start the BulkOperation, returning an object with the process id and status, with no entries in the userErrors key. When my app’s webhook enpoint recieves the BULK_OPERATIONS_FINISH
request, I get back the expected payload, with the same gid as in the original mutation return value. The problem is that querying for that node by id returns { node: null }.
Worth noting, I’m aware that if your query returns no items, then the url will be null but thats not whats happening here - the entire node is null, not just the url.
To troubleshoot I used the GraphiQL test app on my developments store and ran the exact same queries and mutation as my app and was able to retrieve the node with all of the expected attributes like the url to the JSONL file.
Here’s the code for creating the BulkOperation:
const session = await Shopify.Utils.loadCurrentSession(req, res);
const { shop, accessToken } = session;
const client = new Shopify.Clients.Graphql(shop, accessToken);
const bulkQueryVariables = {
query: `{
customers {
edges {
node {
id
firstName
lastName
email
defaultAddress {
id
firstName
lastName
address1
address2
city
province
provinceCode
country
countryCodeV2
zip
}
}
}
}
}`
}
const bulkQuery = `
mutation($query: String!) {
bulkOperationRunQuery(query: $query) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}`;
const { body } = await client.query({
data: {
query: bulkQuery,
variables: bulkQueryVariables
}
});
if (body.userErrors) {
// userErrors is empty, this block never runs
console.log(error("BULK_QUERY_ERROR"), body.userErrors);
res.status(500).json({ status: 500, error: body.userErrors });
}
console.log(info("BULK_QUERY_PROCESSED"));
console.dir(body.data);
/* Returns:
{
bulkOperationRunQuery: {
bulkOperation: {
id: 'gid://shopify/BulkOperation/1000007131997',
status: 'CREATED'
},
userErrors: []
}
}
/*
Querying for the returned id returns null in my app as well as GraphiQL. I’ve also tried many different queries, including the simple products query shown in this tutorial with the exact formatting (triple quote marks and no variables). Just for the sake of being thorough, here’s my app code that handles the webhook request:
import Shopify from "@shopify/shopify-api";
import { info, success, error } from "../../utils/logger";
export const bulkHandler = async (shop, reqBody) => {
const session = await Shopify.Utils.loadOfflineSession(shop);
const body = JSON.parse(reqBody);
const { accessToken } = session
const { admin_graphql_api_id } = body;
const client = new Shopify.Clients.Graphql(shop, accessToken)
console.log(info('BULK_HANDLER_BODY'))
console.log(body)
const query = `{
node(id: "${admin_graphql_api_id}") {
... on BulkOperation {
url
partialDataUrl
}
}
}`
console.log(info("BULK_GRAPH_QUERY"));
console.log(query);
const res = await client.query({
data: {query}
})
const { data } = res.body
console.log(info('BULK_GRAPH_ATTEMPT'), data)
// Returns { node: null }
};
What could be the reason that the BulkOperation nodes created by my app are not accessible, but not when using the GraphiQL app? I made sure that my app has proper read and write scopes for products and customers (the only two bulk queries I’ve tried)