Created
July 22, 2023 16:12
-
-
Save SilviaMargaritaOcegueda/353d6fb3db80be292b3fe31f950dbcee to your computer and use it in GitHub Desktop.
getBabiesOfRelationship
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
const { request, gql } = require("graphql-request"); | |
// Function to query the subgraph and retrieve babies for the given relationship | |
async function getBabiesOfRelationship(relationAddress) { | |
const endpoint = | |
"https://api.thegraph.com/subgraphs/name/silviamargaritaocegueda/bb-relationships"; | |
const query = gql` | |
query MyQuery($relationAddress: Bytes) { | |
relationship(id: $relationAddress) { | |
creature | |
} | |
} | |
`; | |
try { | |
const data = await request(endpoint, query, { relationAddress }); | |
return data.relationship.creature; | |
} catch (error) { | |
console.error("Error fetching data:", error); | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment