2023.41.0-RELEASE • Published 2 years ago

@hexworks/cobalt-graphql v2023.41.0-RELEASE

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

GraphQL Client for Cobalt

This library wraps the Apollo GraphQL Client with Functional Programming constructs, and also adds data validation and error handling.

Usage:

📘 Note that this library uses io-ts for data valiation.

First, you have to create an io-ts codec that represents the data that you'll receive:

import * as z from "zod";

const Events = t.array(
    t.strict({
        id: t.number,
        name: t.string,
    })
);

a GraphQL query:

import { DocumentNode } from "graphql";
import gql from "graphql-tag";

const query: DocumentNode = gql`
    query events($limit: Int) {
        events(first: $limitF) {
            id
            name
        }
    }
`;

and the corresponding client:

import { createGraphQLClient } from "@hexworks/cobalt-graphql";

const client = createGraphQLClient(URL);

Then you can call query to get your result:

const result = client.query(query, { limit: 10}, this.codec))