GraphQL

GraphQL query language commands and examples

18 commands
Search & Copy
Save Favorites
18
Total Commands
100%
Free Access
Lightning Fast

Available Commands

Click on any command to copy it instantly

18 commands available
18 of 18
Resources

Learn GraphQL

Master GraphQL query language

graphql

Introspection Query

Fetch GraphQL schema details

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ __schema { types { name } } }"}'
graphql
schema
introspection
graphql

Fetch All Users

Retrieve a list of all users

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ users { id name email } }"}'
graphql
users
query
graphql

Get User By ID

Retrieve a single user by ID

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ user(id: 1) { id name email } }"}'
graphql
user
query
graphql

Add New User

Create a new user via mutation

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"mutation { addUser(name: \"Alice\", email: \"alice@example.com\") { id name email } }"}'
graphql
user
mutation
graphql

Update User

Update an existing user's details

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"mutation { updateUser(id: 1, name: \"Alice Updated\") { id name email } }"}'
graphql
user
mutation
graphql

Delete User

Remove a user by ID

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"mutation { deleteUser(id: 1) { id } }"}'
graphql
user
mutation
graphql

Fetch All Posts

Retrieve all posts with fields

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ posts { id title content author { id name } } }"}'
graphql
posts
query
graphql

Get Post By ID

Retrieve a single post by ID

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ post(id: 1) { id title content author { name } } }"}'
graphql
post
query
graphql

Add Post

Create a new post via mutation

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"mutation { addPost(title: \"New Post\", content: \"Content here\", authorId: 1) { id title } }"}'
graphql
post
mutation
graphql

Update Post

Update an existing post

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"mutation { updatePost(id: 1, title: \"Updated Title\") { id title } }"}'
graphql
post
mutation
graphql

Delete Post

Remove a post by ID

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"mutation { deletePost(id: 1) { id } }"}'
graphql
post
mutation
graphql

Search Users by Name

Search for users matching a name

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ users(search: \"Alice\") { id name email } }"}'
graphql
search
users
graphql

Search Posts by Keyword

Search posts containing a keyword

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ posts(search: \"GraphQL\") { id title content } }"}'
graphql
search
posts
graphql

Nested Query Example

Query users with nested posts

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ users { id name posts { id title } } }"}'
graphql
nested
query
graphql

Pagination Example

Fetch paginated posts

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ posts(limit: 5, offset: 10) { id title } }"}'
graphql
pagination
query
graphql

Use Fragments

Query with reusable fragments

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"fragment userFields on User { id name email } query { users { ...userFields } }"}'
graphql
fragments
query
graphql

Aliases Example

Rename query results using aliases

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ admin: user(id:1) { name } guest: user(id:2) { name } }"}'
graphql
aliases
query
graphql

Using Directives

Use @include and @skip directives

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"query($showEmail:Boolean!) { users { name email @include(if:$showEmail) } }","variables":"{\"showEmail\":true}"}'
graphql
directives
query

Missing a command?

Help us improve this collection by suggesting commands that should be added. Your contributions help the entire developer community!