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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

How to fix graphql parse error on $ using rails shopify_app gem?

Solved

How to fix graphql parse error on $ using rails shopify_app gem?

bmc121177
Shopify Partner
2 0 0

I'm using the shopify_app gem and trying to get multiple products using the graphql Admin API. I can hardcode product Id's and get a valid response. However, when using dynamic variables I get the error below in my terminal:

 

 

GraphQL::ParseError (Parse error on "$" (VAR_SIGN) at [2, 27]):

 

 

 

      get_order_products = ShopifyAPI::GraphQL.client.parse <<-'GRAPHQL'
      {
        query getProducts($ids: [ID!]!) {
        nodes(ids: $ids) {
          ... on Product {
            id
            title
            metafields(first: 5) {
              edges {
                node {
                  namespace
                  key
                  value
                }
              }
            }
          }
        }
       }
      }
      GRAPHQL

      {
          "ids": ["gid://shopify/Product/abc123", "gid://shopify/Product/abc456"]
      }

     @result = ShopifyAPI::GraphQL.client.query(get_order_products)

 

 

I'm new to graphql but would have expected this to work based on this shopify community forum post][1]

Accepted Solution (1)

awwdam
Shopify Staff
249 42 39

This is an accepted solution.

Hey @bmc121177

I did some testing with this query using an API Client and received the same type of error, so I would not expect the issues to be with the the application specifically, and instead the formatting.

The example above appears to have a an extra set of { } curly brackets before and after the query. Based on what was shared, and using our Shopify GraphiQL Explorer  - I was able to successfully format and complete the following request with no error (input variables used returned from the explorer):

 

 

query GetProductMetafields($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on Product {
      id
      title
      metafields(first: 5) {
        edges {
          node {
            namespace
            key
            value
          }
        }
      }
    }
  }
}

Input:
{
  "ids": [
    "gid://shopify/Product/1974208364566",
    "gid://shopify/Product/1974208397334"
  ]
}

 

 

My suggestions would be to take a closer look at how this app is building or formatting the request body, ideally using the raw request output as a starting point!

Hope this helps - Cheers!

awwdam | API Support @ 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

Reply 1 (1)

awwdam
Shopify Staff
249 42 39

This is an accepted solution.

Hey @bmc121177

I did some testing with this query using an API Client and received the same type of error, so I would not expect the issues to be with the the application specifically, and instead the formatting.

The example above appears to have a an extra set of { } curly brackets before and after the query. Based on what was shared, and using our Shopify GraphiQL Explorer  - I was able to successfully format and complete the following request with no error (input variables used returned from the explorer):

 

 

query GetProductMetafields($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on Product {
      id
      title
      metafields(first: 5) {
        edges {
          node {
            namespace
            key
            value
          }
        }
      }
    }
  }
}

Input:
{
  "ids": [
    "gid://shopify/Product/1974208364566",
    "gid://shopify/Product/1974208397334"
  ]
}

 

 

My suggestions would be to take a closer look at how this app is building or formatting the request body, ideally using the raw request output as a starting point!

Hope this helps - Cheers!

awwdam | API Support @ 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