https://github.com/coatl-labs/gql
A GraphQL client for Node.js (>=18) and the browser.
https://github.com/coatl-labs/gql
browser client gql graphql http nodejs query
Last synced: 25 days ago
JSON representation
A GraphQL client for Node.js (>=18) and the browser.
- Host: GitHub
- URL: https://github.com/coatl-labs/gql
- Owner: coatl-labs
- Created: 2022-09-04T17:49:10.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-02T18:31:56.000Z (over 3 years ago)
- Last Synced: 2025-10-03T04:55:14.353Z (9 months ago)
- Topics: browser, client, gql, graphql, http, nodejs, query
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @coatl/gql
A GraphQL client for Node.js and the browser.
## Requirements
- Node.js 18.0.0 or later (for Fetch API support)
- Any browser with Fetch API support
## Installation
```bash
# using npm
npm install @coatl/gql
# using yarn
yarn add @coatl/gql
# using pnpm
pnpm add @coatl/gql
```
## Features
- [x] Queries and mutations
- [x] Variable interpolation
- [x] Full type safety
- [x] Fragments
- [x] Subscriptions
- [ ] File uploads (multipart/form-data)
- [ ] Directives
- [ ] Custom scalars
## Usage
### Implementing a client
```ts
import { GQLClient } from '@coatl/gql'
export const client = new GQLClient('https://api.example.com/graphql', {
headers: {
Authorization: 'Bearer '
}
})
```
### Queries
```ts
import { client } from './client'
interface User {
id: string
name: string
email: string
}
const users = await client.query(`
users {
id
name
email
}
`)
console.log(users) // [...]
```
### Mutations
```ts
import { client } from './client'
interface User {
id: string
name: string
email: string
}
interface CreateUserInput {
name: string
email: string
}
const userExist = await client.query(`
# check if the user already exists
user(email: $email) {
id
}
`)
if (userExist) {
throw new Error('User already exists')
}
const variables = {
name: 'John Doe',
email: 'jhon@doe.com'
}
const user = await client.mutation(
`
createUser(input: $input) {
id
name
email
}
`,
variables
)
```