Skip to content

Commit

Permalink
feat(gatsby-source-shopify): Add shopifyShop query (#25763)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulieScanlon committed Jul 20, 2020
1 parent 5f54f76 commit 16ee206
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/gatsby-source-shopify/README.md
Expand Up @@ -148,6 +148,7 @@ The following data types are available:
| **ProductOption** | Custom product property names. |
| **ProductVariant** | Represents a different version of a product, such as differing sizes or differing colors. |
| **ShopPolicy** | Policy that a merchant has configured for their store, such as their refund or privacy policy. |
| **ShopDetails** | Name, Description and Currency that a merchant has configured for their store. |

For each data type listed above, `shopify${typeName}` and
`allShopify${typeName}` is made available. Nodes that are closely related, such
Expand Down Expand Up @@ -389,6 +390,20 @@ Shopify merchants can create pages to hold static HTML content.
}
```

### Query shop details

Shopify merchants can give their shop a name, description and a money format.

```graphql
{
shopifyShop {
name
description
moneyFormat
}
}
```

### Image processing

To use image processing you need `gatsby-transformer-sharp`,
Expand Down
Expand Up @@ -2947,5 +2947,17 @@ Object {
],
"vendor": "Gatsby Swag",
},
"Shopify__Shop__undefined": Object {
"children": Array [],
"description": "",
"id": "Shopify__Shop__undefined",
"internal": Object {
"contentDigest": "7e8bd622d5376313766d087914010149",
"type": "ShopifyShop",
},
"moneyFormat": "",
"name": "",
"parent": "__SOURCE__",
},
}
`;
@@ -0,0 +1 @@
{ "shop": { "description": "", "name": "", "moneyFormat": "" } }
1 change: 1 addition & 0 deletions packages/gatsby-source-shopify/src/constants.js
Expand Up @@ -12,6 +12,7 @@ export const PRODUCT_VARIANT = `ProductVariant`
export const PRODUCT_METAFIELD = `ProductMetafield`
export const PRODUCT_VARIANT_METAFIELD = `ProductVariantMetafield`
export const SHOP_POLICY = `ShopPolicy`
export const SHOP_DETAILS = `Shop`
export const PAGE = `Page`
export const SHOP = `shop`
export const CONTENT = `content`
Expand Down
24 changes: 24 additions & 0 deletions packages/gatsby-source-shopify/src/gatsby-node.js
Expand Up @@ -15,6 +15,7 @@ import {
ProductMetafieldNode,
ProductVariantMetafieldNode,
ShopPolicyNode,
ShopDetailsNode,
PageNode,
} from "./nodes"
import {
Expand All @@ -26,6 +27,7 @@ import {
COLLECTION,
PRODUCT,
SHOP_POLICY,
SHOP_DETAILS,
PAGE,
} from "./constants"
import {
Expand All @@ -34,6 +36,7 @@ import {
COLLECTIONS_QUERY,
PRODUCTS_QUERY,
SHOP_POLICIES_QUERY,
SHOP_DETAILS_QUERY,
PAGES_QUERY,
} from "./queries"

Expand Down Expand Up @@ -64,6 +67,7 @@ export const sourceNodes = async (
collections: COLLECTIONS_QUERY,
products: PRODUCTS_QUERY,
shopPolicies: SHOP_POLICIES_QUERY,
shopDetails: SHOP_DETAILS_QUERY,
pages: PAGES_QUERY,
}

Expand Down Expand Up @@ -130,6 +134,7 @@ export const sourceNodes = async (
)
}),
createShopPolicies(args),
createShopDetails(args),
])
}
if (includeCollections.includes(CONTENT)) {
Expand Down Expand Up @@ -188,6 +193,25 @@ const createNodes = async (
if (verbose) console.timeEnd(msg)
}

/**
* Fetch and create nodes for shop policies.
*/
const createShopDetails = async ({
client,
createNode,
formatMsg,
verbose,
queries,
}) => {
// // Message printed when fetching is complete.
const msg = formatMsg(`fetched and processed ${SHOP_DETAILS} nodes`)

if (verbose) console.time(msg)
const { shop } = await queryOnce(client, queries.shopDetails)
createNode(ShopDetailsNode(shop))
if (verbose) console.timeEnd(msg)
}

/**
* Fetch and create nodes for shop policies.
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-source-shopify/src/nodes.js
Expand Up @@ -14,6 +14,7 @@ import {
PRODUCT_METAFIELD,
PRODUCT_VARIANT_METAFIELD,
SHOP_POLICY,
SHOP_DETAILS,
PAGE,
} from "./constants"

Expand Down Expand Up @@ -174,4 +175,6 @@ export const ProductVariantMetafieldNode = _imageArgs =>

export const ShopPolicyNode = createNodeFactory(SHOP_POLICY)

export const ShopDetailsNode = createNodeFactory(SHOP_DETAILS)

export const PageNode = createNodeFactory(PAGE)
10 changes: 10 additions & 0 deletions packages/gatsby-source-shopify/src/queries.js
Expand Up @@ -231,6 +231,16 @@ export const PRODUCTS_QUERY = `
}
`

export const SHOP_DETAILS_QUERY = `
query GetShop {
shop {
description
moneyFormat
name
}
}
`

export const SHOP_POLICIES_QUERY = `
query GetPolicies {
shop {
Expand Down

0 comments on commit 16ee206

Please sign in to comment.