So your GraphQL APIs and REST API kind of exist together. REST API is just your legacy system, and then GraphQL API is where you build all of your new technologies, your new business logic. So they both kind of live together.
For us, while we were adopting GraphQL, we had a few different options of plugging in GraphQL, and here are some of them. So we thought that we could start by converting our existing APIs into GraphQL and maybe do it one step at a time, one endpoint at a time. Another approach we thought was perhaps we could convert everything new that we're building into GraphQL APIs, and so we'd build these as standalone APIs, and this was especially useful for applications that are going to be powering UI front-end, like UI layers.
A few things that we had in mind before plugging in GraphQL was, when we were choosing an application, was who especially is the client that is going to be using the API, and if they would be open to calling GraphQL. So for example, if it was an external client or a customer, and we knew that they would not be open to calling GraphQL, perhaps we would introduce GraphQL in a different place. But if it was a front-end application, and front-end application would be open to calling GraphQL, then that would be a really good candidate of introducing a GraphQL API. Another thing was, how many downstream APIs are we calling, and this is especially useful because we were talking about getting smaller payloads, having a consistent experience, and detail analytics, so if we have multiple different APIs we're going to be calling, then it would be a really good candidate of calling, of creating a GraphQL layer. But if there is only one REST API we're going to be calling, it's not really a good application of GraphQL because then we'll be duplicating all of the work that's happening in the REST layer and making double the amount of effort. Another thing we had in mind was also what is the business impact and and the business side of application basically, so who does this business, who does this application serve, who are the stakeholders, what is the time frame, how long can we take to convert this app into a GraphQL layer or into a GraphQL app? So we thought that we'd first start with like a first application and kind of convert a first kind of like this demo application to a GraphQL application and so we started with the tool that I was working on, it was actually a new internal tool that we were building, our stakeholders were internal customers, internal teams actually, customer service reps, the, we were calling five different downstream APIs and the front-end application which was my team was super open to being integrated with GraphQL so it became a really good candidate for experimenting with GraphQL.
Our goal for this app was to make it fast and make it lightweight and basically that meant that we shouldn't send any extraneous data, so GraphQL was a really good candidate there and we didn't want to add any libraries that we didn't need, any third-party libraries that we didn't need and so what ended up happening was when we introduced GraphQL we noticed that we don't really need a lot of state management so we were able to get rid of Redux and we just use React State with the help of Apollo Cache to get rid of our state management solutions. So basically we ended up, with the help of GraphQL, we ended up shipping less data and we ended up using less libraries. And so for that business logic we were the team who owned one of the backend REST APIs so we ended up putting all of our heavy business logic in our backend REST API itself. We had our orchestration layer of GraphQL as kind of like a simple, like a proxy layer, between a front end, between our front end application and our business logic layer which was the REST API. For authentication we used existing REST APIs that exist in Paypal itself, so it was our existing infrastructure, and then the rest of the downstream REST APIs we kept it in the API itself, we did not touch any of that. So basically our GraphQL orchestration layer was a simple, thin orchestration layer, it kind of, it was really cool to see because you were still able to use all of the benefits of GraphQL and we found that GraphQL really works really well as an orchestration layer.
And so our architecture kind of looked like this. So we had the GraphQL layer that was the first layer that the UI would talk to, and that was the only layer that the UI would talk to. And then the GraphQL layer will kind of do the job of like figuring out when to call the authentication layer, when to call analytics, when to call REST API. So GraphQL kind of did this job of like acting as a facade between all of the different REST APIs we had in our application that the application was supposed to talk to. So basically what we ended up learning for our first application, that is that it's really cool to wrap a REST API with the GraphQL API and kind of work, kind of create our GraphQL layer as an orchestration layer. And the client is still able to use the benefits of GraphQL, even though we don't have to change anything that's downstream. And that was really awesome to see. And another thing was that because we also own the backend REST API, our backend developers didn't have to change the way that they were working. So it was really cool because they were independent and the way that they wanted to work, which was awesome. And it brought our front end and backend developers really close because we established a schema and we had a contract to go from. Everybody was talking to everybody and everybody was super happy because we had team collaboration. So we ended up creating GraphQL interface to orchestrate that new REST API, and we were able to deliver only the data that we need and make it easier to evolve the REST API over time.
Comments