@codecraftkit
Documentation
The useGqlQueryRequest allows you to make requests using graphql.
This hook is based on useQuery
npm i @codecraftkit/usegqlrequest
it can be imported from hooks.
import { useGqlQueryRequest } from "@codecraftkit/hooks";
or alone.
import { useGqlQueryRequest } from "@codecraftkit/usegqlrequest";
This hook allows you to make requests using graphql
In order to use this hook do you need to configure a query like this
import { gql } from '@apollo/client'export const USERS_QUERY = gql`query S_Users($options: Options) {S_Users(options: $options) {_idnameavatarfavoriteColor}}`
Using the hooks
const {data, call, loading, error} = useGqlQueryRequest('S_Users', USERS_QUERY)
You can make calls using the call item, and the data will load in the data item
Also you can pass params throughout the call request
const {data, call, loading, error} = useGqlQueryRequest('S_Users', USERS_QUERY)useEffect(() => {call({options: {_id: 2}})}, []);console.log('%c data', 'background: #222; color: #bada55',data)
The loading item is an internal loading managed in the hook, it is NOT the loading from useQuery
collection
String
yes
The name of the query's collection
QUERY
QUERY
yes
The query to execute when making the call, it must be a valid graphql query
options
Object
no
{ ssr: false, skip: true, fetchPolicy: 'network-only' }
configuration accepted for the useQuery hook
defaultValue
String
no
data default value
verbose
String
no
Show requests logs in the console
data
any
Query's response inside the collection field
call
function
Function to execute the query supplied, it receive the query params as arguments
loading
boolean
Request loading state
error
String
Response Error