Metaobject query search - Can't get the same result as graphiql

anhdd_kuro
Tourist
5 0 0

I'm attempting to retrieve metaobjects filtered by their display_name. Here is my GraphQL query:

 

query GetMetaobjects {
  metaobjects(
      first: 250
      query: "display_name:\"*⑭公開日未設定作品(ONE SHOT CINEMA 近日公開作品)*\""
      type: "custom"
) {
     nodes {
       id
       displayName
     }
  }
}
I receive the expected result when testing it with the local GraphiQL, indicating that it uses the same scopes as the app. However, when I actually call the API inside my Remix app like this:

 

const graphqlQuery = `#graphql
query GetMetaobjects($query: String, $first: Int = 200) {
metaobjects(
  first: $first
  type: "custom"
  query: $query
) {
    nodes {
      __typename
      id
      display_name
    }
  }
}
`
 
const response = await admin.graphql(graphqlQuery, {
  variables: {
    query:  `display_name:"*${name}*"`,
  },
})

 

The result becomes empty. I have tried variations such as
`display_name:"*${name}*"`
`display_name:\\"*${name}*\\"` `display_name:\"*${name}*\"`

but I still can't get the same result; it's all empty.

I believe the issue lies in the escape special character part, but what did I miss?

Replies 2 (2)

morishin
Shopify Partner
8 0 4

I have also encountered this issue.

anhdd_kuro
Tourist
5 0 0

I'm currently resolve it by using single quote and sting combine ( not template literal using back quote )

instead of 

 

`display_name:"*${name}*"`

 

 do

 

'display_name:' + '"' + '*${name}*' + '"'

 

 and it working as expected , still don't know why 😅 hope it help