Conditionally deploy endpoints?

I’m using graphql with my stack and one of the convienent development endpoints is graphiql which points to the POST graphql endpoint for testing queries. However, I only want to use this endpoint during development, i.e. sls offline start.

Is there a way to conditionally deploy API Gateway endpoints?

I read this post but I couldn’t found out how their solution works.

Maybe. If you can it’s going to look something like this.

default_functions: &default_functions
  # Put your function definitions here (except graphiql)

  <<: *default_functions
  # Add the definitions for graphiql here

  <<: *default_functions

functions: ${self:${self:custom.stage}_functions}

What you’re doing is:

  1. Setting up default_functions with all of your functions except graphiql
  2. Setting up a section for each each stage dev_functions and prod_functions that inherits the values from default_functions then you’re adding graphiql to only the dev_functions stage.
  3. Setting up functions to inherit from the functions for the current stage (dev_functions or prod_functions).