A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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)
Did you ever get this figured out? I'm having the same issue.
Ok. I figured this out.
If you use the shopify-graphiql-app to create your webhook, the webhook is created under different credentials than the other webhooks for your store/custom app.
You have to create the webhook through GraphQL using the credentials of your other webhooks, which most likely means just submitting the webhook creation query as you do your other GraphQL queries.
@Schmidtc63 Hey Bro !
I need Help.
I am doing the bulkOperationRunMutation for productCreate but i got null object in return. Do you Know anything about it?
I don't off hand. However... I bet we can figure this out.
Post your query and we'll take it from there.
@Schmidtc63 Thanks for your replay!
i posted my query here:
https://community.shopify.com/c/shopify-apps/bulkoperation-response-is-null-when-creating-products-i...
but I didn't get any solution yet.
Hey @syedusama0786 - can you share the response body you're receiving from the API call that returns the null value for the bulk operation? Are you just receiving a null value for the bulk operation or are you seeing any error messages returned?
Hope to hear from you soon - happy to help out with this.
Al | Shopify Developer Support
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thank You So much for your response I solve this issue!
Hi there,
How did you resolve this?
I'm running a bulk mutation for productCreate for 1000 products at a time, but I have noticed that it will either miss a product or two, or it when I go to the returned URL for the jsonl file, it has null for all my products.
As it doesn't give me any errors or any information, I'm unsure how I'm meant to diagnose why it doesn't upload the products.
Here is a screenshot (since jsonl files aren't supported for some reason) of the file...
As you can see, only one product uploaded out of the 1000, and it's missing all its fields other than the title and descriptionHtml.
Thanks in advance.
@nahtE First of all sorry for the late reply!
I think you did something wrong when you create a JSONL file for your product.
My Query is working fine but I got an issue in the bulk query it skip some of my products.
but in the response JSONL file, it shows me all the products.
No I don't believe I did anything wrong, as its entirely random and different products each time. Another perk of Shopify's absolute shit API with garbage documentation.
@nahtE Hey!😅
Show me your code probably it will help you after I analyze your code.
@Schmidtc63 @ShopifyDevSup
I am also in same kind of issue like @dsegal_maze mention. what I figure out so far. Here is my query
query {
node(id: "gid://shopify/BulkOperation/3782671040662") {
... on BulkOperation {
url
partialDataUrl
}
}
}
Right I use shopify node api library shopify-api 7.1.0.
Here is problem when I try access same query with online session it's working fine but when I try to fetch using offline session, I am getting same "node": null as response.
can tell what can be problem here?