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

Add a Docker Playground #17

Open
perfectbase opened this issue Jul 15, 2022 · 4 comments
Open

Add a Docker Playground #17

perfectbase opened this issue Jul 15, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@perfectbase
Copy link

perfectbase commented Jul 15, 2022

Would it be possible to add a Dockerized version of the playground?
One that people could run without the need to import the appRouter to setup the playground?

I believe that to make it possible, we would need a way to get the router configuration from the trpc endpoint.

Does that functionality already exist?
If not, would it be possible to sync with the trpc team and make it?

I love this project, and I think its super important for the trpc community.
I would love to help contributing.

@sachinraja
Copy link
Owner

I am a tRPC core maintainer so I could try to make that happen if it were possible. Unfortunately, routers are not portable. Resolvers can import from anywhere and run anything. What you can do is use the playground with an express server and bundle your code.

@sachinraja sachinraja added the enhancement New feature or request label Jul 15, 2022
@perfectbase
Copy link
Author

@sachinraja Yeah.. I think you are right...
If we had a way to print the router configuration on a specific endpoint, we maybe could be able to use that for setting up the playground, but we can't print the AppRouter interface, since interfaces don't exist in runtime.

I tried to print out the actual appRouter object to see if we could use it as a schema for the playground, but it doesn't seem like an easy task.

// console.log(JSON.stringify(appRouter, null,2))
{
  "_def": {
    "queries": {
      "test.hello": {
        "middlewares": [],
        "inputParser": {
          "_def": {
            "innerType": {
              "_def": {
                "innerType": {
                  "_def": {
                    "unknownKeys": "strip",
                    "catchall": {
                      "_def": {
                        "typeName": "ZodNever"
                      }
                    },
                    "typeName": "ZodObject"
                  },
                  "_cached": null
                },
                "typeName": "ZodOptional"
              }
            },
            "typeName": "ZodNullable"
          }
        }
      }
    },
    "mutations": {},
    "subscriptions": {},
    "middlewares": [],
    "transformer": {
      "input": {},
      "output": {}
    }
  }
}

I really think it would be a great feature to be able to run the Playground on docker by only setting the API endpoint as an environment variable.
But, sadly, it doesn't feel like a trivial solution..

@perfectbase
Copy link
Author

I'm starting to understand more the codebase.
And I realized that you already have an API that is returning the "schema" of the trpc.

// POST: http://localhost:3000/api/trpc-playground
["declare function query<QueryName extends 'hello' | 'hello_num' | 'subtract_nums' | 'add_nums' | 'no-args' | 'date'>(name: QueryName,...args: QueryName extends 'hello' ? [({\n    text: (string | undefined) | null;\n} | undefined) | null] : QueryName extends 'hello_num' ? [({\n    text: number;\n} | undefined) | null] : QueryName extends 'subtract_nums' ? [{\n    a: number;\n    b: number;\n}] : QueryName extends 'add_nums' ? [{\n    a: number;\n    b: number;\n}] : QueryName extends 'no-args' ? [undefined?] : QueryName extends 'date' ? [Date] : never): void","declare function mutation<QueryName extends 'delete_last_user'>(name: QueryName,...args: QueryName extends 'delete_last_user' ? [undefined?] : never): void"]

Couldn't we put this inside the main trpc repo?
For example: POST: /api/trpc/_schema

I believe that if we could do that, people would be able to run the dockerized playground without having to make any changes to the code.

What do you think?

@sachinraja
Copy link
Owner

sachinraja commented Jul 17, 2022

I don't think we'll be doing anything like that in core. But we can potentially offer an option to pass that "schema" instead of your router in this project.

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

No branches or pull requests

2 participants