Closed
Description
When initing a new SQLDataSource in the datasources function with an existing knex connection it throws the following error:
Can't extend QueryBuilder with existing method ('cache')
Option 1: This does not work:
const dbConnection = Knex(knexConfig)
const server = new ApolloServer({
schema,
dataSources: () => ({ db: new SQLDataSource(dbConnection) })
})
The below both works:
Option 2: when you insert a dataSource that's called outside of the of the datasource function
const dbConnection = Knex(knexConfig)
const db = new SQLDataSource(dbConnection)
const server = new ApolloServer({
schema,
dataSources: () => ({ db })
})
Option 3: Or when you call the SQLDataSource function with the config instead of an existing connection
const server = new ApolloServer({
schema,
dataSources: () => ({ db: new SQLDataSource(knexConfig) })
})
The first example which doesn't work is what's most appealing to me. I have an external rest api that also uses the db connection so would be good to pass that one along. And according to the docs the datasources function should create a new instance of each data source for each operation which is not the case for option 2.
Metadata
Metadata
Assignees
Labels
No labels