I'm going to compare different graph ql tools. Then I'll try suggest different graph ql - client side implementations for a react app. -easa 10:51 3/6/2022 GMT+03:30
The following table shows the differences between the different graph ql hooks and tools.
Name | Downloads | Stars / Issues | Version | Last Update |
---|---|---|---|---|
apollo-client | 1,030,721 | 16,728/447 | 2.6.10 | 2020 |
apollo-boost | 303,390 | 16,579/406 | 0.4.9 | 2020 |
react-relay | 185,666 | 16,734/375 | 13.1.1 | 2022 |
urql | 111,374 | 6,940/23 | 2.2.0 | 2022 |
The goal of this project is to compare the different graph ql hooks and tools and to see which one is the best for a given use case. The following use cases are considered:
- Have a hook named
useQuery
and use it to fetch data from a graphql endpoint. - The hook should accept a
query
and avariables
as parameters. - The hook should return a
data
, aerror
and afetch
function as properties. - The
fetch
function should be called when the data is needed. - The
fetch
function should return aPromise
that resolves to thedata
property. - The
fetch
function should return aPromise
that rejects with theerror
property. - The hook should be used in a
React.Component
. - The hook should return a loading state.
- The hook should have an internal state to indicate whether running the
fetch
function at the first time or not. - The hook should have an internal state to indicate whether the data is loading or not.
- The hook should accept configuration options.
- The configuration options should be able to be passed to the
useQuery
hook. - The configuration options should be able to be passed to the
fetch
function. - The configuration options should be able to reset all the internal states.
export default ()=>{
const {data, error, fetch} = useQuery({
query: gql`
query getUser($id: ID!){
user(id: $id){
id
name
email
}
}
`,
variables: {
id: '1'
}
})
return (
<div>
{data && data.user.name}
{error && error.message}
<button onClick={()=>fetch()}>Fetch</button>
</div>
)
}