GraphQL is the new standard for API and developed by Facebook as open-sourced. GrapgQL provides a more flexible, efficient, and more powerful API. it reduces network requests for that we need it in a single query. if we want in a single query then GraphQL is the better than REST.
For every client-server request then we need REST because each endpoint in a REST API has a fixed data structure. for example, if we request the employee name then we need to request the employee name by providing id of the employee but the return value is the entire row of the employee. here we are not getting the exact value of employee name. So the main problem in the above scenario is getting unnecessary data along with necessary data.
"Why GraphQl is Better Than Rest "
Uses of GraphQL:
- Architecture is client-driven not at server-driven like REST.
- performs the Operations at GraphQL as Querry mutation subscription.
- performs the Operations at REST as Create, Read, Update, and delete.
- The development speed is high and fast loading on the webpage.
- Only the required data will be present on the web.
- Less number of network requests.
- Very good for microservices and complex systems
- GraphQl has its own type system, these type system used to define the schema of as api
Uses of REST API:
- It is a stateless server and structured access to a resource.
- REST is the strict specification.
- REST has no its own type system like GraphQL.
How Data flow at GraphQL and Rest API
Rest API Request Flow:
GraphQL Request Flow:
Wha is Schema Definition Language (SDL)?
This type has 2 fields, they’re called name and deptid and are respectively of type String and Int. The "!" following the type means that this field is required.
So far we have seen request queries. Before going to Learn the in-depth concept of GraphQL, you should know the below 3 main concepts.
- type Query {..} syntax
- type Mutation{..} syntax
- type Subscription{..} syntax
1.1 type Query syntax with Arguments
2. type Subscription syntax
3. type Mutation syntax
Mutations create and modify objects. it is used to create, delete and update the data and similar to put, post, and delete the request in REST. Mutation query always start with mutation keyword
Post a Comment (0)