Wp-graphql-woocommerce: Accessing meta_data product property?

Created on 10 Aug 2019  路  7Comments  路  Source: wp-graphql/wp-graphql-woocommerce

Do we have meta_data product property, much like WC REST API?

I have tried the following which works just fine, but I'm missing the meta_data product property...

{
  products {
    edges {
      node {
        sku
        name
        status
        manageStock
        regularPrice
        salePrice
        dateOnSaleFrom
        dateOnSaleTo
        stockQuantity
        taxClass
      }
    }
  }
}
design notes enhancement

Most helpful comment

@jasonbahl You mean something like this?

{
  products {
    edges {
      node {
        sku
        name
        status
        manageStock
        regularPrice
        salePrice
        dateOnSaleFrom
        dateOnSaleTo
        stockQuantity
        taxClass
        metaData {
            key {
                internalCode
                uom
            }
        }
    }
  }
}

The thing is, I want my metaData to return the values based on keys of my choice.

I hope it makes sense :thinking:

All 7 comments

Haven't implemented it yet, however I am putting this in the v0.2.1 milestone. I have implemented the MetaDataInput type to be used in Order and Checkout mutations, so this isn't far off.

@stefanos82 would it be possible for you do create a potential query? I'm still making decision what would work best for a meta data query.

When you say create a potential query? I barely know how to use GraphQL to be honest with you :disappointed:

@stefanos82 if you were to have a component that was asking for data, how would you expect that query to look?

Mocking the shape of Queries can help identify issues before implementation.

@jasonbahl You mean something like this?

{
  products {
    edges {
      node {
        sku
        name
        status
        manageStock
        regularPrice
        salePrice
        dateOnSaleFrom
        dateOnSaleTo
        stockQuantity
        taxClass
        metaData {
            key {
                internalCode
                uom
            }
        }
    }
  }
}

The thing is, I want my metaData to return the values based on keys of my choice.

I hope it makes sense :thinking:

@stefanos82 so since you want to filter by keys maybe something like.

{
  products {
    edges {
      node {
        sku
        name
        status
        manageStock
        regularPrice
        salePrice
        dateOnSaleFrom
        dateOnSaleTo
        stockQuantity
        taxClass
        metaData( keysIn: [ 'internalCode', 'uom' ] ) {
            key
            value
        }
    }
  }
}

and you would receive back an array that looks like this for the metaData field.

{
    metaData: [
        {
            "key": "internalCode",
            "value": "internalCodeValue"
        },
        {
            "key": "uom",
            "value": "uomValue"
        },
    ]
}

Any other suggestions?

I guess we need interoperability between REST API and WPGraphQL so there's a consistency between the two.

The same fields we see from WC REST API would be ideal to have (more or less with the same syntax) in WPGraphQL.

It would be nice to generate REST API keys and use them with WPGraphQL as well.

I'm asking such feature, because I have a customer with a POS system that I send its data on a live website via REST API.

It takes around 1.7-ish seconds though to create a batch of 10 products and I would like to drop that speed as low as possible with the help of GraphQL.

Just see how many unnecessary data it retrieves that I don't really need: retrieve a product

With GraphQL I'm sure it would improve exponentially and I can't wait to figure out how to make it reality.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

huniqcast picture huniqcast  路  4Comments

ardiewen picture ardiewen  路  3Comments

mehidi258 picture mehidi258  路  3Comments

jake-101 picture jake-101  路  7Comments

aresrioja10 picture aresrioja10  路  6Comments