Skip to content

Conversation

@GauBen
Copy link
Member

@GauBen GauBen commented Oct 28, 2025

Description

Small new feature!

This PR introduces typed GraphQL document support for our useGQLQuery server hook, without removing support for raw queries.

  • Previous usage, unsafe

    const { data, errors } = useGQLQuery({
      query: "query { ... }",
      variables: { /* not typed */ }
    })
    // data is typed `any`
  • New usage, with gql.tada

    import { graphql } from "gql.tada"
    const { data, errors } = useGQLQuery({
      query: graphql("query { ... }"),
      variables: { /* typed */ }
    })
    // data is properly typed

    It works with any library that produces a TypedDocumentNode (added some examples in the readme)

    Usage in Luxe:

    image image

Checklist

Source code

  • I've shared and documented any breaking change
  • I've reviewed and updated the jahia-depends

Tests

  • I've provided Unit and/or Integration Tests
  • I've updated the parent issue with required manual validations

Tip

Documentation to guide the reviews: How to do a code review

@GauBen GauBen requested a review from a team as a code owner October 28, 2025 11:28
Copilot AI review requested due to automatic review settings October 28, 2025 11:28
@GauBen GauBen self-assigned this Oct 28, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for typed GraphQL documents via TypedDocumentNode to the useGQLQuery hook while maintaining backward compatibility with string queries. The implementation enables type-safe GraphQL queries when used with libraries like gql.tada or GraphQL Codegen, providing typed variables and return data.

Key Changes:

  • Added function overloads to useGQLQuery to support both string queries and TypedDocumentNode with proper type inference
  • Added @0no-co/graphql.web and @graphql-typed-document-node/core as optional peer dependencies
  • Updated documentation with examples of compatible GraphQL type generation tools

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
javascript-modules-library/src/hooks/useGQLQuery.ts Added function overloads and runtime support for TypedDocumentNode with type parameter inference
javascript-modules-library/package.json Added graphql.web and typed-document-node dependencies as optional peer dependencies
javascript-modules-library/README.md Added documentation about typed document node support and compatible tooling
javascript-modules-engine/tests/cypress/e2e/ui/gqlTest.cy.ts Updated test assertions to verify typed document node functionality
jahia-test-module/src/react/server/views/testGQL/TestGQL.tsx Added test case demonstrating usage with parsed GraphQL documents
jahia-test-module/package.json Added graphql dependency for test module

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@baptistegrimaud baptistegrimaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Idea for the future: when creating a new JS module with @jahia/create-module, should we let the developer opt in or out for typed GraphQL document? As interacting with Jahia GraphQL APIs is fairly common for customers.

@GauBen
Copy link
Member Author

GauBen commented Oct 30, 2025

Testing fully covered by automated tests

@GauBen GauBen merged commit 84d8a30 into main Oct 30, 2025
29 checks passed
@GauBen GauBen deleted the feat/typed-graphql branch October 30, 2025 08:31
@Fgerthoffert Fgerthoffert added this to the javascript-modules-1.1.0 milestone Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants