Can we use both GraphQL and REST API in the same project?

0

I'm creating a mobile application and was thinking of using Amplify/AppSync to communicate with the backend from the app. However, we also have a lot of relational data and the backend isn't designed around GraphQL. Using GraphQL would be convenient in the mobile app, but not for other aspects.

So I was wondering if we can add both the REST API and the GraphQL API to the same project.

Thanks!

asked 3 years ago6308 views
4 Answers
0

Yes, this is possible to do.

hsspain
answered 3 years ago
0

Yes you can use both APIs by amplify add api command. You have to answer the questions asked about API configurations while creating API. Then proceed with the command again and add another API (either API gateway - REST or Appsync - GraphQL one)

Shaista
answered 2 years ago
0

It is possible to have a mix of APIs (GraphQL and REST, for example) in a project and even to share data stores (such as databases) between the various API schema. Nevertheless, you should be aware of some of the complexities that you have to face with such a decision and compare it to the option to convert the clients of the REST APIs to use GraphQL.

GraphQL is prevalent in mobile development as you want to be efficient in the number of calls that you need to do to the backend to fetch data, in the screen size of presenting that data, and the power (CPU, battery life...) of the mobile device to execute it. You might claim that these issues are not relevant to other data system interfaces such as desktops and prefer to use a more traditional API such as REST to build the interface.

When developing with a GraphQL attitude, you define the objects you want to work with using the format of GraphQL schema. In contrast, in the REST attitude, you will use Database Schema or API defined in code using frameworks such as FastAPI or Spring. GraphQL is more flexible, and you can create "graph" objects with columns or attributes from different related entities, while in REST, you will have to perform this logic on the client-side after calling multiple API calls to fetch the data.

There is also a tendency to associate GraphQL with a NoSQL database such as DynamoDB or MongoDB, and REST APIs more with Relational databases, where you can define relations between the objects in the "graph" in the relational model of the DB. This is also a type of a mix that you want to avoid, as data replication between these different datastore types is hard to maintain.

Eventually, you want to query and update the same object in the same datastore, and have different schema or datastore will make it complicated to evolve and modify them in parallel.

MLGuy
answered 2 years ago
0

Yes, you can definitely use both AWS AppSync (GraphQL) and AWS API Gateway (REST API) in the same project. AWS provides various services that allow you to build different types of APIs based on your project's requirements.

AWS
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions