Apollo-server: MySQL DataSource

Created on 31 Jul 2018  路  6Comments  路  Source: apollographql/apollo-server

Are there any plans to create a MySQL DataSource just like we have the REST DataSource?

If not, can you give any pointers on what would be the best way to connect to a MySQL DB directly, withou using a REST Server in the middle?

Thank you

Most helpful comment

There should be more and better documentation with examples of using Data Sources with databases, as apps have more of a need to connect with databases than REST sources.

A simple starter kit would be good.

That "fullstack-workshop-server" example still seems outdated as it refers to Facebook's dataloader, and may not be easy to start with for those who didn't attend the workshop.

All 6 comments

There are no plans to create a data source specifically for SQL, but the concept of data sources isn't limited to REST.

You can extend DataSource (from apollo-datasource) and add your own data access methods. Optionally, you can implement an initialize({ context, cache }) method to get access to the context (which is often used to store user information for example) and cache (so you can cache backend results).

Here is an example of a data source that uses Sequelize to access a database.

There should be more and better documentation with examples of using Data Sources with databases, as apps have more of a need to connect with databases than REST sources.

A simple starter kit would be good.

That "fullstack-workshop-server" example still seems outdated as it refers to Facebook's dataloader, and may not be easy to start with for those who didn't attend the workshop.

I left some sample code on https://github.com/tgriesser/knex/issues/2787 - its a bit hacky but it shows how to make a SQL datasource using Knex

See: https://github.com/tgriesser/knex/issues/2787#issuecomment-417765925

There are a couple of good examples in here, and some more information about connecting a database in our docs. Closing this issue now!

Was this page helpful?
0 / 5 - 0 ratings