Convert Figma logo to code with AI

urql-graphql logourql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

8,603
448
8,603
29

Top Related Projects

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.

5,803

Minimal GraphQL client

8,602

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

A reference implementation of GraphQL for JavaScript

The Fullstack Tutorial for GraphQL

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.

Quick Overview

urql is a highly customizable and versatile GraphQL client for React, Vue, Svelte, and vanilla JavaScript. It offers a lightweight, extensible, and efficient solution for integrating GraphQL APIs into web applications, with a focus on simplicity and performance.

Pros

  • Lightweight and modular architecture, allowing for easy customization and extension
  • Excellent TypeScript support, providing type safety and improved developer experience
  • Built-in caching and normalization capabilities
  • Support for multiple frameworks and vanilla JavaScript

Cons

  • Smaller community and ecosystem compared to Apollo Client
  • Less comprehensive documentation for advanced use cases
  • Fewer built-in features compared to some other GraphQL clients
  • May require additional setup for more complex scenarios

Code Examples

  1. Basic query execution:
import { createClient, gql } from '@urql/core';

const client = createClient({
  url: 'https://api.example.com/graphql',
});

const query = gql`
  query GetUser($id: ID!) {
    user(id: $id) {
      id
      name
      email
    }
  }
`;

const result = await client.query(query, { id: '123' }).toPromise();
console.log(result.data);
  1. Using the React hooks:
import { useQuery } from 'urql';

const UserComponent = ({ id }) => {
  const [result] = useQuery({
    query: `
      query GetUser($id: ID!) {
        user(id: $id) {
          id
          name
          email
        }
      }
    `,
    variables: { id },
  });

  if (result.fetching) return <p>Loading...</p>;
  if (result.error) return <p>Error: {result.error.message}</p>;

  return <div>User: {result.data.user.name}</div>;
};
  1. Mutation example:
import { useMutation } from 'urql';

const [updateUserResult, updateUser] = useMutation(`
  mutation UpdateUser($id: ID!, $name: String!) {
    updateUser(id: $id, name: $name) {
      id
      name
    }
  }
`);

// Later in your component
const handleUpdate = () => {
  updateUser({ id: '123', name: 'New Name' }).then(result => {
    console.log(result.data);
  });
};

Getting Started

To start using urql in a React project:

  1. Install the necessary packages:

    npm install urql graphql
    
  2. Set up the client and provider:

    import { createClient, Provider } from 'urql';
    
    const client = createClient({
      url: 'https://api.example.com/graphql',
    });
    
    function App() {
      return (
        <Provider value={client}>
          {/* Your app components */}
        </Provider>
      );
    }
    
  3. Use the hooks in your components as shown in the code examples above.

Competitor Comparisons

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.

Pros of Apollo Client

  • More extensive feature set, including advanced caching and state management
  • Larger community and ecosystem, with more third-party integrations
  • Better documentation and learning resources

Cons of Apollo Client

  • Larger bundle size, which may impact performance for smaller applications
  • Steeper learning curve due to its complexity and extensive API
  • More opinionated approach, which may limit flexibility in some cases

Code Comparison

Apollo Client:

import { ApolloClient, InMemoryCache } from '@apollo/client';

const client = new ApolloClient({
  uri: 'https://api.example.com/graphql',
  cache: new InMemoryCache()
});

urql:

import { createClient } from 'urql';

const client = createClient({
  url: 'https://api.example.com/graphql',
});

Both Apollo Client and urql are popular GraphQL client libraries for JavaScript applications. Apollo Client offers a more comprehensive set of features and a larger ecosystem, making it suitable for complex applications. urql, on the other hand, provides a lighter-weight alternative with a simpler API, making it easier to get started and potentially more suitable for smaller projects or those requiring a more flexible approach.

5,803

Minimal GraphQL client

Pros of Graffle

  • Lightweight and minimalistic approach to GraphQL client implementation
  • Focuses on simplicity and ease of use for basic GraphQL operations
  • Potentially faster setup and integration for small-scale projects

Cons of Graffle

  • Less feature-rich compared to URQL, which offers more advanced capabilities
  • Smaller community and ecosystem, potentially leading to fewer resources and extensions
  • May not be suitable for complex GraphQL applications with advanced requirements

Code Comparison

URQL:

import { createClient, Provider, useQuery } from 'urql';

const client = createClient({
  url: 'https://api.example.com/graphql',
});

function App() {
  return (
    <Provider value={client}>
      <MyComponent />
    </Provider>
  );
}

Graffle:

import { createClient } from 'graffle';

const client = createClient({
  url: 'https://api.example.com/graphql',
});

function App() {
  return <MyComponent client={client} />;
}

Both URQL and Graffle provide GraphQL client solutions, but URQL offers a more comprehensive set of features and a larger ecosystem. Graffle, on the other hand, focuses on simplicity and ease of use for basic GraphQL operations. The code comparison shows that URQL uses a Provider component for context, while Graffle opts for passing the client directly to components.

8,602

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

Pros of urql

  • Lightweight and flexible GraphQL client
  • Easy to set up and use with minimal configuration
  • Supports various frameworks and environments

Cons of urql

  • Less extensive ecosystem compared to larger alternatives
  • May lack some advanced features found in more complex clients
  • Documentation could be more comprehensive for advanced use cases

