swapped posting method, reformatted black
import json
-import statistics
-from typing import List, Tuple
+from typing import Tuple
from fastapi.testclient import TestClient
@@ -8,24 +7,24 @@ from ariadne import QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL
-def benchmark_simple(query, n:int = 10) -> Tuple:
- with open('benchmarks/simple.json') as f:
+def benchmark_simple_list(query: str) -> Tuple:
+ with open("benchmarks/simple.json") as f:
data = json.load(f)
app = GraphQL(schema, root_value=data)
-
client = TestClient(app)
+ request = client.post("/", json={"query": query})
- time_list = []
- for _ in range(n):
- request = client.post("/", data=query)
- time_list.append(request.elapsed.microseconds / 1000)
+ return request.status_code
- return {
- "min": min(time_list),
- "max": max(time_list),
- "avg": statistics.mean(time_list),
- }
+
+def benchmark_simple(query: str) -> Tuple:
+ data = [{"name": "John", "age": 23}]
+ app = GraphQL(schema, root_value=data)
+ client = TestClient(app)
+ request = client.post("/", json={"query": query})
+
+ return request.status_code
type_defs = gql(
@@ -44,22 +43,17 @@ type_defs = gql(
query = QueryType()
-simple_query_list = """
- {
- people{
- name,
- age
- }
- }
- """
-
-schema = make_executable_schema(type_defs, query)
+@query.field("people")
+def resolve_people(*_):
+ with open("benchmarks/simple.json") as f:
+ data = json.load(f)
+ return data
-def main():
- print(benchmark_simple(simple_query_list))
+@query.field("person")
+def resolve_person(*_):
+ return [{"name": "John", "age": 23}]
-if __name__== "__main__":
- main()
+schema = make_executable_schema(type_defs, query)
