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 http://forum.serverless.com/t/conditional-serverless-yml-based-on-stage/1763 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)

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

prod_functions:
  <<: *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).