Solved

GraphQL Shop Policies

bradgarropy
Tourist
9 0 5

I'm using the Shopify GraphQL Admin API to retrieve my Shop Policies.

  • Refund Policy
  • Privacy Policy
  • Terms of Service
  • Shipping Policy

I've installed the Shopify GraphiQL App and I'm unable to retrieve any of the shop policies. I've granted full read access to all scopes of the API.

 

My query looks like this;

{
    shop {
        privacyPolicy {
            body
            id
            title
            url
        }
        refundPolicy {
            body
            id
            title
            url
        }
        shippingPolicy {
            body
            id
            title
            url
        }
        termsOfService {
            body
            id
            title
            url
        }
    }
}

Response is as follows:

{
  "errors": [
    {
      "message": "Field 'privacyPolicy' doesn't exist on type 'Shop'",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "fields": [
        "query",
        "shop",
        "privacyPolicy"
      ]
    },
    {
      "message": "Field 'refundPolicy' doesn't exist on type 'Shop'",
      "locations": [
        {
          "line": 9,
          "column": 5
        }
      ],
      "fields": [
        "query",
        "shop",
        "refundPolicy"
      ]
    },
    {
      "message": "Field 'shippingPolicy' doesn't exist on type 'Shop'",
      "locations": [
        {
          "line": 15,
          "column": 5
        }
      ],
      "fields": [
        "query",
        "shop",
        "shippingPolicy"
      ]
    },
    {
      "message": "Field 'termsOfService' doesn't exist on type 'Shop'",
      "locations": [
        {
          "line": 21,
          "column": 5
        }
      ],
      "fields": [
        "query",
        "shop",
        "termsOfService"
      ]
    }
  ]
}

Anyone know what's up?

Accepted Solution (1)
KarlOffenberger
Shopify Partner
1873 184 900

This is an accepted solution.

In Gatsby you can use multiple sources i.e. have the Shopify source for the bulk of data and use the gatsby-source-graphql or gatsby-source-api to use Shopify GraphQL Admin API or REST Admin API respectively. Using admin APIs in this case would make sense and be safe given that Gatsby build-time SSB. With the source-api plugin, you could also use the storefront itself (the one hosted by Shopify with good ol' Liquid) as that comes with some nifty data endpoints too and you can make your own "faux" data endpoints as shown above - these come in handy as Storefront API will at times be a dead end.

View solution in original post

Replies 7 (7)

Alex_B
Shopify Staff
56 4 29

Hey @bradgarropy !

 

The Shop object in the GraphQL Admin API doesn't have these fields.

However, the Shop object in the GraphQL Storefront API has all of these, minus shippingPolicy.

 

If you're using the Shopify GraphiQL App from our GraphQL Admin API Explorer docs, it will only have access to the admin side of things.

 

To see the GraphQL Storefront API in action, you can check out the in-browser demo we have in the GraphQL Storefront API Explorer docs.

 

These are two different APIs, both accessible with GraphQL.

It can be a little unclear which API a particular doc is referring to, especially since we use the same "GraphQL explorer" terminology for both.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

bradgarropy
Tourist
9 0 5

Great answer @Alex_B, thank you!

 

So if the GraphQL Storefront API does not provide access to the Shipping Policy, what API can I use to fetch that data?

Alex_B
Shopify Staff
56 4 29

Hey @bradgarropy 

 

You can also access all the policies directly through the REST Admin API's policies.json endpoint.

Your app can use the same token/authorization to access both the GraphQL and REST admin APIs, so this is probably easier than trying to also get a storefront access token.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

bradgarropy
Tourist
9 0 5

@Alex_B,

Is there any plan to add Shipping Policy to the GraphQL Storefront API? Seems like a natural fit there alongside the other policies.

 

Just asking because I'm using Gatsby to create an online store and the gatsby-source-shopify plugin uses only the GraphQL Storefront API to retrieve data.

KarlOffenberger
Shopify Partner
1873 184 900

This is an accepted solution.

In Gatsby you can use multiple sources i.e. have the Shopify source for the bulk of data and use the gatsby-source-graphql or gatsby-source-api to use Shopify GraphQL Admin API or REST Admin API respectively. Using admin APIs in this case would make sense and be safe given that Gatsby build-time SSB. With the source-api plugin, you could also use the storefront itself (the one hosted by Shopify with good ol' Liquid) as that comes with some nifty data endpoints too and you can make your own "faux" data endpoints as shown above - these come in handy as Storefront API will at times be a dead end.

bradgarropy
Tourist
9 0 5

@KarlOffenberger,

This is a great answer!

 

It looks like the GraphQL Admin API doesn't yet support Shop Policies.

So I'll go ahead and use the gatsby-source-apiserver plugin to pull in the Shop Policies from the REST Admin API.

 

Thank you everyone for your help!

KarlOffenberger
Shopify Partner
1873 184 900

Or in case you need this only for storefront, i.e. won't be using Admin APIs at all (for whatever reason) then you can create a no layout page template and 

 

{%- layout none -%}
{%- assign policy_url_parts = shop.shipping_policy.url | split: "/" -%}
{
{%- if shop.shipping_policy %}
  "shop": {
    "shippingPolicy": {
      "id": "{{ shop.shipping_policy.id }}",
      "handle": "{{ policy_url_parts.last }}",
      "title": "{{ shop.shipping_policy.title | escape }}",
      "body": "{{ shop.shipping_policy.body | escape }}",
      "url": "{{ shop.shipping_policy.url }}",
    }
  }
{% endif -%}
}

Bob's your uncle too 😉