Replace nhost js GraphQL Client with a third party GraphQL Client
The current GraphQL Client in our js SDK (nhost.grapqhl) is our custom-built client with minimal features.
We should consider replacing it with a third-party GraphQL client with support for more features and better maintenance.
Some alternatives are:
graphql-request: https://github.com/prisma-labs/graphql-requesturql: https://formidable.com/open-source/urql/docs/basics/core/apollo/client: https://www.apollographql.com/docs/react/api/core/ApolloClient
@elitan If you do a request with the built-in client of Nhost JS SDK:
const QUERY_GET_ALL_USER = gql
query QueryGetAllUser {
users {
email
displayName
id
emailVerified
createdAt
roles {
role
}
}
}
const { data, error } = await client.graphql.request(QUERY_GET_ALL_USER)
And got the following error:
Error: incorrect response data from GraphQL server
Seems that the default accept-encoding header that Axios uses in a node environment causes issues. If you add "accept-encoding: null" to headers everything is working like expected.
const { data, error } = await client.graphql.request(QUERY_GET_ALL_USER, {}, {
headers: {
'accept-encoding': null
}
})
If think the best solution is to use "apollo/client" as third party client for GraphQL.
@elitan If you do a request with the built-in client of Nhost JS SDK:
const QUERY_GET_ALL_USER = gql query QueryGetAllUser { users { email displayName id emailVerified createdAt roles { role } } } const { data, error } = await client.graphql.request(QUERY_GET_ALL_USER)And got the following error:
Error: incorrect response data from GraphQL serverSeems that the default accept-encoding header that Axios uses in a node environment causes issues. If you add "accept-encoding: null" to headers everything is working like expected.
const { data, error } = await client.graphql.request(QUERY_GET_ALL_USER, {}, { headers: { 'accept-encoding': null } })If think the best solution is to use "apollo/client" as third party client for GraphQL.
I can confirm this issue. The fix also works.
Thanks for the info. It will help us prioritize this issue.
I think we should use graphql-request instead of urql or @apollo/client because we want a minimal and thin client with no advanced features.
Looks good 👍🏻 any plans for the release? 🤗
A small comparison:
| Library | Bundle size | Npm weekly downloads | Easy to begin with | Codegen |
|---|---|---|---|---|
graphql-request |
7.9kB | 2,447K | + | Vanilla |
@apollo/client |
42.6kB | 767K | - | Vanilla, React, Vue, Angular, Stencil, Svelte, Nextjs |
urql |
8kB | 142K | + | React, Vue |
I feel urql is a bit too react-driven and not as generic as graphql-request. I would go for graphql-request too.
Moreover:
- we already have a generic
@nhost/apolloclient - as we are working on a
@nhost/react-urqllibrary, we could consider adding a@nhost/urqllibrary at a later stage so the client can be reused with other frameworks
For a base, graphql-request is good for thinnest possible.
Urql I'm looking at using for my future projects. Apollo cache and its complexity (too smart for its own good with normalization) has annoyed me enough, besides being a fat chunky package. Urql is much lighter and does caching in minimal and predictable ways. +1 to @nhost/react-urql being actively maintained
Hi, for vue 2/3 did you condiser the library vue-apollo? Its really nice to work with and its supports "new" composition API.
We've decided not to do this for now.