Code Comparison

urql:

import { createClient, Provider } from 'urql';

const client = createClient({
  url: 'https://api.example.com/graphql',
});

function App() {
  return (
    <Provider value={client}>
      {/* Your app components */}
    </Provider>
  );
}

Additional Notes

Both repositories (urql-graphql/urql and urql-graphql/urql>) appear to be the same project. The comparison provided above is based on the features and characteristics of the urql GraphQL client. If there are specific differences between these two repositories, they are not immediately apparent from the repository names alone.

urql is known for its simplicity and ease of use, making it a popular choice for developers who want a lightweight GraphQL client. It provides a good balance between functionality and simplicity, although it may not have all the advanced features of some larger, more complex GraphQL clients.

A reference implementation of GraphQL for JavaScript

Pros of graphql-js

  • Reference implementation of GraphQL in JavaScript, ensuring high compatibility and adherence to the spec
  • Comprehensive and well-documented, covering all aspects of GraphQL server implementation
  • Widely adopted and battle-tested in production environments

Cons of graphql-js

  • Lower-level implementation, requiring more boilerplate code for setup and execution
  • Steeper learning curve for beginners due to its comprehensive nature
  • Lacks built-in client-side features, focusing primarily on server-side implementation

Code Comparison

graphql-js (server-side schema definition):

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      hello: {
        type: GraphQLString,
        resolve: () => 'Hello, World!'
      }
    }
  })
});

urql (client-side query execution):

const client = createClient({
  url: 'https://api.example.com/graphql',
});

const { data, fetching, error } = useQuery({
  query: 'query { hello }'
});

urql focuses on providing a streamlined client-side GraphQL experience, while graphql-js offers a comprehensive server-side implementation. urql simplifies client-side operations with a more declarative API, whereas graphql-js provides granular control over schema definition and execution on the server.

The Fullstack Tutorial for GraphQL

Pros of How to GraphQL

  • Comprehensive learning resource for GraphQL beginners
  • Covers multiple languages and frameworks
  • Community-driven with contributions from various experts

Cons of How to GraphQL

  • Not a production-ready GraphQL client
  • Less frequent updates compared to urql
  • Limited to educational purposes

Code Comparison

How to GraphQL (example query):

query {
  allPersons {
    name
    age
  }
}

urql (example query execution):

const { data, fetching, error } = useQuery({
  query: `
    query {
      allPersons {
        name
        age
      }
    }
  `,
});

Summary

How to GraphQL is an educational resource focused on teaching GraphQL concepts across various technologies. It's ideal for beginners but not intended for production use. urql, on the other hand, is a lightweight and versatile GraphQL client library for production applications.

How to GraphQL provides a wide range of tutorials and examples, making it excellent for learning. However, it may not be as up-to-date with the latest GraphQL developments as urql, which is actively maintained and regularly updated.

While How to GraphQL offers code examples in multiple languages, urql provides a more focused, production-ready solution for JavaScript and TypeScript applications, with features like caching and real-time updates.

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.

Pros of graphql-engine

  • Provides a complete backend solution with automatic CRUD API generation
  • Offers real-time subscriptions and event triggers out of the box
  • Includes a built-in authorization system for fine-grained access control

Cons of graphql-engine

  • Steeper learning curve due to its comprehensive feature set
  • Less flexibility in custom server-side logic compared to client-side solutions
  • Requires more setup and infrastructure management

Code Comparison

graphql-engine (Hasura configuration):

tables:
  - table:
      schema: public
      name: users
    insert_permissions:
      - role: user
        permission:
          check: {}
          columns:
            - name
            - email

urql (Client-side query):

const USERS_QUERY = `
  query {
    users {
      id
      name
      email
    }
  }
`;

const { data, fetching, error } = useQuery({ query: USERS_QUERY });

While graphql-engine focuses on server-side configuration and API generation, urql is a client-side GraphQL library for executing queries and managing data. graphql-engine provides a more comprehensive backend solution, while urql offers flexibility in client-side data fetching and state management.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

urql

A highly customisable and versatile GraphQL client

CI Status Weekly downloads Discord

✨ Features

urql is a GraphQL client that exposes a set of helpers for several frameworks. 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.

📃 For more information, check out the docs.

💙 Sponsors

BigCommerce
BigCommerce
WunderGraph
WunderGraph
The Guild
The Guild
BeatGig
BeatGig

🙌 Contributing

The urql project was founded by Formidable and is actively developed by the urql GraphQL team.

If you'd like to get involved, check out our Contributor's guide.

📦 Releases

All new releases and updates are listed on GitHub with full changelogs. Each package in this repository further contains an independent CHANGELOG.md file with the historical changelog, for instance, here’s @urql/core’s changelog.

If you’re upgrading to v4, check out our migration guide, posted as an issue.

New releases are prepared using changesets, which are changelog entries added to each PR, and we have “Version Packages” PRs that once merged will release new versions of urql packages. You can use @canary releases from npm if you’d like to get a preview of the merged changes.

📃 Documentation

The documentation contains everything you need to know about urql, and contains several sections in order of importance when you first get started:

Furthermore, all APIs and packages are self-documented using TSDocs. If you’re using a language server for TypeScript, the documentation for each API should pop up in your editor when hovering urql’s code and APIs.

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

NPM DownloadsLast 30 Days