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.
Updated the code call the GraphQL Persisted query from the QA AEM Aut…
…hor server, and also to authenticate using the JWT Bearer token
- Loading branch information
Showing
3 changed files
with
46 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export async function graphqlDemoGet() { | ||
const baseApiUrl = 'http://localhost:4502/graphql/execute.json'; | ||
const projectId = 'my-project'; | ||
const queryName = 'all-teams'; | ||
const queryParams = ''; // Adjust if needed | ||
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}${queryParams}`; | ||
const username = 'admin'; | ||
const password = 'admin'; | ||
const base64Credentials = btoa(username + ':' + password); | ||
|
||
// Return the fetch promise chain so that it can be awaited outside | ||
return fetch(graphqlEndpoint, { | ||
method: 'GET', | ||
headers: { | ||
'Authorization': `Basic ${base64Credentials}`, | ||
}, | ||
}).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 | ||
}); | ||
} | ||
|
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