From 954be34bc938acc9e14d9fb3b32c8f96cd999959 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 25 Sep 2024 14:02:52 -0500 Subject: http-api: T6736: remove routes on config delete Avoid duplicate entries in the list of routes when adding/deleting endpoints. --- src/services/api/graphql/routers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/services/api/graphql') diff --git a/src/services/api/graphql/routers.py b/src/services/api/graphql/routers.py index d04375a49..f02380cdc 100644 --- a/src/services/api/graphql/routers.py +++ b/src/services/api/graphql/routers.py @@ -38,6 +38,10 @@ def graphql_init(app: "FastAPI"): in_spec = state.introspection + # remove route and reinstall below, for any changes; alternatively, test + # for config_diff before proceeding + graphql_clear(app) + if state.origins: origins = state.origins app.add_route('/graphql', CORSMiddleware(GraphQL(schema, @@ -52,3 +56,9 @@ def graphql_init(app: "FastAPI"): context_value=get_user_context, debug=True, introspection=in_spec)) + + +def graphql_clear(app: "FastAPI"): + for r in app.routes: + if r.path == '/graphql': + app.routes.remove(r) -- cgit v1.2.3