Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion datajunction-server/datajunction_server/api/graphql/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import strawberry
from fastapi import Request
from strawberry.extensions.tracing import OpenTelemetryExtension
from strawberry.fastapi import GraphQLRouter
from strawberry.types import Info
from datajunction_server.api.graphql.queries.catalogs import list_catalogs
Expand Down Expand Up @@ -135,6 +136,11 @@ class Query:
)


schema = strawberry.Schema(query=Query)
schema = strawberry.Schema(
query=Query,
extensions=[
OpenTelemetryExtension,
],
)

graphql_app = GraphQLRouter(schema, context_getter=get_context)
21 changes: 13 additions & 8 deletions datajunction-server/datajunction_server/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Main DJ server app.
"""

from contextlib import asynccontextmanager
import logging
from datajunction_server.api import setup_logging # noqa

Expand Down Expand Up @@ -55,6 +56,17 @@

dependencies = [Depends(default_attribute_types), Depends(default_catalog)]


@asynccontextmanager
async def lifespan(app: FastAPI):
"""
Lifespan context for initializing and tearing down app-wide resources, like the FastAPI cache
"""
FastAPICache.init(InMemoryBackend(), prefix="inmemory-cache") # pragma: no cover

yield


app = FastAPI(
title=settings.name,
description=settings.description,
Expand All @@ -64,6 +76,7 @@
"url": "https://mit-license.org/",
},
dependencies=dependencies,
lifespan=lifespan,
)

app.add_middleware(
Expand Down Expand Up @@ -99,14 +112,6 @@
app.include_router(notifications.router)


@app.on_event("startup")
async def startup():
"""
Initialize FastAPI cache when the server starts up
"""
FastAPICache.init(InMemoryBackend(), prefix="inmemory-cache") # pragma: no cover


@app.exception_handler(DJException)
async def dj_exception_handler(
request: Request,
Expand Down
Loading
Loading