Spring Boot GraphQL Mongo DB Project Tutorial with Example for API Developers |

Опубликовано: 08 Октябрь 2024
на канале: codeonedigest
1,339
33

GraphQL Springboot Mongo database project to create graphql apis. Create springboot GraphQL application with Mongo database. Step by step guide to create GraphQL APIs in springboot with Mongo DB.

GraphQL is a query language to retrieve data from a server. It is an alternative to REST, SOAP or gRPC. GraphQL is that it is statically typed i.e., the server knows exactly the shape of every object you can query and any client can actually "introspect" the server and ask for the "schema". GraphQL allows the client to specify exactly what data it desires, including navigating child resources in a single request and allows for multiple queries in a single request. It uses named queries and mutations.

** GraphQL Schema **
The GraphQL server exposes a schema describing the API. This schema consists of type definitions. Each type has one or more fields, each taking zero or more arguments and returning a specific type. GraphQL Schema describes what queries are possible and what fields you can get back. The graph is derived from the way these fields are nested with each other.

** GraphQL Java **
The GraphQL Java Engine is only concerned with executing queries. It doesn't deal with any HTTP or JSON related topics. For these aspects, we will use Spring for GraphQL which takes care of exposing our API via Spring Boot over HTTP.

The main steps of creating a GraphQL Java server are:
1. Defining a GraphQL Schema.
2. Deciding on how the actual data for a query is fetched.

** Springboot GraphQL Starter **
The Spring Boot GraphQL Starter offers a fantastic way to get a GraphQL server running in a very short time. Using autoconfiguration and an annotation-based programming approach, we need only write the code necessary for our service. The GraphQL Boot starter works by processing GraphQL Schema files to build the correct structure and then wires special beans to this structure. The Spring Boot GraphQL starter automatically finds these schema files.

We need to annotate the handler methods with @QueryMapping #SchemaMapping & @MutationMapping annotations and place these inside standard @Controller components in our application. very complex type in the GraphQL server is represented by a Java bean. Fields inside the Java bean will directly map onto fields in the GraphQL response based on the name of the field.

** GraphiQL Tool **
GraphQL also has a companion tool called GraphiQL. This UI tool can communicate with any GraphQL Server and helps to consume and develop against a GraphQL API. This provides a very useful in-browser tool to write and test queries, particularly during development and testing.
** Postman Tool **
Postman is the API testing tool used by developers. We can use postman to test GraphQL queries. We can fire GraphQL GET Queries & Mutation Query from postman tool.

** Mongo Database **
MongoDB is a document database. It stores data in a type of JSON format called BSON. A record in MongoDB is a document, which is a data structure composed of key value pairs similar to the structure of JSON objects. There are many benefits of using mongodb hence many new projects are adopting nosql mongodb for their applications. Some of the benefits are
• Full cloud-based developer data platform.
• Flexible document schemas.
• Easy horizontal scale-out with sharding.
• Simple installation Cost-effective.

** Chapter Timestamps **
0:00 Welcome to Spring boot GraphQL Mongo DB API Project
1:16 Agenda of the Tutorial
2:50 Architecture Diagram
4:48 Spring Boot GraphQL Project Setup
5:21 Understand Maven Pom xml dependencies
7:06 Create GraphQL Schema file for Query & Mutation
9:27 Coding GraphQL Controllers & Repository Components
15:20 Understanding GraphQL configuration in application properties file
16:22 GIT project repository for GraphQL Project
17:34 Running Spring boot GraphQL Server
18:12 Testing GraphQL GET Data Query in GraphiQL Tool
20:51 Testing GraphQL GET Data Query in Postman Tool
23:54 GraphQL Mutation Explained
29:06 Testing GraphQL Mutation Query in GraphiQL Tool
32:29 Testing GraphQL Mutation Query in Postman Tool
37:07 Summary

#graphqlapi #graphql #springboottutorial

** CHECK OUR PLAYLISTS **
• GraphQL Tutorial for API Developers | GraphQL Explained with Example    • GraphQL Tutorial for API Developers |...  
• Cloud & Container Tutorial with AWS Cloud and Docker Containers    • Cloud & Container Tutorial with AWS C...  
• Microservice Introduction & Architecture Tutorial, Service Discovery, Registry    • Microservice Introduction & Architect...  
• Nodejs Javascript Tutorial for Microservice | Async non-blocking microservices    • Nodejs Tutorial for Microservice & Ev...  
• Spring Boot Tutorial with Project Setup, Annotations, Microservices, Rest api    • Spring Boot Tutorial with Project Set...