Skip to content

useEntity

The useEntity hook retrieves an entity client by name from the GraphQLProvider context. It is a convenience wrapper around useGraphQLClient().entity(name) with React memoization.

import { useEntity } from '@graphql-suite/query'
function MyComponent() {
const articleEntity = useEntity('article')
// Pass articleEntity to useEntityList, useEntityQuery, etc.
}

The returned entity client can be used with any of the query and mutation hooks.

useEntity infers types from the provider context, but the inference can be limited since the provider uses a generic client type. For full type safety on select, where, and orderBy parameters, obtain the entity at module level from the client instance:

import { client } from './graphql-client'
const articleEntity = client.entity('article')

This preserves the complete type information from your Drizzle schema, giving you autocomplete and type checking on all query parameters.