Skip to content

dumbjs/urql-generic-requester

Repository files navigation

urql-generic-requester

GraphQL Codegen Generic SDK Requester creator for URQL Client

Stargazers Issues

About

This package is to work with graphql-code-generator's generic sdk configuration which generates the sdk with a dynamic requester in place. Apollo supports it directly and so does other graphql solutions. This one is for urql/core

generates:
  sdk.ts:
    plugins:
      - typescript
      - typescript-generic-sdk

Install

The package depends on graphql and urql, so do install them. Ignore if you've already got them installed.

npm i urql-generic-requester graphql urql
# or
yarn add urql-generic-requester graphql urql

Usage

The library is typesafe and will infer types from urql's response structure for you to use as is.

import {createUrqlRequester} from 'urql-generic-requester'
import {createClient} from 'urql'

// get the sdk from the generated file from graphql-codegen
import {getSdk} from './sdk.ts'

const client = createClient({
  // ... urql client config and exchanges
})

const requestHandler = createUrqlRequester(client)

const sdk = getSdk(requestHandler)

License

MIT