Skip to content

Commit 663cf67

Browse files
author
Guillaume Raille
committed
add documentation
1 parent 434d934 commit 663cf67

File tree

15 files changed

+1284
-6
lines changed

15 files changed

+1284
-6
lines changed

LICENSE.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
MIT License
2+
Copyright (c) 2018 YOUR NAME
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
The above copyright notice and this permission notice shall be included in all
10+
copies or substantial portions of the Software.
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
SOFTWARE.

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Saleor GraphQL Loader
2+
3+
`saleor-gql-loader` is small python package that allows you to quickly and easily
4+
create entities such as categories, warehouses, products on your saleor website
5+
using the graphQL endpoint exposed by saleor.
6+
7+
As of now, `saleor-gql-loader` allows to create the following entities:
8+
9+
- [x] warehouse
10+
- [x] shipping_zone
11+
- [x] attribute
12+
- [x] attribute_value
13+
- [x] product_type
14+
- [x] category
15+
- [x] product
16+
- [x] product_variant
17+
18+
PR for supporting more graphQL mutations and/or queries are more than welcome.
19+
20+
In it's current state, the project is in very early alpha, might be unstable
21+
and no tests are provided.
22+
23+
_disclaimer: This project is not connected nor it has been endorsed by saleor
24+
team/community._
25+
26+
## installation
27+
28+
using Pypi:
29+
30+
```bash
31+
pip install saleor-gql-loader
32+
```
33+
34+
Or cloning the repo:
35+
36+
```bash
37+
git clone https://github.com/grll/saleor-gql-loader.git
38+
```
39+
40+
## usage
41+
42+
### prerequisities
43+
44+
The first requirement is to have a running saleor installation with the latest
45+
version installed (2.9).
46+
47+
Before being able to use the package to create entities you need to create a
48+
saleor app with the necessary permissions to create the entities you need.
49+
50+
One way of doing that is to use the specific django cli custom command `create_app`:
51+
52+
```bash
53+
python manage.py create_app etl --permission account.manage_users \
54+
--permission account.manage_staff \
55+
--permission app.manage_apps \
56+
--permission app.manage_apps \
57+
--permission discount.manage_discounts \
58+
--permission plugins.manage_plugins \
59+
--permission giftcard.manage_gift_card \
60+
--permission menu.manage_menus \
61+
--permission order.manage_orders \
62+
--permission page.manage_pages \
63+
--permission product.manage_products \
64+
--permission shipping.manage_shipping \
65+
--permission site.manage_settings \
66+
--permission site.manage_translations \
67+
--permission webhook.manage_webhooks \
68+
--permission checkout.manage_checkouts
69+
```
70+
71+
> This command will return a token. Keep it somewhere as it will be need to use the
72+
> loader.
73+
74+
### loading data
75+
76+
`saleor-gql-loader` package exposes a single class that needs to be initialized
77+
with the authentication token generated in the section above. Then for each entity
78+
that you want to create there is a corresponding method on the class.
79+
80+
```python
81+
from saleor_gql_loader import ETLDataLoader
82+
83+
# initialize the data_loader (optionally provide an endpoint url as second parameter)
84+
data_loader = ETLDataLoader("LcLNVgUt8mu8yKJ0Wrh3nADnTT21uv")
85+
86+
# create a warehouse
87+
warehouse_id = etl_data_loader.create_warehouse()
88+
```
89+
90+
by default the `ETLDataLoader` will create a warehouse with sensible default values
91+
in order to not make the query fail. You can override any parameter from the graphQL
92+
type corresponding to the input of the underlying mutation.
93+
94+
For example, to set the name and email of my warehouse:
95+
96+
```python
97+
# create a warehouse with specified name and email
98+
warehouse_id = etl_data_loader.create_warehouse(name="my warehouse name", email="email@example.com")
99+
```
100+
101+
When a input field is mandatory it will need to be passed as first argument for example
102+
you can't create an attribute_value without specifying on which attribute id:
103+
104+
```python
105+
# create a year attribute
106+
year_attribute_id = etl_data_loader.create_attribute(name="year")
107+
108+
# add the following year value to the year attribute
109+
possible_year_values = [2020, 2019, 2018, 2017]
110+
for year in possible_year_values:
111+
etl_data_loader.create_attribute_value(year_attribute_id, name=year)
112+
```
113+
114+
That's all there is to it. I added a jupyter notebook as an example with more usage [here](https://github.com/grll/saleor-gql-loader/blob/master/saleor_gql_loader/example.ipynb) where you will find a full
115+
example that I used to populate my data.
116+
117+
For more details, I recommend you to check out the code, I tried to document it as much
118+
as possible (it's only one module with one class).
119+
120+
once again for any new features additions comments, feel free to open an issue or
121+
even better make a Pull Request.

__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .data_loader import ETLDataLoader

0 commit comments

Comments
 (0)