Hygraph Examples

repository·master·Indexed 20 days ago

https://github.com/hygraph/hygraph-examples

A collection of example projects for Hygraph, covering Content API features (Asset Upload, Management SDK, Mutations, Pagination, Rich Text Rendering, Union Types), framework integrations (React, Next.js, Gatsby, Vue.js, Nuxt.js, SvelteKit, Astro, Eleventy, Swift), and UI Extensions such as uix-autofill-relation, uix-basic-input, uix-cloudinary-input, uix-focal-point-input, uix-bynder-input, and uix-conditional-field.

Tokens
56.1K
Snippets
216
Records
247
Agent score
69%

What's inside hygraph-examples

  1. Pagination patterns in Hygraph

    master

    This example demonstrates two primary patterns for handling paginated data from Hygraph queries:

    1. Generating numbered static pages: Uses a total count and a 'per page' limit to generate a specific number of static pages (e.g., /products/1, /products/2). This is implemented in src/pages/products/[page].js.
    2. Handling larger result sets: Hygraph has a default result set size of 100 entries (which can be increased up to 1000). To retrieve all data matching a query that exceeds these limits, you can use a for await statement to loop through requests until all data is returned. This is implemented in src/pages/index.js.

    This implementation uses Next.js and graphql-request.

  2. Key features of the Hygraph Swift implementation

    master

    The Swift implementation for Hygraph provides the following capabilities:

    • Native Swift await/async: Uses modern Swift concurrency for handling asynchronous GraphQL requests.
    • SwiftUI: The user interface is built using the SwiftUI framework.
    • swift-graphql: Uses the swift-graphql library to execute GraphQL queries and mutations.
    • Codable objects: GraphQL response data is mapped to Swift objects using the Codable protocol for easy data handling.
  3. Programmatically build a project schema with the Hygraph Management SDK

    master

    This example demonstrates how to use the @hygraph/management-sdk to define and create models and field types via code.

    In this specific implementation, the SDK is used to create a schema containing:

    Blog Post Model

    • Title
    • Excerpt (configured with a multi-line form renderer)
    • Content (configured as Rich Text)
    • Author (a field linked to the Author model)

    Author Model

    • Name
    • Posts (a one-to-many relationship back to Blog Posts)
  4. Hygraph Content API Features & Recipes

    master

    This repository contains several examples demonstrating how to implement specific Hygraph Content API features:

    • Asset Upload: Programmatically upload assets using the Asset Upload endpoint.
    • Management SDK: Scripts for creating schemas, including examples using Remote Fields to query data from external APIs like Stripe.
    • Mutations: Demonstrations of using mutations in a Next.js application with graphql-request, SWR, and API routes.
    • Pagination: Examples of paginating Hygraph queries using graphql-request in Next.js.
    • Rich Text Rendering: How to render Rich Text content using @graphcms/rich-text-react-renderer in Next.js.
    • Union Types: Using union types to compose UI 'blocks' in a product marketing site built with Next.js, graphql-request, and Tailwind CSS.
  5. Features of the Hygraph x Swift implementation

    master

    The Hygraph x Swift example demonstrates modern Swift development patterns for interacting with Hygraph via GraphQL:

    • Native Swift await/async: Uses structured concurrency for asynchronous operations.
    • SwiftUI: Built using the SwiftUI declarative framework for the user interface.
    • URLSession based GraphQL calls: Performs network requests using standard URLSession without heavy external dependencies.
    • Codable objects: Uses Swift's Codable protocol to map GraphQL responses directly to native Swift types.
  6. Hygraph Frameworks & Libraries Integrations

    master

    The repository provides a wide range of integration examples for popular frameworks and libraries:

    Frontend Frameworks

    • React: Querying with graphql-request or React Query.
    • Next.js: Static site generation (getStaticProps/getStaticPaths), Internationalized (i18n) routing, Image component integration (including custom loaders), and MDX support.
    • Gatsby: Using gatsby-source-graphcms for product pages, File System Route API, Gatsby Image, and MDX integration.
    • Vue.js: Vanilla Vue.js starter with Vue Router.
    • Nuxt.js: Nuxt starter with Tailwind/Axios, and Nuxt 3 with nuxt-graphql-client.
    • SvelteKit: Fetching data with graphql-request or URQL, and Houdini integration.
    • Astro: Fetching data with graphql-request.
    • Eleventy: Fetching data with graphql-request.
    • Mobile: Native Swift (iOS & Mac) examples, including usage with swift-graphql.

    Other Integrations

    • Apollo: Using Apollo Client 3 for querying or Apollo Server with apollo-datasource-graphql to pull Hygraph schemas.
    • Search: Syncing content to Algolia via webhooks and Next.js API routes.
    • GraphQL Tooling: Generating types with GraphQL Code Generator and schema stitching with GraphQL Mesh.
    • Authentication: Integrating with NextAuth.js to update account info.
    • Vanilla JS: Using the native Fetch API in the browser.
  7. Hygraph UI Extensions Examples

    master

    These examples demonstrate how to extend the Hygraph UI with custom components using the UI Extensions API:

    • Quickstart (uix-basic-input): A basic React-based <input /> component.
    • Cloudinary (uix-cloudinary-input): A custom React component for picking Cloudinary assets.
    • Focal Point (uix-focal-point-input): A JavaScript-based custom focal point picker.
    • Bynder (uix-bynder-input): A JavaScript-based component to browse assets from Bynder using the Compact View V2 component.
    • Conditional Fields (uix-conditional-field): A TypeScript-based extension to manage field visibility and use fieldConfig.
  8. Concept: Using Remote Fields to query external APIs

    master

    Remote Fields allow you to extend your Hygraph schema by querying data from external services directly within your GraphQL queries.

    In this example, a PricingPlan model is created that uses a Remote Field to fetch product and price data from the Stripe API instead of storing that data locally in Hygraph. This is achieved programmatically using the Hygraph Management SDK to build the project schema.