Skip to content

Commit

Permalink
Fix TypeScript types for flattenConnection (#945)
Browse files Browse the repository at this point in the history
* Fix TypeScript types for flattenConnection

* update docs
  • Loading branch information
frehner committed May 25, 2023
1 parent 967870c commit 7d6a1a7
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 71 deletions.
6 changes: 6 additions & 0 deletions .changeset/fuzzy-eels-smell.md
@@ -0,0 +1,6 @@
---
'@shopify/hydrogen-react': patch
'@shopify/hydrogen': patch
---

Fix `flattenConnection()`'s TypeScript types when working with `edges.node`
76 changes: 38 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -6054,14 +6054,14 @@
"filePath": "/flatten-connection.ts",
"syntaxKind": "TypeAliasDeclaration",
"name": "ConnectionEdges",
"value": "{\n edges: {node: Array<unknown>};\n}",
"value": "{\n edges: Array<{node: unknown}>;\n}",
"description": "",
"members": [
{
"filePath": "/flatten-connection.ts",
"syntaxKind": "PropertySignature",
"name": "edges",
"value": "{ node: unknown[]; }",
"value": "{ node: unknown; }[]",
"description": ""
}
]
Expand Down
101 changes: 77 additions & 24 deletions packages/hydrogen-react/docs/generated/generated_static_pages.json
@@ -1,19 +1,19 @@
[
{
"title": "Hydrogen React",
"description": "Hydrogen React is an unopinionated and performant library of Shopify-specific React components, reusable functions, and utilities for interacting with the Storefront API. This guide provides a complete reference of the components, hooks, and utilities that Hydrogen React offers, and their relationships to each other.",
"description": "Hydrogen React is a performant, framework-agnostic library of React components, reusable functions, and utilities for interacting with Shopify’s [Storefront API](/docs/api/storefront). It’s bundled with [Hydrogen](/docs/api/hydrogen), but can be used by any React-based web app.",
"id": "hydrogen-react",
"sections": [
{
"type": "Generic",
"anchorLink": "setup",
"title": "Setup",
"sectionContent": "\n1. Run one of the example commands to install the package\n1. Import the component, hook, or utility that you want to use in your app. For more detailed instructions, see the Getting Started Guide.\n ",
"sectionContent": "\n1. Install Hydrogen React in your project with your preferred package manager.\n1. Import components, hooks, or utilities that you want to use in your app. For more detailed instructions, see the Getting Started guide.\n ",
"sectionCard": [
{
"subtitle": "Navigate to",
"name": "Getting Started Guide",
"url": "/custom-storefronts/hydrogen-react#get-started-with-hydrogen-react",
"subtitle": "Tutorial",
"name": "Getting Started with Hydrogen React",
"url": "/docs/custom-storefronts/hydrogen-react",
"type": "tutorial"
}
],
Expand All @@ -35,27 +35,60 @@
"type": "Generic",
"anchorLink": "authentication",
"title": "Authentication",
"sectionContent": "\n To use Hydrogen React, you need to authenticate with and make requests to the [Storefront API](/api/storefront-api). Refer to [Get started with Hydrogen React](/custom-storefronts/hydrogen-react#get-started-with-hydrogen-react) for instructions on how to get an access token and set up the Storefront API client.\n ",
"sectionContent": "To use Hydrogen React, you need to authenticate with and make requests to the [Storefront API](/docs/api/storefront). Hydrogen React includes an [API client](/docs/api/hydrogen-react/current/utilities/createstorefrontclient) to securely handle API queries and mutations.\n\nYou can create and manage Storefront API access tokens by installing the [Headless sales channel](https://apps.shopify.com/headless) on your store.\n\nApps have access to [two kinds of tokens](/docs/api/usage/authentication#access-tokens-for-the-storefront-api): a public API token, which can be used in client-side code, and a private API token, which should only be used in server-side contexts and never exposed publicly.",
"sectionCard": [
{
"subtitle": "Navigate to",
"name": "Enable Storefront API Access",
"url": "/custom-storefronts/hydrogen-react#step-2-enable-storefront-api-access",
"type": "key"
"subtitle": "Install",
"name": "Headless sales channel",
"url": "https://apps.shopify.com/headless",
"type": "apps"
}
]
],
"codeblock": {
"title": "Authenticate a Hydrogen app",
"tabs": [
{
"title": "client.js",
"code": "import {createStorefrontClient} from '@shopify/hydrogen-react';\n\nexport const client = createStorefrontClient({\n // load environment variables according to your framework and runtime\n storeDomain: process.env.PUBLIC_STORE_DOMAIN,\n storefrontApiVersion: process.env.PUBLIC_STOREFRONT_API_VERSION,\n publicStorefrontToken: process.env.PUBLIC_STOREFRONT_API_TOKEN,\n});\n",
"language": "javascript"
},
{
"title": ".env",
"code": "# Replace with your own store domain and Storefront API token\n\nPUBLIC_STOREFRONT_API_TOKEN=\"public_token\"\nPRIVATE_STOREFRONT_API_TOKEN=\"private_token\"\nPUBLIC_STOREFRONT_API_VERSION=\"2023-04\"\nPUBLIC_STORE_DOMAIN=\"store_id.myshopify.com\"\n"
},
{
"title": "server-side-query.js",
"code": "import {client} from './client.js';\n\nexport async function getServerSideProps() {\n const response = await fetch(client.getStorefrontApiUrl(), {\n body: JSON.stringify({\n query: GRAPHQL_QUERY,\n }),\n // Generate the headers using the private token.\n headers: client.getPrivateTokenHeaders(),\n method: 'POST',\n });\n\n if (!response.ok) {\n throw new Error(response.statusText);\n }\n\n const json = await response.json();\n\n return {props: json};\n}\n\nconst GRAPHQL_QUERY = `\n query {\n shop {\n name\n }\n }\n`;\n",
"language": "javascript"
}
]
}
},
{
"type": "Generic",
"anchorLink": "versioning",
"title": "Versioning",
"sectionContent": "Hydrogen React is tied to specific versions of the [Storefront API](/api/storefront). For example, if you're using Storefront API version `2023-01`, then Hydrogen React versions `2023.1.x` are fully compatible. \n\n >Caution: \n>If the Storefront API version update includes breaking changes, then Hydrogen React includes breaking changes. Because the API version is updated every three months, breaking changes to Hydrogen React could occur every three months. \n\n Learn more about [API versioning](/api/usage/versioning)."
"sectionContent": "Hydrogen React is tied to specific versions of the [Storefront API](/docs/api/storefront), which is versioned quarterly. For example, if you're using Storefront API version `2023-04`, then Hydrogen versions `2023.4.x` are fully compatible.\n\n> Caution:\n>If a Storefront API version includes breaking changes, then the corresponding Hydrogen React version will include the same breaking changes.",
"sectionCard": [
{
"subtitle": "Learn more",
"name": "Shopify API versioning",
"url": "/docs/api/usage/versioning",
"type": "tutorial"
},
{
"subtitle": "Learn more",
"name": "API release notes",
"url": "/docs/api/release-notes",
"type": "changelog"
}
]
},
{
"type": "Generic",
"anchorLink": "components",
"title": "Components",
"sectionContent": "A component encapsulates all of the business logic and data parsing/processing for the concept it represents and outputs limited, sensible markup. Components provide defaults, but allow customizations and provide no visual styles, other than those provided natively by the browser.",
"sectionContent": "Components include all the business logic and data parsing required to produce predictable markup for objects available through the Storefront API. Components provide defaults but can be customized. Hydrogen React components include no visual styles, other than the ones provided natively by browsers.",
"codeblock": {
"title": "Component example",
"tabs": [
Expand All @@ -71,7 +104,7 @@
"type": "Generic",
"anchorLink": "hooks",
"title": "Hooks",
"sectionContent": "Hooks are functions that provide reusable, business and/or stateful logic. These functions allow you to leverage the business logic and state management functions used in the components with more flexibility.",
"sectionContent": "Hooks are functions that provide reusable business and/or state logic. They give you additional flexibility to control the behavior and display of Hydrogen React components.",
"codeblock": {
"title": "Hook example",
"tabs": [
Expand All @@ -87,7 +120,7 @@
"type": "Generic",
"anchorLink": "utilities",
"title": "Utilities",
"sectionContent": "Utilities are reusable functions for common data manipulations performed on Storefront API data.",
"sectionContent": "Utilities are reusable functions for common manipulations performed on data returned from the Storefront API.",
"codeblock": {
"title": "Utility example",
"tabs": [
Expand All @@ -99,27 +132,47 @@
]
}
},
{
"type": "Generic",
"anchorLink": "with_hydrogen",
"title": "How Hydrogen React works with Hydrogen",
"sectionContent": "Hydrogen React is bundled as part of Hydrogen, Shopify’s opinionated headless commerce stack built on [Remix](https://remix.run). Hydrogen React is also published separately as a standalone package so that it can be used by other React-based frameworks.\n\nHydrogen adds features like standard routes, caching strategies, redirects, and SEO. When using Hydrogen, you can also install the Hydrogen sales channel, which includes built-in support for Oxygen, Shopify’s global edge hosting platform. Consider which approach works best for your use case and existing technology stack.",
"sectionCard": [
{
"subtitle": "Learn more",
"name": "Hydrogen",
"url": "/docs/custom-storefronts/hydrogen",
"type": "tutorial"
},
{
"subtitle": "Install",
"name": "Hydrogen sales channel",
"url": "https://apps.shopify.com/hydrogen",
"type": "hydrogen"
}
]
},
{
"type": "Resource",
"anchorLink": "resources",
"title": "Resources",
"resources": [
{
"name": "Custom Storefronts",
"subtitle": "Learn more about how to design, build, and manage, your custom storefront.",
"name": "Custom storefronts on Shopify",
"subtitle": "Learn more about how to design, build, and manage custom storefronts on Shopify.",
"url": "/custom-storefronts",
"type": "custom-storefronts"
},
{
"name": "Getting started guide",
"subtitle": "Follow this tutorial to get started with Hydrogen React.",
"url": "/custom-storefronts/hydrogen-react#get-started-with-hydrogen-react",
"type": "quickstart"
"name": "Hydrogen on Discord",
"subtitle": "Chat with the growing community of commerce developers building with Hydrogen.",
"url": "https://discord.gg/shopifydevs",
"type": "discord"
},
{
"name": "Hydrogen React README",
"subtitle": "Get more details on how to improve your end-to-end development experience.",
"url": "https://github.com/Shopify/hydrogen/blob/main/packages/hydrogen-react/README.md",
"name": "Hydrogen on GitHub",
"subtitle": "Follow the Hydrogen project, file bugs and feature requests, preview upcoming features, and more.",
"url": "https://github.com/Shopify/hydrogen",
"type": "github"
}
]
Expand Down

0 comments on commit 7d6a1a7

Please sign in to comment.