From e64708289360bbfde0f70114f1f2a131b5599829 Mon Sep 17 00:00:00 2001 From: RafaDSan Date: Fri, 24 Nov 2023 14:37:13 -0300 Subject: [PATCH 1/4] feat: file added to fetch data from the subgraph API. Package.json Updated with axios and ts-node. --- package.json | 8 +++--- src/services/subgraph-queries.ts | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/services/subgraph-queries.ts diff --git a/package.json b/package.json index a7fda77..bf462a3 100644 --- a/package.json +++ b/package.json @@ -6,26 +6,27 @@ "dependencies": { "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", + "@hookform/resolvers": "^3.3.1", "@mui/icons-material": "5.14.1", "@mui/lab": "^5.0.0-alpha.137", "@mui/material": "^5.14.2", "@mui/system": "^5.14.1", "@mui/x-date-pickers": "6.10.1", - "@hookform/resolvers": "^3.3.1", + "axios": "^1.6.2", "bootstrap": "^4.4.1", "date-fns": "2.28.0", "dayjs": "1.11.7", + "ethers": "5.7.2", "nprogress": "0.2.0", "react": "^18.0.0", "react-custom-scrollbars-2": "4.5.0", "react-dom": "^18.0.0", "react-helmet-async": "1.3.0", + "react-hook-form": "7.47.0", "react-icons": "^4.10.1", "react-number-format": "5.1.4", "react-router-dom": "6.14.2", - "react-hook-form": "7.47.0", "wagmi": "^0.4.2", - "ethers": "5.7.2", "yup": "^1.3.2" }, "overrides": { @@ -52,6 +53,7 @@ ] }, "devDependencies": { + "@types/node": "^20.10.0", "@types/react-dom": "^18.2.7", "@types/react-swipeable-views": "^0.13.2", "@types/react-swipeable-views-utils": "^0.13.4", diff --git a/src/services/subgraph-queries.ts b/src/services/subgraph-queries.ts new file mode 100644 index 0000000..8d31815 --- /dev/null +++ b/src/services/subgraph-queries.ts @@ -0,0 +1,46 @@ +const axios = require("axios"); + +async function main() { + const endpoint = + "https://api.studio.thegraph.com/query/57887/web3task-mumbai-testnet/version/latest"; + const headers = { + "content-type": "application/json", + Authorization: "3b2048f02febad918a35bbafe78b2115", + }; + + //Example of query + const graphqlQuery = { + operationName: "AuthorizedPersonnelsQuery", + query: `query { + authorizePersonnels { + roleId + isAuthorized + authorizedAddress + } + }`, + variables: {}, + }; + + const config = { + url: endpoint, + method: "post", + headers: headers, + data: graphqlQuery, + }; + + try { + const response = await axios(config); + console.log(JSON.stringify(response.data, null, 2)); + console.log(response.data.errors); + } catch (error) { + console.error(error); + process.exit(1); + } +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); From ee1ab8e9a3e9cf6b36d6278fecba8ff300d4e2a6 Mon Sep 17 00:00:00 2001 From: RafaDSan Date: Thu, 7 Dec 2023 11:10:28 -0300 Subject: [PATCH 2/4] fix: subgraph-queries.ts is now fetching senstive information from the .env file --- src/services/subgraph-queries.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/subgraph-queries.ts b/src/services/subgraph-queries.ts index 8d31815..0167657 100644 --- a/src/services/subgraph-queries.ts +++ b/src/services/subgraph-queries.ts @@ -1,12 +1,15 @@ const axios = require("axios"); +require('dotenv').config({ path: __dirname + '/../../.env' }); + +const {ENDPOINT_URL, AUTHORIZATION_kEY} = + process.env; async function main() { - const endpoint = - "https://api.studio.thegraph.com/query/57887/web3task-mumbai-testnet/version/latest"; - const headers = { - "content-type": "application/json", - Authorization: "3b2048f02febad918a35bbafe78b2115", - }; + const endpoint = process.env.ENDPOINT_URL; + const headers = { + "content-type": "application/json", + Authorization: process.env.AUTHORIZATION_kEY, + }; //Example of query const graphqlQuery = { From e37989b13a48d05c6c8da135948e9a15c4ab6424 Mon Sep 17 00:00:00 2001 From: RafaDSan Date: Thu, 7 Dec 2023 11:11:15 -0300 Subject: [PATCH 3/4] feat: dotenv DevDependece added to package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index bf462a3..e4a5cfd 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "eslint-plugin-react": "7.33.2", "eslint-plugin-react-hooks": "4.6.0", "prettier": "3.0.2", - "react-scripts": "5.0.1" + "react-scripts": "5.0.1", + "dotenv": "^16.3.1" } } From 6d05195b477a11955654b86594853cd844373e70 Mon Sep 17 00:00:00 2001 From: RafaDSan Date: Thu, 7 Dec 2023 11:12:17 -0300 Subject: [PATCH 4/4] environment file added to the root directory to hide sensitve information --- .env.sample | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..894959c --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +#Subgraph endpoint and authorization token. These are real values but they are used only for test purposes. It does not cost anythig to use them. +AUTHORIZATION_kEY=b7df5ecfbcc1fa644899ea8e04c45bf9 +ENDPOINT_URL=https://api.studio.thegraph.com/query/57887/web3task-mumbai-testnet/version/latest \ No newline at end of file