Check out a free preview of the full Introduction to GraphQL course:
The "Layering GraphQL on REST" Lesson is part of the full, Introduction to GraphQL course featured in this preview video. Here's what you'd learn in this lesson:

Scott gives thoughts on layering GraphQL on to of REST.

Get Unlimited Access Now

Transcript from the "Layering GraphQL on REST" Lesson

[00:00:00]
>> Speaker 2: I have a question on talking to a REST API.
>> Scott Moss: Yep.
>> Speaker 2: From GraphQL and there's tools for that or?
>> Scott Moss: Yeah, so are you saying you have a REST API server and you have a GraphQL server and you want the GraphQL server to talk to the REST API server?

[00:00:17]
>> Speaker 2: Right.
>> Scott Moss: Yeah, so if you don't wanna manually do it as in, in my resolvers I'm setting all this stuff up, basically what you wanna do is, let's see. REST to, let's see if the, no, you wanna wrap it, nope. I'm looking for a specific one, I don't know if this is it.

[00:00:42] Maybe Apollo's the one that doesn't know. I think Apollo doesn't know.
>> Scott Moss: Schema-First. Yeah, I think Apollo doesn't know. So, yeah, that's right. So what you can do with Apollo is basically, you can define different data resources for your GraphQL API to contact. And one of those data resources can be a REST API.

[00:01:06] It doesn't have to be a database, it can be a REST API. And then that way you're basically just gonna be writing different resolvers that talk to different parts of your REST API. Like this resolver talks to this part of API, this resolver talks to this part of the API and so forth.

[00:01:21] All this stuff is very new and experimental, so I can't comment on how good it is. There's also another one, this isn't the one I was looking for. There's another one that I can't think of right now, maybe it died because this one put it out of business, but yeah.

[00:01:34] There's wrappers that do it, in my opinion, I myself would do it manually. Because it's strict and it's legible. If you do it automatically, I don't know, I feel like you give up control. With something so strict as GraphQL giving up control is not a good idea in my opinion.

[00:01:54] But feel free to check this out which is called layer GraphQL with Apollo MVRP. No, that's just an example of API, but yeah, Layer GraphQL. So check that out, and see how they did it, but they're using something called RESTDataSource. This is very new. I've never even seen this before, but I'm guessing, yeah, this allows you to define a RESTDataSource that creates resolvers that interact with your REST API, that delegate to your GraphQL schema.

[00:02:26] So at the end of the day, it looks like they're just creating your GraphQL schema on the fly using schema stitching to wrap your GraphQL API. So, that sounds like a pretty good way to do it. I think I would've done it that way. But I still would do it manually myself.