Solved

GraphQL Shopify-Buy SDK retrieve available shipping rates with checkout

codemonkey
Excursionist
12 1 2

I'm attempting to use the Shopify Buy SDK to create a checkout and look up the available shipping rates for that checkout. How do I add the available shipping rates selection to the query? addConnection appears to be used for paginated data (like products, variants, or images). 

 

const query = this.client.graphQLClient.query((root) => {
  root.add('node', { args: {id: checkout_id} }, (node) => {
    node.add('id');
    node.addInlineFragmentOn('Checkout', (checkout) => {
      checkout.add('totalPrice');
      checkout.addConnection('availableShippingRates', (rate) => {
        rate.add('title');
      });
    });
  });
});

return this.client.graphQLClient.send(query).then(({ model, data }) => {
  return data;
});

gives me the error:

ERROR Error: Uncaught (in promise): Error: No field of name "pageInfo" found on type "AvailableShippingRates" in schema
Error: No field of name "pageInfo" found on type "AvailableShippingRates" in schema

 

Accepted Solution (1)

codemonkey
Excursionist
12 1 2

This is an accepted solution.

For those curious, here's what I found that works:

    const query = this.client.graphQLClient.query((root) => {
      root.add('node', { args: {id: checkout_id} }, (node) => {
        node.add('id');
        node.addInlineFragmentOn('Checkout', (checkout) => {
          checkout.add('totalTax');
          checkout.add('taxesIncluded');
          checkout.add('taxExempt');
          checkout.add('subtotalPrice');
          checkout.add('totalPrice');
          checkout.add('email');
          checkout.add('createdAt');
          checkout.add('webUrl');
          checkout.add('requiresShipping');
          checkout.add('availableShippingRates', (rates) => {
            rates.add('ready');
            rates.add('shippingRates', (rate) => {
              rate.add('title');
              rate.add('price');
              rate.add('handle');
            });
          });
        });
      });
    });

View solution in original post

Replies 3 (3)

codemonkey
Excursionist
12 1 2

This is an accepted solution.

For those curious, here's what I found that works:

    const query = this.client.graphQLClient.query((root) => {
      root.add('node', { args: {id: checkout_id} }, (node) => {
        node.add('id');
        node.addInlineFragmentOn('Checkout', (checkout) => {
          checkout.add('totalTax');
          checkout.add('taxesIncluded');
          checkout.add('taxExempt');
          checkout.add('subtotalPrice');
          checkout.add('totalPrice');
          checkout.add('email');
          checkout.add('createdAt');
          checkout.add('webUrl');
          checkout.add('requiresShipping');
          checkout.add('availableShippingRates', (rates) => {
            rates.add('ready');
            rates.add('shippingRates', (rate) => {
              rate.add('title');
              rate.add('price');
              rate.add('handle');
            });
          });
        });
      });
    });
Cleankitchen
Shopify Partner
13 1 5

@codemonkey is this solution still working for you?

It was working fine for us as well, but for the last couple of weeks, it's not returning any shippingRates.

kneeki
Shopify Partner
23 2 4

@Cleankitchen I actually ended up switching to Apollo GraphQL client so I'm unsure if this solution works any longer.

---