An open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.
Common Directories
/graphql/graphiql/graphql.php/graphql/console
Basic Operations - Queries
We can fetch field information by sending queries.
query{__typename}
Fields
To fetch a field object, send a query like the following.
query{user{namefriends{name } }}
Arguments
We can get the specific information by padding arguments (e.g. id) to fields.
Aliases
We can set aliases each field to get multiple results in one request.
Fragments
We can define arbitrary fragment that is be reusable when fetching each field.
Operation Names
We can define an operation name to make an operation less ambiguous. By setting a name, it makes it easier to understand at a glance what kind of operation.
Variables
Directives
We can filter by passing a directive in fields.
include
Only include this field if the argument is true.
skip
Skip this field if the argument is true.
Basic Operations - Mutations
We can modify fields with the mutation field.
To modify a field, execute like the following.
Enumeration
SQL Injection
We might be able to inject SQL somewhere e.g. arguments. Please refer to SQL Injection Cheat Sheet for more payloads.
NoSQL Injection
We might be able to inject NoSQL somewhere e.g. arguments. Please refer to NoSQL Injection for more payloads.
query {
John: user (id: "1") {
name
age
}
Emma: user (id: "2") {
name
age
}
}
query {
firstUser: user (id: "1") {
...userFields
}
secondUser: user (id: "2") {
...userFields
}
fragment userFields on User {
name
age
friends {
name
}
}
}
query UserNameAndFriends {
user {
name
friends {
name
}
}
}
query UsrNameAndFriends($userId: ID) {
user (id: $userId) {
name
friends {
name
}
}
}
query UserNameAndFriends($userId: ID, $withFriends: Boolean!) {
user(id: $userId) {
name
friends @include(if: $withFriends) {
name
}
}
}
query UserNameAndFriends($userId: ID, $withFriends: Boolean!) {
user(id: $userId) {
name
friends @skip(if: $withFriends) {
name
}
}
}