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

ASSETS-88898 : (Backend) Campaign Overview Page Components #64

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions scripts/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ export async function graphqlCampaignByName(campaignName) {
});
}

export async function graphqlFilterOnMarketingInitiative(marketingInitiative) {

const baseApiUrl = `${await getGraphqlEndpoint()}/graphql/execute.json`;
const projectId = 'gmo';
const queryName = 'filter-on-marketing-initiative';
const encodedMarketingInitiative = encodeURIComponent(marketingInitiative);
const encodedSemiColon = encodeURIComponent(';');
//persisted query URLs have to be encoded together with the first semicolon
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}${encodedSemiColon}marketingInitiative=${encodedMarketingInitiative}`;
const jwtToken = await getBearerToken();

// Return the fetch promise chain so that it can be awaited outside
return fetch(graphqlEndpoint, {
method: 'GET',
headers: {
Authorization: jwtToken,
},
}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
}).then(data => {
return data; // Make sure to return the data so that the promise resolves with it
}).catch(error => {
console.error('Error fetching data: ', error);
throw error; // Rethrow or handle error as appropriate
});
}



async function getGraphqlEndpoint() {
const result = await getAdminConfig();
Expand Down
Loading