0.0.25 • Published 1 year ago
hasura-gql-client v0.0.25
hasura-gql-client
Typescript based Hasura GQL client for NodeJS/TS/JS apps.
- 🚀 Blazing fast GraphQL
- ⚡️ Lightning Fast
- 🔑 Fully Typed APIs
- 🛠️ Rich Features
- 📦 Optimized Build
- 🥴 No Graphql string mess
Installation
yarn add hasura-gql-client
or
npm i hasura-gql-client
Settings
import Client from 'hasura-gql-client';
interface TestBook {
id: string;
name: string;
}
interface TestUser {
id: string;
email: string;
books: TestBook[];
book: TestBook;
}
interface Select {
test_user: TestUser;
test_book: TestBook;
}
// Insert type
interface InsertTestUser {
email: string;
}
interface InsertTestBook {
name: string;
}
interface Insert {
test_user: InsertTestUser;
test_book: InsertTestBook;
}
// Update type
interface UpdateTestUser {
email?: string;
}
interface UpdateTestBook {
name: string;
}
interface Update {
test_user: UpdateTestUser;
test_book: UpdateTestBook;
}
const client = new Client<Select, Insert, Update>({
host: process.env.HOST ?? 'err',
customHeaders: { 'x-hasura-admin-secret': process.env.X_HASURA_ADMIN_SECRET ?? 'err' },
debug: true,
});
const start = async (): Promise<void> => {
// select
const usersSelect2 = await client.select('test_user', ['id', 'book.name', 'books.id']);
console.log(usersSelect2[0]?.id);
console.log(usersSelect2[0]?.books[0].id);
console.log(usersSelect2[0]?.book.name);
// insert
const usersInsert = await client.insert('test_user', { email: 'foo@email.com', name: 'foo' }, ['id']);
console.log(usersInsert[0].id);
// update
const usersUpdate = await client.update('test_user', { email: 'foo2@email.com' }, ['id']);
console.log(usersUpdate[0].id);
};
start().catch(console.error);
See example folder for more details.
0.0.25
1 year ago
0.0.24
2 years ago
0.0.23
2 years ago
0.0.22
2 years ago
0.0.21
2 years ago
0.0.20
2 years ago
0.0.19
2 years ago
0.0.18
2 years ago
0.0.17
2 years ago
0.0.16
2 years ago
0.0.15
2 years ago
0.0.14
2 years ago
0.0.13
2 years ago
0.0.12
2 years ago
0.0.11
2 years ago
0.0.10
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago