A Bird's Eye View of GraphQL
Ravi Shankar
Experienced Software Testing Leader | Expertise in Test Automation & Performance
Let us start looking at GraphQL. GraphQL is a query language
GraphQL exists as a layer between the frontend and backend of the application. Client specifies the data
GraphQL has a number of design principles:
Key Components of GraphQL APIs
A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type. E.g. The below is a GraphQL schema for a query called bookById that returns the details of a specified book.
type Query {
bookById(id: ID): Book
}
type Book {
id: ID
name: String
pageCount: Int
author: Author
}
type Author {
id: ID
firstName: String
lastName: String
}
This is served by the following functions:
public Book bookById(@Argument String id) {
return Book.getById(id);
}
public Author author(Book book) {
return Author.getById(book.authorId());
}
GraphQL supports mainly 2 types of operations:-
e.g.?
领英推荐
query hero{
name
appearsIn
Id
}
We should get something like this as a result
{
"data": {
"hero": {
"name": "R2-D2",
"appearsIn": [
"NEWHOPE",
"EMPIRE",
"JEDI"
],
"id": "2001"
}
}
}
We can add arguments to further filter things out.
e.g.
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
createReview(episode: $ep, review: $review) {
stars
commentary
}
}
This would result in the something like the below
{
"ep": "JEDI",
"review": {
"stars": 5,
"commentary": "This is a great movie!"
}
}
Some Public GraphQL APIs
#apis #fundamentals #graphql
Senior Consultant |Product Owner | PMP | Test Management | JIRA | Agile | Scrum |Azure CI/CD | PLM
10 个月Very helpful!
Software Engineer III at Walmart || Mentor at crio.do || Expertise in Software Quality Engineering || Building problem solving skills || Content creator @youtube/CodewithKrishnendu
10 个月Thanks Ravi for this, this is something in my to-do list as well, soon, I will be preparing something on this too. GraphQL is something which we need to explore more. Good initiative??
Salesforce Trailblazer Community Speaker, Senior Architect
10 个月Insightful!