Logo
Chakra-UIReactJsNext.JS
Head

@codecraftkit

Documentation

useGqlQueryRequest

Description#

The useGqlQueryRequest allows you to make requests using graphql.

Installation#

Code Example

npm i @codecraftkit/usegqlrequest

Import#

it can be imported from hooks.

Code Example

import { useGqlQueryRequest } from "@codecraftkit/hooks";

or alone.

Code Example

import { useGqlQueryRequest } from "@codecraftkit/usegqlrequest";

Usage#

This hook allows you to make requests using graphql

In order to use this hook do you need to configure a query like this

Code Example

import { gql } from '@apollo/client'
export const USERS_QUERY = gql`
query S_Users($options: Options) {
S_Users(options: $options) {
_id
name
avatar
favoriteColor
}
}
`

Using the hooks

Code Example

const {data, call, loading, error} = useGqlQueryRequest('S_Users', USERS_QUERY)

Another Example#

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

Code Example

const {data, call, loading, error} = useGqlQueryRequest('S_Users', USERS_QUERY)
useEffect(() => {
call({options: {_id: 2}})
}, []);
console.log('%c data', 'background: #222; color: #bada55',data)

Arguments#

name

type

required

default

description

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

Results#

name

type

description

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