You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
5.0 KiB
128 lines
5.0 KiB
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "markdown", |
|
"id": "c5130422", |
|
"metadata": {}, |
|
"source": [ |
|
"# Bulk upload data via GraphQL endpoint" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 1, |
|
"id": "0019cd52-56b8-4f1d-82f5-55137f05456b", |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"name": "stdout", |
|
"output_type": "stream", |
|
"text": [ |
|
"zsh:1: no matches found: gql[all]\n", |
|
"Note: you may need to restart the kernel to use updated packages.\n" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"pip install gql[all] aiohttp" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 2, |
|
"id": "6658fd82-d8db-4a80-a103-3f015c851e69", |
|
"metadata": { |
|
"scrolled": true, |
|
"tags": [] |
|
}, |
|
"outputs": [ |
|
{ |
|
"ename": "ModuleNotFoundError", |
|
"evalue": "No module named 'gql'", |
|
"output_type": "error", |
|
"traceback": [ |
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", |
|
"\u001b[1;32m/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js query.ipynb Cell 3\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=0'>1</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39masyncio\u001b[39;00m\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=2'>3</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mgql\u001b[39;00m \u001b[39mimport\u001b[39;00m Client, gql\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=3'>4</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mgql\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtransport\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39maiohttp\u001b[39;00m \u001b[39mimport\u001b[39;00m AIOHTTPTransport\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=5'>6</a>\u001b[0m transport \u001b[39m=\u001b[39m AIOHTTPTransport(\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=6'>7</a>\u001b[0m url\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mhttp://wiki:3000/graphql\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=7'>8</a>\u001b[0m headers\u001b[39m=\u001b[39m{\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=10'>11</a>\u001b[0m },\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Wiki-js%20query.ipynb#ch0000003?line=11'>12</a>\u001b[0m )\n", |
|
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'gql'" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"import asyncio\n", |
|
"\n", |
|
"from gql import Client, gql\n", |
|
"from gql.transport.aiohttp import AIOHTTPTransport\n", |
|
"\n", |
|
"transport = AIOHTTPTransport(\n", |
|
" url=\"http://wiki:3000/graphql\",\n", |
|
" headers={\n", |
|
" \"Content-type\": \"application/json\",\n", |
|
" \"Authorization\": \"os.env(directus_token)\",\n", |
|
" },\n", |
|
")\n", |
|
"\n", |
|
"client = Client(transport=transport, fetch_schema_from_transport=False)\n", |
|
"\n", |
|
"query = gql(\n", |
|
" \"\"\"\n", |
|
" query pageList {\n", |
|
" pages {\n", |
|
" list(locale: \"en\") {\n", |
|
" id\n", |
|
" path\n", |
|
" locale\n", |
|
" title\n", |
|
" description\n", |
|
" contentType\n", |
|
" isPublished\n", |
|
" isPrivate\n", |
|
" privateNS\n", |
|
" createdAt\n", |
|
" updatedAt\n", |
|
" tags\n", |
|
" }\n", |
|
" }\n", |
|
" }\n", |
|
"\"\"\"\n", |
|
")\n", |
|
"\n", |
|
"result = await client.execute_async(query)\n", |
|
"print(result)" |
|
] |
|
} |
|
], |
|
"metadata": { |
|
"kernelspec": { |
|
"display_name": "Python 3.8.9 64-bit", |
|
"language": "python", |
|
"name": "python3" |
|
}, |
|
"language_info": { |
|
"codemirror_mode": { |
|
"name": "ipython", |
|
"version": 3 |
|
}, |
|
"file_extension": ".py", |
|
"mimetype": "text/x-python", |
|
"name": "python", |
|
"nbconvert_exporter": "python", |
|
"pygments_lexer": "ipython3", |
|
"version": "3.8.9" |
|
}, |
|
"vscode": { |
|
"interpreter": { |
|
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" |
|
} |
|
}, |
|
"widgets": { |
|
"application/vnd.jupyter.widget-state+json": { |
|
"state": {}, |
|
"version_major": 2, |
|
"version_minor": 0 |
|
} |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 5 |
|
}
|
|
|