Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-source-shopify): Add shopifyShop query #25763

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/gatsby-source-shopify/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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__",
},
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "shop": { "description": "", "name": "", "moneyFormat": "" } }
1 change: 1 addition & 0 deletions packages/gatsby-source-shopify/src/constants.js
Original file line number Diff line number Diff line change
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`
PaulieScanlon marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,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