From ee73475df52954245e4e56149dfd405eb8e1b71d Mon Sep 17 00:00:00 2001
From: vtexier <vit@free.fr>
Date: Sun, 28 Apr 2019 18:35:22 +0200
Subject: [PATCH] issue #59 WIP: graphql lib removed, get schema query added

---
 duniterpy/api/client.py                    |  2 +-
 duniterpy/api/gva/get_schema_query.graphql | 99 ++++++++++++++++++++++
 duniterpy/api/gva/schema.qraphql           | 62 --------------
 examples/request_swapi.py                  | 18 ++--
 4 files changed, 110 insertions(+), 71 deletions(-)
 create mode 100644 duniterpy/api/gva/get_schema_query.graphql
 delete mode 100644 duniterpy/api/gva/schema.qraphql

diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py
index 92518245..b2783221 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 00000000..996742fa
--- /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 d12e5b2b..00000000
--- 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 b60aa142..409dd2a9 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 {
-- 
GitLab