jetbridge/flask_cognito

Using Flask_Cognito with add_url_rule()

Opened this issue · 3 comments

Hi am very new to flask. How can one use this library with the add_url_rule() method for authentication?

app.add_url_rule(
'/example', #the endpoint
view_func=GraphQLView.as_view( #setting the view function
'lta',
#we set the schema that we generate
schema=schema,
#we say that we do want to use graphqli interface
graphiql=True))

I'm not positive but maybe try view_func= cognito_auth_required(GraphQLView.as_view( ...

a decorator is just a function that takes a function and returns a function

Yes, you can do as @revmischa says. I've done something like this but in a separate function:

def graphql_view():
    view = GraphQLView.as_view('graphql', schema=schema, graphiql=True)
    return cognito_auth_required(view)

app.add_url_rule('/graphql', view_func=graphql_view())