urql is a highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow. It’s built to be both easy to use for newcomers to GraphQL, and extensible, to grow to support dynamic single-app applications and highly customized GraphQL infrastructure. In short, urql prioritizes usability and adaptability.jotai-urql is a Jotai extension library for URQL. It offers a cohesive interface that incorporates all of URQL’s GraphQL features, allowing you to leverage these functionalities alongside your existing Jotai state.
Install
You have to installjotai-urql, @urql/core and wonka to use the extension.
Exported functions
atomWithQueryfor client.queryatomWithMutationfor client.mutationatomWithSubscriptionfor client.subscription
Basic usage
Query:
Mutation:
Simplified type of options passed to functions
Disable suspense
Usage ofimport { loadable } from "jotai/utils" is preferred instead as proven more stable. However is you still want that
here is how you do it:
Referencing the same instance of the client for both atoms and urql provider
To ensure that you reference the same urqlClient object, be sure to wrap the root of your project in a<Provider> and initialise clientAtom with the same urqlClient value you provided to UrqlProvider.
Without this step, you may end up specifying client each time when you use atomWithQuery. Now you can just ignore the optional getClient parameter, and it will use the client from the context.