router_custom_app.include_router(router_custom_app_s3) router_custom_app.include_router(router_custom_app_cascade) router_custom_app.include_router(router_custom_app_ws) # graphql class Query(graphene.ObjectType): hello = graphene.String(name=graphene.String(default_value="stranger")) def resolve_hello(self, info, name): return "Hello " + name # graphql - http://127.0.0.1:3000/api/graphql (it did not recognize prefix... like websockets currently) # https://fastapi.tiangolo.com/advanced/graphql/ router_custom_app.add_route("/graphql", GraphQLApp(schema=graphene.Schema(query=Query))) @router_custom_app.get("/ext-db", tags=["api_custom_app"]) async def ext_db(): result = get_db().execute("select * from books") names = [row[1] for row in result] print(names) return {"Where": "ext-db", "test": names} @router_custom_app.get("/ext-spawn", tags=["api_custom_app"]) async def ext_spawn(): spawn_path = set_model_path("run_model.py") subprocess.Popen( ["python", spawn_path], # program and arguments
import datetime from cpuinfo import get_cpu_info from fastapi import APIRouter from fastapi.responses import ORJSONResponse from loguru import logger from starlette_exporter import handle_metrics from endpoints.health.checks import get_processes router = APIRouter() # TODO: detmine method to shutdown/restart python application # TODO: Determine method to get application uptime router.add_route("/metrics", handle_metrics) @router.get("/status", tags=["system-health"], response_class=ORJSONResponse) async def health_main() -> dict: """ GET status, uptime, and current datetime Returns: dict -- [status: UP, uptime: seconds current_datetime: datetime.now] """ result: dict = {"status": "UP"} return result @router.get("/system-info", tags=["system-health"])
ensemble = gr.Field(Ensemble, id=gr.ID(required=True)) @staticmethod def resolve_experiments(root: Any, info: ResolveInfo) -> None: return ["default"] @staticmethod def resolve_experiment(root: Any, info: ResolveInfo, id: str) -> None: return "default" @staticmethod def resolve_ensemble(root: Any, info: ResolveInfo, id: str) -> None: return get_name("ensemble", id) class Mutations(gr.ObjectType): create_experiment = CreateExperiment.Field() create_ensemble = gr.Field( CreateEnsemble, active_realizations=gr.List(gr.Int), parameter_names=gr.List(gr.String), size=gr.Int(), experiment_id=gr.ID(required=True), ) schema = gr.Schema(query=Query, mutation=Mutations) graphql_app = GraphQLApp(schema=schema) router = APIRouter(tags=["graphql"]) router.add_route("/gql", graphql_app)
# FastAPI from fastapi import APIRouter # GraphQL import graphene from starlette.graphql import GraphQLApp from .graphql.schema import schema # Routers from .rest.notes import router as notes_router from .rest.users import router as users_router from .rest.login import router as login_router from .websocket.notes import router as notes_ws_router # Routes api_v1_router = APIRouter() api_v1_router.include_router(notes_router, prefix="/notes", tags=["notes"]) api_v1_router.include_router(users_router, prefix="/users", tags=["users"]) api_v1_router.include_router(login_router, prefix="/login", tags=["login"]) api_v1_router.add_route("/graphql", GraphQLApp(schema=schema, graphiql=True)) api_v1_router.include_router(notes_ws_router, prefix="/notes/ws", tags=["ws"])
from graphql.execution.executors.asyncio import AsyncioExecutor # type: ignore from fastapi import APIRouter from starlette.graphql import GraphQLApp from ..graphql import schema router = APIRouter() router.add_route("/graphql", GraphQLApp(schema=schema, executor_class=AsyncioExecutor))
import graphene from fastapi import FastAPI, APIRouter from starlette.graphql import GraphQLApp graph_router = APIRouter(tags=["Graphql"]) app = FastAPI(title='ContactQL', description='GraphQL Contact APIs', version='0.1') class Query(graphene.ObjectType): hello = graphene.String(name=graphene.String(default_value="stranger")) def resolve_hello(self, info, name): return "Hello " + name @graph_router.get("/") async def root(): return {"message": "Contact Applications!"} graph_router.add_route("/graphql", GraphQLApp(schema=graphene.Schema(query=Query)))
class NewsList(ObjectType): news = List(News, required=True, filter_by_date=Boolean(default_value=False)) @staticmethod def resolve_news(parent, info, filter_by_date): if filter_by_date: return sorted(news_source, key=lambda x: x.publish_date) resolver = get_news_list_resolver(parent, info, filter_by_date) return news_source news_source = [ News( author=NewsAuthor(name='Victor', author_id=1), content=NewsContent(title='First', text='WOW!'), publish_date=date.today(), ), News(author=NewsAuthor(name='Eugene', author_id=2), content=NewsContent(title='Second', text='WOW 222!'), publish_date=date.today() - timedelta(days=1)), ] router = APIRouter() router.add_route("/graphql", GraphQLApp(schema=graphene.Schema(query=NewsList)))
cfg.applogger.info( f'No pool record found for {username}, creating a default one...' ) class USER_NAMESPACE: bytes = bytes(username, 'utf-8') default_rec = PoolListModel( poolId=str(uuid5(USER_NAMESPACE, username + 'Watchlist')), username=username, poolDisplay='Watchlist', poolType='default', poolDesc='System default list, cannot be deleted', oderId=0) dbsession.add(default_rec) dbsession.commit() return fetchRec() gql_app = GraphQLApp(schema=Schema(query=GQuery, mutation=GMutation), executor_class=AsyncioExecutor) router.add_route("/", gql_app) @router.get('/test') # async def f(request: Request, some_dep=Depends()): async def f(request: Request): return await gql_app.handle_graphql(request=request)