Draqula is a GraphQL client for React apps that don't need everything.
Instead of offering tons of features like extensive caching mechanism, local state management, subscriptions and so on, Draqula focuses on executing the basics well - queries and mutations.
If you want to take a quick look, keep scrolling this readme.
Otherwise, check out the documentation at https://draqulajs.com.
Install
$ npm install draqula graphql graphql-tag
Features
Simple API and codebase
Basic cache implementation with aggressive invalidation and refetching
Automatic retries of network/timeout errors and GraphQL queries
Straightforward way to hook into requests without a need for middleware
Refetches queries when window gets focused
Usage
importReactfrom'react';import{render}from'react-dom';import{Draqula,DraqulaProvider,useQuery}from'draqula';importgqlfrom'graphql-tag';constTODOS_QUERY=gql` query { todos { id title } }`;constTodos=()=>{const{data, isLoading, error}=useQuery(TODOS_QUERY);return(<div>{isLoading&&<span>Loading…</span>}{error&&<span>Error: {error.message}</span>}{data&&(<ul>{data.todos.map(todo=>(<likey={todo.id}>{todo.title}</li>))}</ul>)}</div>);};constclient=newDraqula('https://my-graphql-api.com/graphql');render(<DraqulaProviderclient={client}><Todos/></DraqulaProvider>,document.body);
请发表评论