Introduction
Draqula is a GraphQL client for React apps that don't need everything.
It provides only the essential React hooks for building apps - queries (useQuery
) and mutations (useMutation
), which is enough for the majority of web apps out there.
Draqula doesn't implement higher-order or render-prop components, hooks are the only way to work with Draqula.
It also doesn't offer extensive cache mechanisms, local state management or subscriptions.
By skipping all of that, Draqula can maintain a small and simple codebase and focus on executing the basics well.
If you need any of the missing things, check out Apollo.
Here's how Draqula looks and works:
1 const TODOS_QUERY = gql`2 {3 todos {4 id5 title6 }7 }8 `;910const Todos = () => {11 const {data, isLoading, error} = useQuery(TODOS_QUERY);1213 return (14 <>15 {isLoading && <span>Loading…</span>}16 {error && <span>Error: {error.message}</span>}17 {data && (18 <ul>19 {data.todos.map(todo => (20 <li key={todo.id}>{todo.title}</li>21 ))}22 </ul>23 )}24 </>25 );26};
Features
- Simple API and codebase
- Basic cache implementation with aggressive invalidation and refetching
- Automatic retries of network/timeout errors and failed GraphQL queries
- Straightforward way to hook into requests without a need for middleware
- Refetches queries when window gets focused
What is not supported?
Here are the features that are planned to be implemented soon:
- Server-side rendering
- Polling of queries
- Lazy queries (trigger a query on demand)
- Pause queries if client is offline
And here are the things that will not be implemented:
- Higher-order components
- Render-prop components
- Subscriptions (at least not in the foreseeable future)
- Caching implementation similar to the one in Apollo
Can I use Draqula in production?
No, not yet. I would appreciate if you tested Draqula in your personal projects or experiments though! I want to give Draqula time to stabilize its API and fix any bugs that could come up to ensure that when 1.0 version is out, it's safe for production apps.