Giter Club home page Giter Club logo

urql's Introduction

urql

A highly customisable and versatile GraphQL client for React

Build Status Test Coverage NPM Version Maintenance Status

Steve Urkel

โœจ Features

  • ๐Ÿ“ฆ One package to get a working GraphQL client in React
  • โš™๏ธ Fully customisable behaviour via "exchanges"
  • ๐Ÿ—‚ Logical but simple default behaviour and document caching
  • โš›๏ธ Minimal React components and hooks

urql is a GraphQL client that exposes a set of React components and hooks. It's built to be highly customisable and versatile so you can take it from getting started with your first GraphQL project all the way to building complex apps and experimenting with GraphQL clients.

While GraphQL is an elegant protocol and schema language, client libraries today typically come with large API footprints. We aim to create something more lightweight instead.

The documentation contains everything you need to know about urql

Quick Start Guide

First install urql and graphql:

yarn add urql graphql
# or
npm install --save urql graphql

Create a client for your endpoint url and wrap your app with a <Provider> component which urql exposes:

import { Provider, createClient } from 'urql';

const client = createClient({
  url: 'http://localhost:1234/graphql', // Your GraphQL endpoint here
});

ReactDOM.render(
  <Provider value={client}>
    <YourApp />
  </Provider>,
  document.body
);

This allows you to now use the <Query> component to fetch data from your server:

import { Query } from 'urql';

<Query query="{ todos { id } }">
  {({ fetching, data }) =>
    fetching ? <Loading /> : <List data={data.todos} />
  }
</Query>;

Alternatively you can take advantage of the useQuery hook in your function component:

import { useQuery } from 'urql';

const YourComponent = () => {
  const [{ fetching, data }] = useQuery({ query: `{ todos { id } }` });
  return fetching ? <Loading /> : <List data={data.todos} />;
};

Learn the full API in the "Getting Started" docs!

Examples

There are currently two examples included in this repository:

Maintenance Status

Active: Formidable is actively working on this project, and we expect to continue for work for the foreseeable future. Bug reports, feature requests and pull requests are welcome.

urql's People

Contributors

kitten avatar andyrichardson avatar kenwheeler avatar ryan-roemer avatar baer avatar danielrosenwasser avatar alex-saunders avatar boygirl avatar tptee avatar theianjones avatar jaredpalmer avatar lukejacksonn avatar scyclow avatar parkerziegler avatar andarist avatar blainekasten avatar glifchits avatar jamesplease avatar joealden avatar flexzuu avatar good-idea avatar wkovacs64 avatar kiraarghy avatar kyleshevlin avatar lnmunhoz avatar koulmomo avatar patcito avatar federicobadini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.