It’s so fun!
A command like this is a good starting point to make sure that whatever GraphQL client in use is set up properly:
GRAPHQL_TOKEN=<your-token>
curl "https://gitlab.com/api/graphql" --header "Authorization: Bearer $GRAPHQL_TOKEN" \
--header "Content-Type: application/json" --request POST \
--data "{\"query\": \"query {currentUser {name}}\"}"
While curl is great, I am partial to using Insomnia as my client of choice for REST and GraphQL API calls. See [tools]. GraphiQL (pronounced “graphical”) is also great.
Get info about security scanners that are enabled, available and in the most recent successful pipeline run:
query {
project(fullPath: "bcarranza/detecting-secrets") {
name
id
securityScanners {
enabled
available
pipelineRun
}
}
}
Docs: SecurityScanners on GraphQL Reference
Get info about the user currently authenticated to GitLab:
query {
currentUser {
id
state
webPath
webUrl
status {
emoji
message
messageHtml
}
}
}
Queries are fun but I want to change things. Enter mutations.
mutation CreateBranch($projectPath: ID!) {
createBranch(input: { projectPath: "meow/whataboutme", ref:"master", name: "excellence"}) {
clientMutationId
errors
}
}
Alternately, set projectPath: $projectPath and set query variables:
Query Variables: {"projectPath": "meow/whataboutme"}