SQL DataSource for Apollo GraphQL projects (v2.1.0, released 2022-04-25). Combines Knex.js query builder with Apollo DataSources, providing caching, context, and declarative SQL queries. Ships TypeScript types. Requires peer dependencies graphql >=14.0.2 and knex >=0.95.0. Differentiates from raw Knex by integrating with Apollo's caching and request lifecycle, and from RESTDataSource by offering SQL-specific features like .cache() on queries. Active development with infrequent releases.
npm install datasource-sqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows creating a custom SQLDataSource class with a cached query using Knex, integrating with ApolloServer.
Append .cache(ttl) to your Knex query chains to enable caching.
Ensure knex >=0.95.0 is in your dependencies (not just devDependencies) and installed.
Update engines field in package.json or use nvm to switch to Node >=12.
Explicitly provide a cache (e.g., Memcached/Redis) in ApolloServer constructor via the cache option.
npm install knex (and graphql) as runtime dependencies.
Use const { SQLDataSource } = require('datasource-sql') or import { SQLDataSource } from 'datasource-sql'.Install knex >=0.95.0 and ensure it's added to package.json.