SettleMint SDK
✨ https://settlemint.com ✨
Integrate SettleMint into your application with ease.
Table of Contents
About
The SettleMint Hasura SDK provides a seamless way to interact with Hasura GraphQL APIs for managing application data. It enables you to easily query and mutate data stored in your SettleMint-powered PostgreSQL databases through a type-safe GraphQL interface.
For detailed information about using Hasura with the SettleMint platform, check out our official documentation.
API Reference
Functions
createHasuraClient()
createHasuraClient<Setup
>(options
, clientOptions
?): object
Defined in: sdk/hasura/src/hasura.ts:74
Creates a Hasura GraphQL client with proper type safety using gql.tada
Type Parameters
Setup extends AbstractSetupSchema |
Parameters
options | { accessToken : string ; adminSecret : string ; cache : "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" ; instance : string ; } | Configuration options for the client |
options.accessToken | string | - |
options.adminSecret ? | string | - |
options.cache ? | "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | - |
options.instance ? | string | - |
clientOptions ? | RequestConfig | Optional GraphQL client configuration options |
Returns
object
An object containing:
- client: The configured GraphQL client instance
- graphql: The initialized gql.tada function for type-safe queries
Throws
Will throw an error if the options fail validation against ClientOptionsSchema
Example
import { createHasuraClient } from '@settlemint/sdk-hasura';
import type { introspection } from "@schemas/hasura-env";
const { client, graphql } = createHasuraClient<{
introspection: introspection;
disableMasking: true;
scalars: {
timestamp: string;
timestampz: string;
uuid: string;
date: string;
time: string;
jsonb: string;
numeric: string;
interval: string;
geometry: string;
geography: string;
};
}>({
instance: process.env.SETTLEMINT_HASURA_ENDPOINT,
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
adminSecret: process.env.SETTLEMINT_HASURA_ADMIN_SECRET,
});
const query = graphql(`
query GetUsers {
users {
id
name
email
}
}
`);
const result = await client.request(query);
createPostgresPool()
createPostgresPool(databaseUrl
): Pool
Defined in: sdk/hasura/src/postgres.ts:83
Creates a PostgreSQL connection pool with error handling and retry mechanisms
Parameters
databaseUrl | string | The PostgreSQL connection URL |
Returns
Pool
A configured PostgreSQL connection pool
Throws
Will throw an error if called from browser runtime
Example
import { createPostgresPool } from '@settlemint/sdk-hasura';
const pool = createPostgresPool(process.env.SETTLEMINT_HASURA_DATABASE_URL);
const client = await pool.connect();
try {
const result = await client.query('SELECT NOW()');
console.log(result.rows[0]);
} finally {
client.release();
}
Type Aliases
ClientOptions
ClientOptions = z.infer
<typeof ClientOptionsSchema
>
Defined in: sdk/hasura/src/hasura.ts:25
Type definition for client options derived from the ClientOptionsSchema.
RequestConfig
RequestConfig = ConstructorParameters
<typeof GraphQLClient
>[1
]
Defined in: sdk/hasura/src/hasura.ts:10
Type definition for GraphQL client configuration options
Variables
ClientOptionsSchema
const
ClientOptionsSchema: ZodObject
<{ accessToken
: ZodString
; adminSecret
: ZodString
; cache
: ZodOptional
<ZodEnum
<["default"
, "force-cache"
, "no-cache"
, "no-store"
, "only-if-cached"
, "reload"
]>>; instance
: ZodUnion
<[ZodString
, ZodString
]>; }, "strip"
, ZodTypeAny
, { accessToken
: string
; adminSecret
: string
; cache
: "default"
| "force-cache"
| "no-cache"
| "no-store"
| "only-if-cached"
| "reload"
; instance
: string
; }, { accessToken
: string
; adminSecret
: string
; cache
: "default"
| "force-cache"
| "no-cache"
| "no-store"
| "only-if-cached"
| "reload"
; instance
: string
; }>
Defined in: sdk/hasura/src/hasura.ts:15
Schema for validating client options for the Hasura client.
Contributing
We welcome contributions from the community! Please check out our Contributing guide to learn how you can help improve the SettleMint SDK through bug reports, feature requests, documentation updates, or code contributions.
License
The SettleMint SDK is released under the FSL Software License. See the LICENSE file for more details.