Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
a1a88ce3
Commit
a1a88ce3
authored
4 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#59
modify graphQL example to request gva prototype
Improve client.query output on http error
parent
c4db9540
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/api/client.py
+7
-3
7 additions, 3 deletions
duniterpy/api/client.py
examples/request_graphql.py
+11
-10
11 additions, 10 deletions
examples/request_graphql.py
with
18 additions
and
13 deletions
duniterpy/api/client.py
+
7
−
3
View file @
a1a88ce3
...
...
@@ -19,6 +19,7 @@ import json
import
logging
from
typing
import
Callable
,
Union
,
Any
,
Optional
,
Dict
import
aiohttp
import
jsonschema
from
aiohttp
import
ClientResponse
,
ClientSession
,
ClientWebSocketResponse
from
aiohttp.client
import
_WSRequestContextManager
...
...
@@ -508,11 +509,14 @@ class Client:
# return the chosen type
result
=
response
# type: Any
if
rtype
==
RESPONSE_TEXT
:
if
rtype
==
RESPONSE_TEXT
or
response
.
status
>
399
:
result
=
await
response
.
text
()
elif
rtype
==
RESPONSE_JSON
:
try
:
result
=
await
response
.
json
()
except
aiohttp
.
client_exceptions
.
ContentTypeError
as
exception
:
logging
.
error
(
"
Response is not a json format
"
)
# return response to debug...
return
result
async
def
connect_ws
(
self
,
path
:
str
=
""
)
->
WSConnection
:
...
...
This diff is collapsed.
Click to expand it.
examples/request_graphql.py
+
11
−
10
View file @
a1a88ce3
...
...
@@ -11,7 +11,7 @@ from graphql.error import GraphQLSyntaxError
# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
# Here we use the secure BASIC_MERKLED_API (BMAS) for standard http over ssl requests
SWAPI_ENDPOINT
=
"
BMAS
swapi.graph.cool 443
"
SWAPI_ENDPOINT
=
"
BMAS
g1.librelois.fr 443 gva
"
################################################
...
...
@@ -27,16 +27,14 @@ async def main():
# convert response dict to schema
schema
=
build_client_schema
(
response
[
"
data
"
])
# create all films query
query
=
"""
query {
allFilms {
title,
characters {
name
}
# create currentUd query
query
=
"""
{
currentUd {
amount
}
}
"""
# check query syntax
try
:
ast_document
=
language
.
parse
(
query
)
...
...
@@ -53,6 +51,9 @@ async def main():
# send valid query to api
response
=
await
client
.
query
(
query
)
if
isinstance
(
response
,
str
):
print
(
response
)
else
:
print
(
json
.
dumps
(
response
,
indent
=
2
))
# Close client aiohttp session
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment