|
16 | 16 | "metadata": {}, |
17 | 17 | "outputs": [], |
18 | 18 | "source": [ |
19 | | - "import requests # should investigate writing a tornado transport\n", |
| 19 | + "from pprint import pprint\n", |
20 | 20 | "from getpass import getpass\n", |
21 | 21 | "from gql import Client, gql\n", |
22 | 22 | "from gql.transport.requests import RequestsHTTPTransport\n", |
23 | | - "from IPython.display import JSON\n", |
24 | | - "from pprint import pprint" |
| 23 | + "from IPython.display import JSON, IFrame\n", |
| 24 | + "import requests # should investigate writing a tornado transport" |
25 | 25 | ] |
26 | 26 | }, |
27 | 27 | { |
28 | 28 | "cell_type": "markdown", |
29 | 29 | "metadata": {}, |
30 | 30 | "source": [ |
31 | | - "You'll need your `jupyter notebook` or `jupyter lab` token (view source, look for `\"token\"`)" |
| 31 | + "## Client!" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "markdown", |
| 36 | + "metadata": {}, |
| 37 | + "source": [ |
| 38 | + "This has to know where you are. For example for `http://localhost:8888/lab`:" |
32 | 39 | ] |
33 | 40 | }, |
34 | 41 | { |
|
37 | 44 | "metadata": {}, |
38 | 45 | "outputs": [], |
39 | 46 | "source": [ |
40 | | - "token = getpass()" |
| 47 | + "URL = \"http://localhost:8888/graphql\"" |
41 | 48 | ] |
42 | 49 | }, |
43 | 50 | { |
44 | 51 | "cell_type": "markdown", |
45 | 52 | "metadata": {}, |
46 | 53 | "source": [ |
47 | | - "Update to suit!" |
| 54 | + "Since this is a _kernel_ talking back to the notebook _server_, you'll need your `jupyter notebook` or `jupyter lab` token (view source, look for `\"token\"`)" |
48 | 55 | ] |
49 | 56 | }, |
50 | 57 | { |
|
53 | 60 | "metadata": {}, |
54 | 61 | "outputs": [], |
55 | 62 | "source": [ |
56 | | - "URL = \"http://localhost:8888/graphql\"" |
57 | | - ] |
58 | | - }, |
59 | | - { |
60 | | - "cell_type": "markdown", |
61 | | - "metadata": {}, |
62 | | - "source": [ |
63 | | - "Make a client!" |
| 63 | + "token = getpass()" |
64 | 64 | ] |
65 | 65 | }, |
66 | 66 | { |
|
79 | 79 | "cell_type": "markdown", |
80 | 80 | "metadata": {}, |
81 | 81 | "source": [ |
82 | | - "Make a query!" |
| 82 | + "## Query!" |
83 | 83 | ] |
84 | 84 | }, |
85 | 85 | { |
|
88 | 88 | "metadata": {}, |
89 | 89 | "outputs": [], |
90 | 90 | "source": [ |
91 | | - "query = gql('''\n", |
92 | | - "query {\n", |
| 91 | + "query = \"\"\"{\n", |
93 | 92 | " contents(path: \"notebooks/gql.ipynb\") {\n", |
| 93 | + " path\n", |
| 94 | + " last_modified\n", |
94 | 95 | " ... on NotebookContents {\n", |
95 | | - " path\n", |
96 | 96 | " content {\n", |
97 | 97 | " nbformat\n", |
98 | 98 | " nbformat_minor\n", |
|
107 | 107 | " }\n", |
108 | 108 | " }\n", |
109 | 109 | "}\n", |
110 | | - "''')\n", |
111 | | - "query" |
| 110 | + "\"\"\"\n", |
| 111 | + "query_gql = gql(query)\n", |
| 112 | + "query_gql" |
112 | 113 | ] |
113 | 114 | }, |
114 | 115 | { |
|
124 | 125 | "metadata": {}, |
125 | 126 | "outputs": [], |
126 | 127 | "source": [ |
127 | | - "result = client.execute(query)\n", |
| 128 | + "result = client.execute(query_gql)\n", |
128 | 129 | "JSON(result)" |
129 | 130 | ] |
130 | 131 | }, |
131 | 132 | { |
132 | 133 | "cell_type": "markdown", |
133 | 134 | "metadata": {}, |
134 | 135 | "source": [ |
135 | | - "Where can you go from here?" |
| 136 | + "Where can you go from here? " |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "markdown", |
| 141 | + "metadata": {}, |
| 142 | + "source": [ |
| 143 | + "## Subscribe!\n", |
| 144 | + "With a little work up-front and even less work at query time, the same types from above can be used to power live _subscriptions_. Right now, only contents are available, but many things in the notebook server and broader ecosystem could become \"live\"." |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": null, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [], |
| 152 | + "source": [ |
| 153 | + "subscription = f\"subscription {query}\"\n", |
| 154 | + "print(subscription)" |
| 155 | + ] |
| 156 | + }, |
| 157 | + { |
| 158 | + "cell_type": "markdown", |
| 159 | + "metadata": {}, |
| 160 | + "source": [ |
| 161 | + "Go ahead and paste that in the iframe below and hit (▷)!\n", |
| 162 | + "> TODO: fix query param parsing!" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "code", |
| 167 | + "execution_count": null, |
| 168 | + "metadata": {}, |
| 169 | + "outputs": [], |
| 170 | + "source": [ |
| 171 | + "IFrame(URL, width=\"100%\", height=\"400px\")" |
136 | 172 | ] |
137 | 173 | } |
138 | 174 | ], |
|
152 | 188 | "name": "python", |
153 | 189 | "nbconvert_exporter": "python", |
154 | 190 | "pygments_lexer": "ipython3", |
155 | | - "version": "3.6.6" |
| 191 | + "version": "3.6.7" |
156 | 192 | } |
157 | 193 | }, |
158 | 194 | "nbformat": 4, |
|
0 commit comments