Comment on page
Initialization
By default, the logic of all your flags is fetched.
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 partially reduced 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
You can enter a query in the Preview tab 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: "[email protected]"
}
}
) {
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
.Set the
HYPERTUNE_QUERY_FILE_PATH
environment variable to point to the new file:HYPERTUNE_QUERY_FILE_PATH=hypertune.graphql
Regenerate the client. 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.If you declared any variables in the initialization query, you need to pass values for these when calling
initializeHypertune
. You'll get type errors everywhere you need to pass them.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.