Skip to content

feat(views): define override interface #1086

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

Draft
wants to merge 7 commits into
base: poc/views-support
Choose a base branch
from

Conversation

danielgroves
Copy link

@danielgroves danielgroves commented May 21, 2025

Suggested config for the view overrides for dev mode. Idea here is a user would create thier view and then they can configure from there.

We don't take an OrgId here as we should be able to infer that from the ViewID/Token?

Using partials for the connections allows us to cover lots of different test scenarios without the end user having to reconfigure everything.
I think for dev-mode we should set some sensible defaults, but look at this in terms of:

  1. Use the value deployed for a given field, e.g if 'vc123' has apiVersion '2025-05-22' configured and one is not explicitly set then we use that, otherwise we fallback to a recent stable.
  2. If a connection name has not been explicitly created yet thats ok, but we should then require query, dataset and projectId

I don't know what the preview mode would look like yet, so this is subject to change. In production you would omit setting viewOverride and then the client would hit the views query endpoint.

// full example
const view: ViewOverride[] = [
  {
    id: 'vw123',
    connection: [
      {
        name: 'vc123',
        query: '*[_id == "something"]{_id}',
        dataset: 'foo',
        projectId: 'bar',
        apiVersion: '2025-01-01',
      },
    ],
  },
]

// how one might use it to develop a new query
const view: ViewOverride[] = [
  {
    id: 'vw123',
    connection: [
      {
        name: 'vc123',
        query: '*[_id == "something"]{_id}',
      },
    ],
  },
]

// test against a different project/env
// this allows a user to have a "production" project and a "dev" project as an example
const view: ViewOverride[] = [
  {
    id: 'vw123',
    connection: [
      {
        name: 'vc123',
        projectId: 'bar',
      },
    ],
  },
]

// or test against a different apiVersion
// this allows a user to have a "production" project and a "dev" project as an example
const view: ViewOverride[] = [
  {
    id: 'vw123',
    connection: [
      {
        name: 'vc123',
        apiVersion: 'X',
      },
    ],
  },
]

// developing a new view from scratch
// this requires a view to exist, but you don't have to have any connections yet
const view: ViewOverride[] = [
  {
    id: 'vw123', 
    connection: [
      {
        name: 'vc123', // can be anything
        query: '*[_id == "something"]{_id}',
        dataset: 'foo',
        projectId: 'bar',
        apiVersion: '2025-01-01',
      },
    ],
  },
]

// passing it into the client:
const viewClient = createViewClient({
  apiVersion: 'X', // this sets the views api version, not what the connection uses
  viewOverride: view // this is optional, but without this we default to production mode
});

Copy link

vercel bot commented May 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
tsdocs-client ⬜️ Ignored (Inspect) May 21, 2025 3:46pm

Copy link
Contributor

github-actions bot commented May 21, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 87.07% 2862 / 3287
🔵 Statements 87.07% 2862 / 3287
🔵 Functions 85.96% 245 / 285
🔵 Branches 88.43% 902 / 1020
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/views/index.ts 66.3% 100% 66.66% 66.3% 81-85, 157-161, 175-196
Generated in workflow #3354 for commit 76d0229 by the Vitest Coverage Report Action

@danielgroves danielgroves force-pushed the poc/views-support-fetch branch from 6dcb406 to db80b4a Compare May 21, 2025 14:23
@danielgroves danielgroves force-pushed the poc/views-support-dev branch from a1d4602 to 3208f8f Compare May 21, 2025 14:24
@danielgroves danielgroves force-pushed the poc/views-support-dev branch from 3208f8f to 76d0229 Compare May 21, 2025 15:46
Base automatically changed from poc/views-support-fetch to poc/views-support May 27, 2025 12:51
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.

1 participant