summaryrefslogtreecommitdiff
path: root/docs/graphql-api-usage.rst
blob: caa1cfbca4423e72bf1fc758a0dad870758b76a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#####################
Using the GraphQL API
#####################

python-gitlab provides basic support for executing GraphQL queries and mutations.

.. danger::

   The GraphQL client is experimental and only provides basic support.
   It does not currently support pagination, obey rate limits,
   or attempt complex retries. You can use it to build simple queries

   It is currently unstable and its implementation may change. You can expect a more
   mature client in one of the upcoming major versions.

The ``gitlab.GraphQLGitlab`` class
==================================

As with the REST client, you connect to a GitLab instance by creating a ``gitlab.GraphQLGitlab`` object:

.. code-block:: python

   import gitlab

   # anonymous read-only access for public resources (GitLab.com)
   gl = gitlab.GraphQLGitlab()

   # anonymous read-only access for public resources (self-hosted GitLab instance)
   gl = gitlab.GraphQLGitlab('https://gitlab.example.com')

   # private token or personal token authentication (GitLab.com)
   gl = gitlab.GraphQLGitlab(private_token='JVNSESs8EwWRx5yDxM5q')

   # private token or personal token authentication (self-hosted GitLab instance)
   gl = gitlab.GraphQLGitlab(url='https://gitlab.example.com', private_token='JVNSESs8EwWRx5yDxM5q')

   # oauth token authentication
   gl = gitlab.GraphQLGitlab('https://gitlab.example.com', oauth_token='my_long_token_here')

Sending queries
===============

Get the result of a simple query:

.. code-block:: python

    query = """{
        query {
          currentUser {
            name
          }
        }
    """

    result = gl.execute(query)