Download tutorial as e-book ⚡️
Loading...

Basic Setup

Let's set up the scaffolding for our connector, and we'll see the first queries start to work. We'll also start to develop a test suite, and see our connector running in Hasura.

For now, we'll just handle the most basic queries, but later, we'll start to fill in some of the gaps in our implementation, and see more queries return results correctly.

The data source you'll be targeting is a SQLite database running on your local machine, and we'll be using the Hasura TypeScript connector SDK.

If you've cloned the repo in the previous step, you can follow along with the code in this tutorial.

Let's start by following the SDK guidelines and use the start function which take a connector of type Connector.

Start

In your src/index.ts file, add the following:

const connector: Connector<RawConfiguration, Configuration, State> = {};
start(connector);

We will also need some imports over the course of the tutorial. Paste these at the top of your index.ts file:

import sqlite3 from 'sqlite3';
import { Database, open } from 'sqlite';
import { BadRequest, CapabilitiesResponse, CollectionInfo, ComparisonValue, Connector, ExplainResponse, InternalServerError, MutationRequest, MutationResponse, NotSupported, ObjectField, ObjectType, OrderByElement, QueryRequest, QueryResponse, RowFieldValue, ScalarType, SchemaResponse, start } from "@hasura/ndc-sdk-typescript";
import { JSONSchemaObject } from "@json-schema-tools/meta-schema";
import { ComparisonTarget, Expression } from '@hasura/ndc-sdk-typescript/dist/generated/typescript/QueryRequest';

You'll notice that your IDE will complain about the connector object not having the correct type, and RawConfiguration, Configuration, State all being undefined. Let's fix that in the next section...

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin