Hypertune
  • Introduction
  • Getting Started
    • Set up Hypertune
    • Next.js (App Router) quickstart
    • Next.js (Pages Router) quickstart
    • React quickstart
    • Remix quickstart
    • Gatsby quickstart
    • Vue quickstart
    • Nuxt quickstart
    • Node.js quickstart
    • React Native quickstart
    • JavaScript quickstart
    • Python quickstart
    • Rust quickstart
    • Go quickstart
    • Web quickstart
    • GraphQL quickstart
  • Example apps
    • Next.js and Vercel example app
  • Concepts
    • Architecture
    • Project
    • Schema
    • Flag lifecycle
    • Logic
    • Variables
    • Splits
    • A/B tests
    • Staged rollouts
    • Multivariate tests
    • Machine learning loops
    • Events
    • Funnels
    • Hypertune Edge
    • Reduction
    • SDKs
    • GraphQL API
    • Git-style version control
    • App configuration
  • Use Cases
    • Feature flags and A/B testing
    • Landing page optimization
    • In-app content management
    • Pricing plan management
    • Permissions, rules and limits
    • Optimizing magic numbers
    • Backend configuration
    • Product analytics
  • Integrations
    • Vercel Edge Config integration
    • Google Analytics integration
    • Segment integration
    • Webhooks
      • Creating webhooks
      • Handling webhooks
  • SDK Reference
    • Installation
    • Type-safe client generation
    • Initialization
    • Build-time logic snapshot
    • Hard-coded fallbacks
    • Local-only, offline mode
    • Hydrate from your own server
    • Wait for server initialization
    • Provide targeting attributes
    • Local, synchronous evaluation
    • Remote logging
    • Getting flag updates
    • Serverless environments
    • Vercel Edge Config
    • Custom logging
    • Shutting down
Powered by GitBook
On this page
  • Use an initialization query
  • 1. Define an initialization query
  • 2. Set environment variable
  • 3. Regenerate the client and update your code
  • That's it
  1. SDK Reference

Initialization

PreviousType-safe client generationNextBuild-time logic snapshot

Last updated 10 months ago

During initialization, SDKs fetch your flag logic from .

By default, the logic of all your flags is fetched.

Use an initialization query

You can optionally use an "initialization query" to:

  • Select which flags to fetch

  • Provide some targeting attributes upfront so that any flag logic that depends on those attributes can be on the edge

This is useful for:

  • Performance

    • You can limit which flags are fetched to reduce the network payload size

    • You can partially reduce flag logic on the edge to:

      • Reduce the network payload size

      • Reduce the logic that needs to be locally evaluated by the SDK

  • Security

    • You can eliminate sensitive logic, e.g. a list of user IDs, on the edge so it doesn't get leaked to publicly accessible clients, e.g. in the browser

1. Define an initialization query

Hypertune uses for its query language.

You can enter a query in the Preview view of the Hypertune UI to see the partially reduced flag logic that would be returned.

For example, the following query fetches the showNewEditor flag and provides the user targeting attributes upfront so that any logic that depends on them can be partially reduced on the edge:

query TestQuery {
  root(
    context: {
      user: {
        id: "test_id"
        name: "Test"
        email: "test@test.com"
      }
    }
  ) {
    showNewEditor
  }
}

You can provide these attributes dynamically during SDK initialization by making them "query variables" instead:

query TestQuery($user: User!) {
  root(context: { user: $user }) {
    exampleFlag
  }
}

Place this query into a new file, e.g. hypertune.graphql.

2. Set environment variable

Set the HYPERTUNE_QUERY_FILE_PATH environment variable to point to the new file:

HYPERTUNE_QUERY_FILE_PATH=hypertune.graphql

3. Regenerate the client and update your code

If you declared any variables in the initialization query, you need to pass values for these when calling createSource. You'll get type errors everywhere you need to pass them.

That's it

Now the SDK will only fetch the flags you selected in your query, you won't need to pass any attributes that you already provided in your query, and your flag logic will be partially reduced with those attributes on the edge, reducing the amount of logic that needs be fetched and evaluated by the SDK.

. Now you no longer need to pass targeting attributes when evaluating your root flag or individual flags if you already passed them in the initialization query. You'll get type errors everywhere you need to remove these attributes.

Regenerate the client
Hypertune Edge
GraphQL
partially reduced