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

Implementation

Right now, we only need to implement five required functions:

  • validate_raw_configuration - which validates the configuration provided by the user.
  • try_init_state - which initializes our database connection.
  • get_capabilities - which returns the capabilities of our connector as per the spec.
  • get_schema - which returns a spec-compatible schema containing our tables and columns.
  • query - which actually responds to query requests.

We'll skip configuration validation entirely for now, so in the validate_raw_configuration function which you pasted in the previous step, we'll just return the configuration. Edit it as follows:

async function validate_raw_configuration(configuration: RawConfiguration): Promise<RawConfiguration> {
return configuration;
}

To initialize our state, which in our case contains a connection to the database, we'll use the open function to open a connection to it, and store the resulting connection object in our state by returning it:

async function try_init_state(configuration: RawConfiguration, metrics: unknown): Promise<State> {
const db = await open({
filename: 'database.db',
driver: sqlite3.Database
});
return { db };
}

Our capabilities response will be very simple, because we won't support many capabilities yet. We just return the version range of the specification that we are compatible with, and the basic query capability.

function get_capabilities(configuration: RawConfiguration): CapabilitiesResponse {
return {
versions: "^0.1.0",
capabilities: {
query: {}
}
}
}
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