Instant Hasura Native Data Connector by writing Typescript Functions
Repository
Current version released
7 months ago
Dependencies
other
Hasura NDC Typescript (Deno) Connector
The Typescript (Deno) Connector allows a running connector to be inferred from a Typescript file (optionally with dependencies).
Github Repository
See the Github Repo for additional details.
Quickstart
Once your project is set up, run locally with:
> cat config.json
{
"functions": "./functions/index.ts",
"vendor": "./vendor",
"preVendor": true,
"schemaMode": "INFER"
}
> deno run -A --watch --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json
Typescript Functions Format
Your functions should be organised into a directory with one file acting as the entrypoint.
An example Typescript entrypoint:
// functions/index.ts
import { Hash, encode } from "https://deno.land/x/checksum@1.2.0/mod.ts";
export function make_bad_password_hash(pw: string): string {
return new Hash("md5").digest(encode(pw)).hex();
}
/**
* Returns the github bio for the userid provided
*
* @param username - Username of the user who's bio will be fetched.
* @returns The github bio for the requested user.
* @pure This function should only query data without making modifications
*/
export async function get_github_profile_description(username: string): Promise<string> {
const foo = await fetch(`https://api.github.com/users/${username}`);
const response = await foo.json();
return response.bio;
}
export function make_array(): Array<string> {
return ['this', 'is', 'an', 'array']
}
type MyObjectType = {'foo': string, 'baz': Boolean}
export function make_object(): MyObjectType {
return { 'foo': 'bar', 'baz': true}
}
export function make_object_array(): Array<MyObjectType> {
return [make_object(), make_object()]
}
/**
* @pure
*/
export function has_optional_args(a: string, b?: string) {
if(b) {
return `Two args: ${a} ${b}`;
} else {
return `One arg: ${a}`;
}
}