From fd368c1798850dec2684e025369e34433107a54b Mon Sep 17 00:00:00 2001 From: amirmoghi3 Date: Mon, 17 Feb 2025 04:57:46 +0330 Subject: [PATCH] add graphql --- src/utils/graphql/index.jsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/utils/graphql/index.jsx diff --git a/src/utils/graphql/index.jsx b/src/utils/graphql/index.jsx new file mode 100644 index 0000000..978d228 --- /dev/null +++ b/src/utils/graphql/index.jsx @@ -0,0 +1,25 @@ + +export default async function graphql(query = '', variables = {}, token = '',) { + + const response = await fetch(`https://api.adhorizonintl.com/graphql`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + }, + body: JSON.stringify({ + query, + variables, + }), + cache:"no-store" + }); + + const json = await response.json(); + + if (json.errors) { + console.error(json.errors); + throw new Error('Failed to fetch GraphQL data'); + } + + return json.data ; +}