Skip to content

DenilssonMontoya/graphql-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graphql server - query example

Learn how to create a Graphql server using spring.

Prerequisites

  • Java 17.

Run Locally

Execute following commands to build and run the Graphql server.

# Build project & install dependencies
./gradlew build

# Run project 
./gradlew bootRun

Testing

This project uses a H2 database that serves as a source for the Person object that will be exposed using Graphql, to include additional information to query you need to modify resources/data.sql file and include new INSERT statements.

By using a GraphQL client like Postman we will be able to query our API. GraphQl server endpoint will be available at http://localhost:8080/graphql .

Query examples:

  • Query to obtain full Person object information
query personDetails {
  personById(id: 1) {
    id    
    name
    lastName
    gender
  }
}

postman01.png

  • Query to obtain just some attributes of Person object.
query personDetails {
  personById(id: 1) {
    id    
    name
  }
}

postman02.png

And just like that we got only the attributes that we need from our API.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages