Skip to content

Commit 097997a

Browse files
committed
feat: add basic GraphQL support (wip)
1 parent c7cf0d1 commit 097997a

13 files changed

+328
-100
lines changed

docs/api-usage.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
############################
2-
Getting started with the API
3-
############################
1+
##################
2+
Using the REST API
3+
##################
44

5-
python-gitlab only supports GitLab API v4.
5+
python-gitlab currently only supports v4 of the GitLab REST API.
66

77
``gitlab.Gitlab`` class
88
=======================

docs/cli-usage.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
############################
2-
Getting started with the CLI
3-
############################
1+
#############
2+
Using the CLI
3+
#############
44

55
``python-gitlab`` provides a :command:`gitlab` command-line tool to interact
66
with GitLab servers.

docs/graphql-api-usage.rst

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#####################
2+
Using the GraphQL API
3+
#####################
4+
5+
python-gitlab provides basic support for executing GraphQL queries and mutations.
6+
7+
.. danger::
8+
9+
The GraphQL client is experimental and only provides basic support.
10+
It does not currently support pagination, obey rate limits,
11+
or attempt complex retries. You can use it to build simple queries
12+
13+
It is currently unstable and its implementation may change. You can expect a more
14+
mature client in one of the upcoming major versions.
15+
16+
The ``gitlab.GraphQLGitlab`` class
17+
==================================
18+
19+
As with the REST client, you connect to a GitLab instance by creating a ``gitlab.GraphQLGitlab`` object:
20+
21+
.. code-block:: python
22+
23+
import gitlab
24+
25+
# anonymous read-only access for public resources (GitLab.com)
26+
gl = gitlab.GraphQLGitlab()
27+
28+
# anonymous read-only access for public resources (self-hosted GitLab instance)
29+
gl = gitlab.GraphQLGitlab('https://gitlab.example.com')
30+
31+
# private token or personal token authentication (GitLab.com)
32+
gl = gitlab.GraphQLGitlab(private_token='JVNSESs8EwWRx5yDxM5q')
33+
34+
# private token or personal token authentication (self-hosted GitLab instance)
35+
gl = gitlab.GraphQLGitlab(url='https://gitlab.example.com', private_token='JVNSESs8EwWRx5yDxM5q')
36+
37+
# oauth token authentication
38+
gl = gitlab.GraphQLGitlab('https://gitlab.example.com', oauth_token='my_long_token_here')
39+
40+
Sending queries
41+
===============
42+
43+
Get the result of a simple query:
44+
45+
.. code-block:: python
46+
47+
query = """{
48+
query {
49+
currentUser {
50+
name
51+
}
52+
}
53+
"""
54+
55+
result = gl.execute(query)

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
cli-usage
88
api-usage
99
api-usage-advanced
10+
graphql-api-usage
1011
cli-examples
1112
api-objects
1213
api/gitlab

gitlab/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
__title__,
3030
__version__,
3131
)
32-
from gitlab.client import Gitlab, GitlabList # noqa: F401
32+
from gitlab.client import Gitlab, GitlabList, GraphQLGitlab # noqa: F401
3333
from gitlab.exceptions import * # noqa: F401,F403
3434

3535
warnings.filterwarnings("default", category=DeprecationWarning, module="^gitlab")

0 commit comments

Comments
 (0)