Mocked/Demo Endpoints for Dev Testing

It’s often the case that during development, you have lifecycle methods or event bindings that fire very rapidly.

When these methods apply to a live datasource, you rack up query usage quota quickly. I found that in 5-10 minutes of bootstrapping a new frontend, even with debouncing, that things like search bars and hot-reloading combined with lifecycle data hooks had run up several hundred queries.

I recognize that processing these requests is not resource-free. But maybe a mocking or demo gateway could be provided that used memoized pre-generated field data inferred from the column type to prevent the request from actually querying or computing anything?

This may go hand-in-hand with the idea of integrating something like Faker.js for seed data using MySQL column types and introspections to generate records - so two birds, one stone.

Hey @GavinRay! I totally get it and agree. Hot reloading is your most expensive friend in this scenario.

It’s really hard for us to discern which requests to “count” in such situations, and as a result encourage that a client side caching solution is the best way to go.

Check out the apollo caching docs: https://www.apollographql.com/docs/react/caching/cache-interaction/

What about using Apollo’s addMockFunctionsToSchema() that take a schema definition from makeExecutableSchema()?

If you want to offload to client side, maybe we could query our schema definition, or schema string, and then pass that to makeExecutableSchema() and wrap the result in addMockFunctionsToSchema()?

Or provide some sort of local dev CLI function to do this?

Bah boom:

query {
  __schema {
    queryType { ...SchemaResponse }
    mutationType { ...SchemaResponse }
    subscriptionType { ...SchemaResponse }
  }
}

fragment SchemaResponse on __Type {
  name
  fields {
    name
    type {
      name
      kind
      description
      fields {
        name
        type {
          name
          description
        }
      }
    }
  }
}

Run this in your API explorer.

This returns some interesting information. What did you want to do with it?

@mike_ekim1024, @GavinRay is building a mocking tool that helps him limit the number of API calls during development! He’s using the schema so to help make the mocking service dynamic.

1 Like