GithubHelp home page GithubHelp logo

chronsyn / urql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from urql-graphql/urql

0.0 0.0 0.0 3.26 MB

A highly customizable and versatile GraphQL client for React

Home Page: https://formidable.com/open-source/urql

License: MIT License

JavaScript 3.55% Shell 0.19% TypeScript 96.26%

urql's Introduction

urql

A highly customisable and versatile GraphQL client for React

NPM Version Test Coverage Minified gzip size Maintenance Status

โœจ 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

You can find the raw markdown files inside this repository's docs folder.

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 use the useQuery hook in your function component to fetch data from your server:

import { useQuery } from 'urql';

const YourComponent = () => {
  const [result] = useQuery({
    query: `{ todos { id } }`,
  });

  const { fetching, data } = result;
  return fetching ? <Loading /> : <List data={data.todos} />;
};

Alternatively you can take advantage of the <Query> component:

import { Query } from 'urql';

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

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.

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.