Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Newlines not allowed anymore in GraphQl query

Solved

Newlines not allowed anymore in GraphQl query

RobertTres
Tourist
4 0 7

Hi all,

 

Since yesterday (1st of august 2024), I get the following error when running Bulk Queries in GraphQl. 

syntax error, unexpected invalid token (\"\\\"\") at [2, 32] 

 

My query is as follows:

mutation MyMutation {
  bulkOperationRunQuery(query: "query Orders {
				orders(query: \"created_at:>'2024-07-26T09:21:56Z'\") {
					edges {
						node {
							id
							name
							totalDiscounts
							cartDiscountAmount
							createdAt
							billingAddress {
								address1
								address2
								city
								company
								country
								countryCode
								firstName
								id
								lastName
								name
								phone
								zip
							}
							shippingAddress {
								address1
								address2
								city
								company
								country
								countryCode
								firstName
								id
								lastName
								name
								phone
								zip
							}
							currentTotalPriceSet {
								shopMoney {
									amount
									currencyCode
								}
							}
							lineItems {
								edges {
									node {
										id
										name
										originalTotal
										originalUnitPrice
										quantity
										sku
										taxable
										title
										totalDiscount
										product {
											id
										}
										discountAllocations {
											discountApplication {
												allocationMethod
												index
												targetSelection
												targetType
												value {
													... on MoneyV2 {
														amount
														currencyCode
													}
													... on PricingPercentageValue {
														percentage
													}
												}
											}
										}
									}
								}
							}
							shippingLine {
								carrierIdentifier
								code
								custom
								deliveryCategory
								id
								phone
								price
								shippingRateHandle
								source
								title
							}
							fulfillmentOrders {
								edges {
									node {
										channelId
										createdAt
										fulfillAt
										fulfillBy
										id
										orderId
										orderName
										orderProcessedAt
										requestStatus
										status
										updatedAt
									}
								}
							}
							discountApplications {
								edges {
									node {
										allocationMethod
										index
										targetSelection
										targetType
										value {
											... on MoneyV2 {
												amount
												currencyCode
											}
											... on PricingPercentageValue {
												percentage
											}
										}
									}
								}
							}
						}
					}
				}
			}") {
    bulkOperation {
      id
    }
  }
}

I solved this by removing all the new lines.
However I wonder if this is as intended. This makes the query much less readable. 


Am I missing a setting or some documentation stating this change?

 

Kind regards,

Robert

 

Accepted Solution (1)
Liam
Community Manager
3108 344 911

This is an accepted solution.

Hi again Robert - it's possible this was a temporary bug on our side and may have already been resolved. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

View solution in original post

Replies 19 (19)

JoonasS
Shopify Partner
2 0 6

Same here, except for... 

 

GraphqlQueryError: syntax error, unexpected invalid token ("\"") at [3, 31]

 

didn't find a workaround yet, it broke basically everything for us, can't update anything anymore.

RobertTres
Tourist
4 0 7

Hi JoonasS,

 

I don't know which language you are using, but I fixed it by using a simple regex replace. 

Regex.Replace(s, @"\t|\n|\r", " ");

 

Have you tried this? Or is it not possible in your solutions.

JoonasS
Shopify Partner
2 0 6

Thanks for the suggestion, but I'm updating metafields which have json values, so I need to add the \" for it to parse the values properly, I don't know what would work to go around this, and at the same time maintain the proper structure for the fields. 


I was "fixing" the prerequest, which was fine, the actual mutation was the one that needed fixing
For anyone else, here's an example how we fix the query so it passes
Thanks @RobertTres for the tip! 

           const bulkUpdate = {
                        data: `mutation {
                    bulkOperationRunMutation(
                    mutation: "mutation call($input: ProductVariantInput!) { 
                        productVariantUpdate(input: $input) { 
                            userErrors {
                                message
                                field 
                            } 
                        }
                    } ",
                    stagedUploadPath: "${stagedUploadPath}") {
                        bulkOperation {
                            id
                            url
                            status
                        }
                        userErrors {
                            message
                            field
                        }
                    }
                }
                `.replace(/\n/g, '').replace(/\t/g, '').replace(/\r/g, '')
Mickeydtails
Shopify Partner
13 1 15

Thanks, we also do something similar to fi xit. But it's really terrible something like is changed in a stable API. I hope Shopify will roll it back

Mickeydtails
Shopify Partner
13 1 15

@Liam Just to make sure someone at Shopify is aware 🙂

Liam
Community Manager
3108 344 911

Hi - is this still ongoing? Looking into this issue now.

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

Mickeydtails
Shopify Partner
13 1 15

I've done some more digging and can confirm it is indeed only bulkMutations that are affected, not bulk queries. As far as I see it's the same for all api versions

bhavin_iflair
Shopify Partner
9 1 3

@Mickeydtails FYI...We have get this issue in the productCreate mutation. There is a new line in the product description that i have removed and all good now.

Falcotech
Shopify Partner
5 0 5

This fix worked for me, thank you.

 

My web app broke due to this unannounced change. I'm surprised Shopify allowed this to happen.

perice666
Shopify Partner
12 0 14

Yeah, they broke it.

 

I had to replace the escaped double quote (\") with an unescaped one (")

 

Before:

mutation { bulkOperationRunQuery(query: """query { products(query: \"updated_at:>'1999-12-31T23:00:00Z' AND published_status:published\") {

After:

 

mutation { bulkOperationRunQuery(query: """query { products(query: "updated_at:>'1999-12-31T23:00:00Z' AND published_status:published") {

 

bhavin_iflair
Shopify Partner
9 1 3

Yes getting same error and it is fixed by removing all the new lines. You are right!

trevor_morehead
Shopify Partner
3 0 0

Same, luckily we have the ability to supply hotfix DLL drops for our software.

Has anyone from Shopify posted anything on why this has happened?  A rollback plan? or something?

Liam
Community Manager
3108 344 911

Hi Robert,

Are you still seeing this issue? Connecting with our team on this now.

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

RobertTres
Tourist
4 0 7

Hi Liam,
I just checked and all the queries work again! 
Did you already fix the problem?

Liam
Community Manager
3108 344 911

This is an accepted solution.

Hi again Robert - it's possible this was a temporary bug on our side and may have already been resolved. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

RobertTres
Tourist
4 0 7

Hi Liam, 
Thanks for looking into it! 

Mickeydtails
Shopify Partner
13 1 15

@Liam I did a quick test and the problem seem to have disappeared. Thanks

 

trevor_morehead
Shopify Partner
3 0 0

I just re-tested our integration and still seeing the same issue

We do have a work around, removing newlines in the status query, however this has worked for a long time and just stopped working last week.

trevor_morehead
Shopify Partner
3 0 0

Update: The error we now get with the newlines is now: "Internal_Server_Error" instead of the unexpected invalid token (\"\\\"\") at [2, 32]  type error