A custom hook, written for Apollo Server
const fetch = useDatabase(query)The useDatabase hook takes the following parameters:
query: backticks string of GraphQL query
Returns:
data: a GraphQL like JSON object. Your resolved queries will be inside this objectloading: abooleanto indicate if the data is still being loadederror: a GraphQL error.undefinedif there is no error
const fetch = useDatabase(`#graphql
{
users {
userId
name
bio
profileImage
}
findPosts(postId: "${postId}"){
postId
description
title
createdAt
user {
userId
name
bio
profileImage
}
}
# ...Other queries
}
`)