Making GraphQL supports @inContext Directive?

Hello,

I’m trying to build a metaobject listing page with some simple filtering functionality. The issue here I’m facing is that, the @inContext Directive only works with Storefront API but only the Admin API works with the query argument. Is there any workaround to to build a filterable + translatable metaobject listing page with one fetch?

Thanks,
Will

Hi @willwongco,

I can confirm that only the Storefront API works with the @inContext Directives, however the query argument filters are available on both the Admin and the Storefront APIs, but not for all queries. The query argument is implemented on a case by cases basis per API query.

Can you provide us with some more context on what you are trying to do exactly, and some details on the API calls you are currently using, and the ones that are insufficient for your use case, and we can definitely help look into it further and see if there’s any available workarounds.

Hi @willwongco,

I just wanted to reach out and see if you needed any further help with this still? If you can share any further questions or context into what you’re wanting to do exactly, we can help look into it and offer any potential solutions or workarounds possible. Otherwise we can go ahead and mark this thread as solved if you don’t need any further help with this.

Hello @Kellan-Shopify ,

To provide a bit more context, we’d like to retrieve a list of metaobject and filter them basing on field value with GraphQL. However it doesn’t seem to be possible with Storefront API. I’m getting the following error when I try to add a “query” object into the “variables”:
Field 'metaobjects' doesn't accept argument 'query'

Looking at the documentation here, it also looks like only the Admin API takes the “query” arguement and we’d love to have it for the Storefront API too:

Thanks,
Will

You’re probably best just retrieving them all for now and filtering on client-side.

It’s not a scalable solution tho and you can only retrieve 250 at a time.

You most likely won’t be getting the query argument anytime soon though, so I’ve provided you with an alternative.

Hi @willwongco,

I can confirm that it is expected behaviour at this time to only be able to filter metafields and metaobjects by namespace or field on the Admin API.

This is mentioned in the Shopify.dev documentation regarding metafield capabilities:

  • adminFilterable: Filter supported owner types based on metafield values for a definition in the Shopify admin and GraphQL Admin API.

The best workaround to this limitation, would be to simply use the Admin API to query and filter metaobjects directly instead of the Storefront API, alternatively as @Luke mentioned you can query for all metaobjects via the Storefront API and then filter the results on your end as well.

I understand this may not be ideal for your workflow and I will be submitting some feedback internally on your behalf that you’d like to see metaobject field filtering available on the Storefront API as well.

While I can’t guarantee when or if it would be added, I can assure you we do take all of our merchant and partner feedback with great value when determining future features and platform updates, and the more requests we get for features like these, the more likely and quicker it would be added.

Hi @Kellan-Shopify,

Can we at least have the GraphQL Admin API available from Theme JS somehow?

Thanks,
Will

You’ll need to create your own endpoint that hits it. And feed it through an app proxy.

1 Like

Hi @willwongco,

As @Luke mentioned above, you will need to use App Proxies if you want to make an API request through the storefront using javascript.

This would work as such:

  1. You’d setup a Back End App that has access to the Admin API.
  2. You setup an App Proxy with the Back End App.
  3. On the storefront you make a request to your back end via the App Proxy.
  4. The back end app receives the request and then makes any external requests needed, including Admin API requests.
  5. The Back End App responds to the original proxy request, with any data that the storefront needs retrieved from the Admin API call it made previously.

Here’s some Shopify.dev documentation that explains this further: