Skip to content

Commit e630eae

Browse files
author
Maxim Avanov
committed
Release 0.1.0
1 parent a264e81 commit e630eae

14 files changed

+1046
-109
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cache: pip
66

77
install:
88
- pip install -r ./requirements/test.txt
9+
- pip install -r ./requirements/minimal.txt
910
- pip install coveralls
1011
- pip install -e ./
1112
python:

README.rst

+86
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,90 @@ Compose GraphQL queries by defining Python types
3131
3232
pip install graphql-dsl
3333
34+
Let's take a manually written `GraphQL query <https://graphql.org/learn/schema/#the-query-and-mutation-types>`_:
35+
36+
.. code-block:: graphql
37+
38+
query {
39+
hero {
40+
name
41+
}
42+
droid(id: "2000") {
43+
name
44+
}
45+
}
46+
47+
48+
With ``graphql-dsl`` you can construct a similar query with the following Python snippet:
49+
50+
.. code-block:: python
51+
52+
from typing import NamedTuple
53+
from graphql_dsl import *
54+
55+
class Hero(NamedTuple):
56+
name: str
57+
58+
class Droid(NamedTuple):
59+
name: str
60+
61+
class HeroAndDroid(NamedTuple):
62+
hero: Hero
63+
droid: Droid
64+
65+
class Input(NamedTuple):
66+
droid_id: ID
67+
68+
q = GQL( QUERY | HeroAndDroid
69+
| WITH | Input
70+
| PASS | Input.droid_id * TO * HeroAndDroid.droid * AS * 'id'
71+
)
72+
73+
print(q.query)
74+
75+
and the output will be::
76+
77+
query HeroAndDroid($droidId:ID!){hero{name}droid(id:$droidId){name}}
78+
79+
The query builder supports both ``NamedTuple`` and ``@dataclass`` types, yet the latter has a slightly different
80+
field reference syntax (because dataclasses don't define class-level field getters):
81+
82+
.. code-block:: python
83+
84+
from dataclasses import dataclass
85+
from graphql_dsl import *
86+
87+
@dataclass
88+
class Hero:
89+
name: str
90+
91+
@dataclass
92+
class Droid:
93+
name: str
94+
95+
@dataclass
96+
class HeroAndDroid:
97+
hero: Hero
98+
droid: Droid
99+
100+
@dataclass
101+
class Input:
102+
droid_id: ID
103+
104+
q = GQL( QUERY | HeroAndDroid
105+
| WITH | Input
106+
| PASS | (Input, 'droid_id') * TO * (HeroAndDroid, 'droid') * AS * 'id'
107+
)
108+
34109
Find out more from `Official Documentation <https://graphql-dsl.readthedocs.io/en/develop/>`_.
110+
111+
112+
Test Suite
113+
----------
114+
115+
Test environment is based on `Nix <https://nixos.org/nix/>`_.
116+
117+
.. code-block:: bash
118+
119+
nix-shell
120+
pytest

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = 'graphql-dsl'
21+
copyright = '2020, Maxim Avanov'
22+
author = 'Maxim Avanov'
23+
24+
# The full version, including alpha/beta/rc tags
25+
release = '0.0.1'
26+
27+
28+
# -- General configuration ---------------------------------------------------
29+
30+
# Add any Sphinx extension module names here, as strings. They can be
31+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32+
# ones.
33+
extensions = [
34+
]
35+
36+
# Add any paths that contain templates here, relative to this directory.
37+
templates_path = ['_templates']
38+
39+
# List of patterns, relative to source directory, that match files and
40+
# directories to ignore when looking for source files.
41+
# This pattern also affects html_static_path and html_extra_path.
42+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
43+
44+
45+
# -- Options for HTML output -------------------------------------------------
46+
47+
# The theme to use for HTML and HTML Help pages. See the documentation for
48+
# a list of builtin themes.
49+
#
50+
html_theme = 'alabaster'
51+
52+
# Add any paths that contain custom static files (such as style sheets) here,
53+
# relative to this directory. They are copied after the builtin static files,
54+
# so a file named "default.css" will overwrite the builtin "default.css".
55+
html_static_path = ['_static']

docs/index.rst

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. graphql-dsl documentation master file, created by
2+
sphinx-quickstart on Sun May 10 13:29:16 2020.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
graphql-dsl
7+
===========
8+
9+
Compose GraphQL queries by defining Python types
10+
11+
Indices and tables
12+
==================
13+
14+
* :ref:`genindex`
15+
* :ref:`modindex`
16+
* :ref:`search`

docs/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

graphql_dsl/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .dsl import *
2+
from .types import ID
3+
4+
5+
__all__ = (
6+
'QUERY',
7+
'WITH',
8+
'PASS',
9+
'MUTATION',
10+
'TO',
11+
'AS',
12+
'GQL',
13+
'ID',
14+
)

0 commit comments

Comments
 (0)