GraphQL is a query language and runtime for APIs that enables clients to request exactly the data they need. Developed by Facebook, GraphQL provides a more efficient, powerful, and flexible alternative to REST APIs by allowing clients to specify the structure of the response data.
# GraphQL Query
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
posts {
id
title
content
createdAt
comments {
id
content
author {
name
}
}
}
}
}
# Variables
{
"id": "123"
}
# Response
{
"data": {
"user": {
"id": "123",
"name": "John Doe",
"email": "john@example.com",
"posts": [
{
"id": "456",
"title": "GraphQL Introduction",
"content": "GraphQL is amazing...",
"createdAt": "2024-01-15T10:30:00Z",
"comments": [
{
"id": "789",
"content": "Great post!",
"author": {
"name": "Jane Smith"
}
}
]
}
]
}
}
}
# GraphQL Schema Definition
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
createdAt: DateTime!
}
type Post {
id: ID!
title: String!
content: String!
author: User!
comments: [Comment!]!
createdAt: DateTime!
updatedAt: DateTime!
}
type Comment {
id: ID!
content: String!
author: User!
post: Post!
createdAt: DateTime!
}
type Query {
user(id: ID!): User
users(limit: Int, offset: Int): [User!]!
post(id: ID!): Post
posts(authorId: ID, limit: Int): [Post!]!
}
type Mutation {
createUser(input: CreateUserInput!): User!
updateUser(id: ID!, input: UpdateUserInput!): User!
deleteUser(id: ID!): Boolean!
createPost(input: CreatePostInput!): Post!
}
type Subscription {
postAdded: Post!
commentAdded(postId: ID!): Comment!
}
input CreateUserInput {
name: String!
email: String!
}
input UpdateUserInput {
name: String
email: String
}
input CreatePostInput {
title: String!
content: String!
authorId: ID!
}
Average GraphQL Developer Salary
Growth in GraphQL Job Postings
GraphQL-Related Job Openings
Join thousands of professionals who've advanced their careers with Lead With Skills. Learn GraphQL, API design, and modern backend development from industry experts.