skip to Main Content

I am specifically using the shopify graphql admin api to query orders.

I want to do a search for a nested related field.

Below is my query.

export const orderHistoryQuery = gql`
  query Order($productsFirst: Int!, $productsAfter: String, $filterQuery: String) {
    orders(first: $productsFirst, after: $productsAfter, reverse: true, query:$filterQuery) {
      edges {
        cursor
        node {
          id
          name
          customer {
            id
            metafields(first: 10) {
              edges {
                node {
                  id
                  key
                  value
                  namespace
                }
                cursor
              }
            }
          }
          totalPriceSet {
            shopMoney {
              amount
              currencyCode
            }
          }
          subtotalPriceSet {
            shopMoney {
              amount
              currencyCode
            }
          }
          totalRefundedSet {
            shopMoney {
              amount
              currencyCode
            }
          }
          currencyCode
          email
          phone
          processedAt
          totalShippingPriceSet {
            shopMoney {
              amount
              currencyCode
            }
          }
          totalTaxSet {
            shopMoney {
              amount
              currencyCode
            }
          }
          shippingAddress {
            firstName
            lastName
            address1
            address2
            city
            province
            zip
            country
          }
          billingAddress {
            firstName
            lastName
            address1
            address2
            city
            province
            zip
            country
          }
          customAttributes {
            key
            value
          }
        }
      }
    }
  }
`;

I want to query metafields or ANYTHING really but it doesn’t seem like it’s supported. I am not sure if I just have the wrong query syntax or if it’s not supported. The shopify search syntax documenation doesn’t really help and this is where my knowledge of graphql falls apart.

Is it possible to do this in graphql? I also tried adding metafields(id: $whateverID) which is not supported by their setup.

2

Answers


  1. You would really help your cause out by simplifying things. My advice to you is to try a simple query. Can you get an order? Since an order has a customer (usually but not always), can you get a metafield associated with that customer?

    You have so many obstacles in your attempt to show what you are trying to do, it is almost as if you want a migraine headache in trying to debug anything. GraphQL calls to endpoints are documented fairly well from the GraphQL website perspective, and Shopify is nothing but a vanilla implementation of that, with the caveat that they charge you for calls based on complexity, so you had best be monitoring your credits.

    So ya, try simple calls. Get a product and it’s Metafields. Get a customer record and it’s Metafields. If you can do that, you are not challenging the documentation much, nor the concept of GraphQL queries. Once a basic all works, you can work in variables, cursors, paging, etc… but until a one-off call gives you what you want, debugging should be concentrated on the simplest of calls, not everything and the kitchen sink.

    Also, when you screw up a call to the endpoint, Shopify usually returns a response with details about where you screwed up, providing you with a first place to look. We see nothing of your response, so there is little to go on to help you.

    Login or Signup to reply.
  2. Unfortunately, Shopify doesn’t support query filters on metafields. The best way to figure this out is by using a graphql explorer like GraphiQL. Shopify dashboard has this built in if you go to Apps > Shopify GraphiQL App.

    Using GraphiQL you can see that:

    1. Customers query doesn’t have metafields supported:
      customers query
    2. Orders query doesn’t have customers or metafields supported:
      orders query
    3. And metafields on customers doesn’t have a query param:
      metafields params

    I think your options are to either query by what you can and filter after you get the results or use a customer tag and query by tag.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search