Lightweight graphql client.
1.2 is around 1.4 KB, checkout Bundlephobia for accurate result.
pnpm add @saltyaom/gql
import gql, { client } from '@saltyaom/gql'
client.config('https://api.hifumin.app/graphql')
gql(
`query SaltyAomGQL($id: Int!) {
nhql {
by(id: $id) {
data {
id
title {
display
}
}
}
}
}`,
{
variables: {
id: 177013
}
}
Y'll made GraphQL too complex and heavy.
I just want to fetch GraphQL query here.
You can implement custom plugin for transforming data, caching, logging, etc.
middlewares
operationName
, variables
)afterwares
data
, operationName
, variables
)import gql, { client } from '@saltyaom/gql'
import LocalCache from '@saltyaom/gql-local-cache'
client.config(
'https://api.opener.studio/graphql',
{
plugins: [
LocalCache(),
// Or write your own plugins
{
afterwares: [
({ data, operationName, variables }) => {
console.log('Logger:', data, operationName, variables)
}
]
}
]
}
)
// You can pass generic if you're using TypeScript
gql<ReturnType, VariableType>(
`query SaltyAomGQL($id: Int!) {
nhql {
by(id: $id) {
data {
id
title {
display
}
}
}
}
}`,
{
variables: {
id: 177013
}
}
).then((data) => {
console.log(data)
})