Dac0d3r
Dac0d3r

Reputation: 1854

How to use apollo-datasource-rest without Apollo Server but with express-graphql

I'm in the process of making a graphql server that sits between our old rest api. There will be db connectivity, but in most cases the data in the graphql server will be coming from http calls to those rest api endpoints.

So far it has been possible to stick to the clean express-graphql server and avoid having to switch to Apollo server (using Relay in the frontend, so a bit hesitant of using Apollo server), but since these datasources are added under the property dataSources is apollo-datasource-rest an npm package that is baked into the Apollo Server, thus forcing us to switch if we want to use it, or is there some way to use datasources without their server library?

Upvotes: 1

Views: 490

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84867

There's work that Apollo Server does to initialize the data sources under the hood, so you wouldn't be able to just add the datasource to your context and call it a day.

That said, you can transition from express-graphql to apollo-server-express pretty seamlessly. All Apollo Server implementations accept a schema parameter to pass in an existing schema -- you don't have to utilize SDL if you don't want to. There's a few differences between what parameters the two libraries accept, but for the most part the APIs are very similar.

Upvotes: 1

Related Questions