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

Support for Next.JS projects in generated clients #289

Closed
wants to merge 3 commits into from

Commits on Jun 24, 2022

  1. Support for Next.JS projects in generated clients

    This commit adds support for generated Typescript clients to be
    compitable with [Next.JS](https://nextjs.org/) applications with the new `--nextjs` argument.
    
    The existing client was not compiatble as we where using namespaces
    to mimic the packages within the Encore application, however namespaces
    are somewhat depcreated and not all transpliers support them; the key one
    here being Babel (which Next.JS uses under the hood).
    
    When turned on the new `--nextjs` flag, therefore prevents the code generator
    from emitting namespaces, and instead it uses the package name as a prefix for
    generated types; such as `$package_$struct`.
    
    To make NextJS development easier, this flag also tells the TypeScript code generator
    to generate [SWR](https://swr.vercel.app/) wrappers for all API's, while maintaining the
    promise based functions if direct calls are still required (i.e. to perform actions).
    
    If the original api call was:
    ```
    const api = new Client()
    
    const rsp: Promise<Data> = api.MySvc.MyAPI("segment", { name: "bob" })
    ```
    
    The SWR wrapper will be:
    ```
    const api = new Client() // this needs to be a singleton for the application instance
    
    const rsp: SWRResponse<Data> = api.MySvc.useMyAPI("segment", { name: "bob" }, { refreshInternval: 1000 })
    ```
    DomBlack committed Jun 24, 2022
    Configuration menu
    Copy the full SHA
    82361e2 View commit details
    Browse the repository at this point in the history

Commits on Jun 27, 2022

  1. Configuration menu
    Copy the full SHA
    b4af18a View commit details
    Browse the repository at this point in the history

Commits on Jun 28, 2022

  1. Configuration menu
    Copy the full SHA
    15192c6 View commit details
    Browse the repository at this point in the history