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

Feature Request: Add GraphQL Query Wrapper to Storyblok JS Client #872

Open
edodusi opened this issue Nov 19, 2024 · 0 comments
Open

Feature Request: Add GraphQL Query Wrapper to Storyblok JS Client #872

edodusi opened this issue Nov 19, 2024 · 0 comments
Labels
feature [Issue] New feature or request

Comments

@edodusi
Copy link
Contributor

edodusi commented Nov 19, 2024

Problem Statement

Currently, when working with GraphQL queries in Storyblok, we need to handle them outside the JS client instance. This separation leads to:

  • Inconsistent request handling
  • Separation of states (eg. registered components)
  • Less coherent codebase structure and DX

Proposed Solution

Add a GraphQL wrapper method to the Storyblok JS Client that allows executing GraphQL queries through the client instance itself.

Proposed API

// GraphQL query
const query = `
  query {
    PageItem(id: $id) {
      name
      content {
        _uid
        component
      }
    }
  }
`;

// Parameters
const version = 'draft';
const variables = { id: '<story-id-123123>' };

// Execution
const response = await StoryblokClient.graphql(query, version, variables);

Benefits

  1. Consistency: All API interactions happen through the client instance with the same state
  2. Simplification: No need to manage separate GraphQL request logic
  3. Better Integration: Leverages existing client configuration and error handling
  4. Maintainability: Centralizes API interaction logic in one place

Implementation Details

A proof of concept implementation has already been created and can be found here:
#868

Questions for Discussion

  1. How is the proposed DX? Should we consider additional parameters for the GraphQL wrapper?
  2. How should we handle caching and throttling for GraphQL queries?
  3. Should we provide helper methods for common GraphQL operations?

References

@edodusi edodusi added the feature [Issue] New feature or request label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature [Issue] New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant