GraphQL quickstart
If you don't want to use an SDK or we don't have one for your language yet, you can get your configuration from the GraphQL API. If you've already set up your project, you can skip to the preview step of this guide.
Define a new feature flag called
enablePaypal
on the Root
type:type Root {
exampleFlag: Boolean!
enablePaypal: Boolean!
}
Switch to the "Logic" tab and select the "Enable Paypal" flag.
Add an "If / Else" expression with a rule that enables the flag if
context > user > id
is test_id
and disables it by default.Click "Save & Activate" in the navigation bar.
Switch to the Preview tab and enter the following query:
query TestQuery {
root {
enablePaypal
}
}
Hypertune uses GraphQL for its query language. In the result panel, you can see just the part of your configuration logic that matches your query.
Now pass the
context
argument containing the user
object in the query:query TestQuery {
root(
context: {
user: {
id: "test_id"
name: "Test"
email: "[email protected]"
}
}
) {
enablePaypal
}
}
Now you can see a more reduced version of your configuration logic, where the "If / Else" expression has been replaced with its result.
Switch to the Code Snippets tab to see JavaScript and cURL snippets for the GraphQL query you entered.
JavaScript Example
cURL Example
/* Query: query TestQuery {
root(
context: {
user: {
id: "test_id"
name: "Test"
email: "[email protected]"
}
}
) {
enablePaypal
}
}
Example Variables: {} */
function fetchConfigFromHypertune(variables) {
return fetch("https://hypertune.edgecompute.app/graphql/your_project_id", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer your_token",
},
body: JSON.stringify({
query: "query TestQuery { root( context: { user: { id: \"test_id\" name: \"Test\" email: \"[email protected]\" } } ) { enablePaypal } }",
variables: variables
}),
redirect: "follow",
referrerPolicy: "no-referrer-when-downgrade",
keepalive: true
})
.then((response) => {
return response.json();
})
.then((result) => {
if (result.data) {
return result.data;
}
throw result;
});
}
curl --location --request POST 'https://hypertune.edgecompute.app/graphql/your_project_id' \
--header 'Authorization: Bearer your_token' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query TestQuery { root( context: { user: { id: \"test_id\" name: \"Test\" email: \"[email protected]\" } } ) { enablePaypal } }","variables":{}}'
Last modified 1mo ago