Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrated API Playground to using the V2 API Definition typings #1564

Merged
merged 26 commits into from
Oct 2, 2024

Conversation

abvthecity
Copy link
Contributor

@abvthecity abvthecity commented Sep 30, 2024

This PR is a follow-up to #1552

Instead of calling /api/fern-docs/resolve-api, which resolves all endpoints, websockets, and webhooks across all the api definitions, this PR introduces 3 new getter functions:

  • GET /api/fern-docs/api-definition/{api}/endpoint/{endpointid} (link)
  • GET /api/fern-docs/api-definition/{api}/websocket/{websocketid} (link)
  • GET /api/fern-docs/api-definition/{api}/webhook/{webhookid} (link)

Each of these endpoints:

  1. loads the api definition from the the api.v1.read endpoint instead of docs.v2.read, which reduces the payload size transferred from FDR to NextJS.
  2. prune the api definition to the specific endpoint that is being requested
  3. resolve and cache all api definition descriptions using the new Transformer utility.

In the API Playground,

  • all references to ResolvedApiDefinition types have been removed in favor of the fdr-sdk types.
  • endpoint definition + endpoint node + types are wrapped in a EndpointContext, which makes it easier to pass the context down to its children without specifying each of the parameters separately. This is useful because an endpoint node and endpoint definition is always paired together.
  • useSWRImmutable is used to leverage SWR's cache
  • the PlaygroundEndpointSelector is configured so that hovering over endpoints will trigger a prefetch, improving perceived speed.

Caching

  • ApiDefinitionLoader: link does the bulk of the load -> prune -> cache work in the load() method, and the resolveDescriptions() method.

  • ApiDefinitionCache: link shows how we leverage mset and mget to batch setting api definitions to parallelize and reduce server round-trips.


  • tested on flagright (ensure that application/json on multipart form is retained)

@abvthecity abvthecity had a problem deploying to Preview - app-dev.buildwithfern.com October 1, 2024 17:25 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app.buildwithfern.com October 1, 2024 17:25 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app.buildwithfern.com October 1, 2024 17:47 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app-dev.buildwithfern.com October 1, 2024 17:47 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app.buildwithfern.com October 1, 2024 18:26 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app-dev.buildwithfern.com October 1, 2024 18:26 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app.buildwithfern.com October 1, 2024 18:42 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app-dev.buildwithfern.com October 1, 2024 18:42 — with GitHub Actions Failure
@abvthecity abvthecity marked this pull request as ready for review October 1, 2024 18:42
@abvthecity abvthecity requested a review from dsinghvi as a code owner October 1, 2024 18:42
@abvthecity abvthecity changed the title stash: cached api playground impl chore: migrated API Playground to using the V2 API Definition typings Oct 1, 2024
@abvthecity abvthecity had a problem deploying to Preview - app.buildwithfern.com October 1, 2024 18:55 — with GitHub Actions Failure
@abvthecity abvthecity had a problem deploying to Preview - app-dev.buildwithfern.com October 1, 2024 18:55 — with GitHub Actions Failure
Copy link
Member

@dsinghvi dsinghvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blind +1

@abvthecity abvthecity merged commit bfc2271 into main Oct 2, 2024
22 checks passed
@abvthecity abvthecity deleted the ajiang/cached-api-playground branch October 2, 2024 22:36
export const PlaygroundContextProvider: FC = () => {
const key = useApiRoute("/api/fern-docs/resolve-api");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abvthecity, can we bring this back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants