generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ASSETS-02024' into assets-98990
- Loading branch information
Showing
5 changed files
with
105 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { getBearerToken } from './security.js'; | ||
import { getAdminConfig } from './site-config.js'; | ||
|
||
export async function graphqlAllCampaigns() { | ||
|
||
const baseApiUrl = `${await getGraphqlEndpoint()}/graphql/execute.json`; | ||
const projectId = 'gmo'; | ||
const queryName = 'getAllCampaigns'; //Todo Shivani will rename query to allCampaigns | ||
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}`; | ||
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 | ||
}); | ||
} | ||
|
||
export async function graphqlCampaignByName(campaignName) { | ||
|
||
const baseApiUrl = `${await getGraphqlEndpoint()}/graphql/execute.json`; | ||
const projectId = 'gmo'; | ||
const queryName = 'campaign-name-in-param'; | ||
const encodedCampaignName = encodeURIComponent(campaignName); | ||
const encodedSemiColon = encodeURIComponent(';'); | ||
//persisted query URLs have to be encoded together with the first semicolon | ||
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}${encodedSemiColon}campaignName=${encodedCampaignName}`; | ||
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(); | ||
return result.aemGraphqlEndpoint; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters