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

feat: added file to fetch data from the subgraph API. Package.json updated with axios and ts-node. #154

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -66,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"
}
}
49 changes: 49 additions & 0 deletions src/services/subgraph-queries.ts
RafaDSan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const axios = require("axios");
require('dotenv').config({ path: __dirname + '/../../.env' });

const {ENDPOINT_URL, AUTHORIZATION_kEY} =
process.env;

async function main() {
const endpoint = process.env.ENDPOINT_URL;
const headers = {
"content-type": "application/json",
Authorization: process.env.AUTHORIZATION_kEY,
};

//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);
});
Loading