Warm tip: This article is reproduced from serverfault.com, please click

Shopify GraphQL partial matching on query filter

发布于 2018-08-08 08:48:33

I'm just getting started with the new Shopify GraphQL Admin API. I'm trying to retreive all products, where the title field contains a certain word.

Currently I can successfully retrieve a product by including the full product title (exact match):

{
  shop {
    id
    name
  }
  products(first: 10, query:"title:'RAVEN DUSTY OLIVE/SILVER MESH'") {
    edges {
      node {
        productType
        title
      }
    }
  }
}

However, I want to partially match the title to display all products with the word "Raven" anywhere in the title, but the following returns no results:

{
  shop {
    id
    name
  }
  products(first: 10, query:"title:'RAVEN'") {
    edges {
      node {
        productType
        title
      }
    }
  }
}

Any ideas on how to get the partial matching working?

Questioner
Bjorn Forsberg
Viewed
0
Ryan Ormsby 2018-08-13 23:14:39

Bjorn! This should work:

{
  shop {
    id
    name
  }
  products(first: 10, query:"title:RAVEN*") {
    edges {
      node {
        productType
        title
      }
    }
  }
}

Check out the docs: https://help.shopify.com/en/api/getting-started/search-syntax