doc/api/graphql/users_example.md
{{< details >}}
{{< /details >}}
You can query a subset of users in a GitLab instance by using:
cURL.Open GraphiQL:
https://gitlab.com/-/graphql-explorerhttps://gitlab.example.com/-/graphql-explorerCopy the following text and paste it in the left window. This query looks for a subset of users in a GitLab instance by username. Alternately, you can use their Global IDs.
{
users(usernames: ["user1", "user3", "user4"]) {
pageInfo {
endCursor
startCursor
hasNextPage
}
nodes {
id
username,
publicEmail
location
webUrl
userPermissions {
createSnippet
}
}
}
}
Select Play.
[!note] The GraphQL API returns a GlobalID, rather than a standard ID. It also expects a GlobalID as an input rather than a single integer.
This query returns the specified information for the three users with the listed username.
If you are signed in as an administrator, you can show the matching administrators
on the instance by adding the admins: true parameter to the query.
Change the second line to:
users(usernames: ["user1", "user3", "user4"], admins: true) {
...
}
Or you can get all of the administrators:
users(admins: true) {
...
}
The query includes:
pageInfoThis contains the data needed to implement pagination. GitLab uses cursor-based pagination. For more information, see Pagination in the GraphQL documentation.
nodesIn a GraphQL query, nodes represents a collection of nodes on a graph.
In this case, the collection of nodes is a collection of User objects. For each one,
the output includes:
id.membership fragment, which represents project or group membership that belongs
to that user. Fragments are indicated by the ...memberships notation.