Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SilviaMargaritaOcegueda/353d6fb3db80be292b3fe31f950dbcee to your computer and use it in GitHub Desktop.
Save SilviaMargaritaOcegueda/353d6fb3db80be292b3fe31f950dbcee to your computer and use it in GitHub Desktop.
getBabiesOfRelationship
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