diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py index 92518245c7a2d4e103367a44916a2146112e5b5a..b2783221ca6766669200eb23c7721fcfc81ed6c0 100644 --- a/duniterpy/api/client.py +++ b/duniterpy/api/client.py @@ -179,7 +179,7 @@ class API: return response async def requests(self, method: str = 'GET', path: str = '', data: Optional[dict] = None, - _json: Optional[dict] = None) -> aiohttp.ClientResponse: + _json: Optional[dict] = None) -> ClientResponse: """ Generic requests wrapper on aiohttp diff --git a/duniterpy/api/gva/get_schema_query.graphql b/duniterpy/api/gva/get_schema_query.graphql new file mode 100644 index 0000000000000000000000000000000000000000..996742fafbe19695e84c3cd1ca253f0e3877306d --- /dev/null +++ b/duniterpy/api/gva/get_schema_query.graphql @@ -0,0 +1,99 @@ +query IntrospectionQuery { + __schema { + queryType { + name + } + mutationType { + name + } + subscriptionType { + name + } + types { + ...FullType + } + directives { + name + description + locations + args { + ...InputValue + } + } + } +} + +fragment FullType on __Type { + kind + name + description + fields(includeDeprecated: true) { + name + description + args { + ...InputValue + } + type { + ...TypeRef + } + isDeprecated + deprecationReason + } + inputFields { + ...InputValue + } + interfaces { + ...TypeRef + } + enumValues(includeDeprecated: true) { + name + description + isDeprecated + deprecationReason + } + possibleTypes { + ...TypeRef + } +} + +fragment InputValue on __InputValue { + name + description + type { + ...TypeRef + } + defaultValue +} + +fragment TypeRef on __Type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/duniterpy/api/gva/schema.qraphql b/duniterpy/api/gva/schema.qraphql deleted file mode 100644 index d12e5b2bb590e061cce96043eeff5e5f992dcf17..0000000000000000000000000000000000000000 --- a/duniterpy/api/gva/schema.qraphql +++ /dev/null @@ -1,62 +0,0 @@ -schema { - query: Query - mutation: Mutation -} - -################################# -# NODE types -################################# - -type Node { - summary: Summary - sandboxes: Sandboxes -} - -type Summary { - software: String! - version: String! - forkWindowSize: Int! -} - -type Sandbox { - size: Int! - free: Int! -} - -type Sandboxes { - identities: Sandbox! - memberships: Sandbox! - transactions: Sandbox! -} - -################################# -# WOT types -################################# - -type Identity { - version: Int! - type: String! - currency: String! - issuer: String! - uniqueID: String! - timestamp: String! - signature: String! -} - -################################# -# NODE queries -################################# - -type Query { - node: Node -} - -################################# -# WOT mutations -################################# - -type Mutation { - addIdentity ( - signedRaw: String! - ): Identity -} diff --git a/examples/request_swapi.py b/examples/request_swapi.py index b60aa14266113d70a77767730d0c2c6a25c82a9d..409dd2a9d03ac15f8403a1989ed947df9606ada1 100644 --- a/examples/request_swapi.py +++ b/examples/request_swapi.py @@ -1,8 +1,6 @@ import asyncio import os -import graphql - from duniterpy.api.client import Client # CONFIG ####################################### @@ -12,19 +10,23 @@ from duniterpy.api.client import Client # Here we use the secure BASIC_MERKLED_API (BMAS) SWAPI_ENDPOINT = "BMAS swapi.graph.cool 443" +GRAPHQL_GET_SCHEMA_QUERY_FILEPATH = "../duniterpy/api/gva/get_schema_query.graphql" + +GRAPHQL_SCHEMA_FILEPATH = "/tmp/duniterpy_example_swapi_schema.graphql" + ################################################ async def main(): + client = Client(SWAPI_ENDPOINT) - # validate duniter GVA graphql schema - with open(os.path.join(os.path.dirname(__file__), '../duniterpy/api/gva/schema.qraphql'), 'r') as fd: - document = graphql.parse(fd.read()) - schema = graphql.build_ast_schema(document) - print(schema) + # get SWAPI graphql schema + with open(os.path.join(os.path.dirname(__file__), GRAPHQL_GET_SCHEMA_QUERY_FILEPATH), 'r') as fd: + query = fd.read() - client = Client(SWAPI_ENDPOINT) + response = await client.query(query) + print(response) query = """query { allFilms {