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

Having multiple locations for basePath #61

Closed
seanlowe opened this issue Apr 7, 2023 · 5 comments
Closed

Having multiple locations for basePath #61

seanlowe opened this issue Apr 7, 2023 · 5 comments

Comments

@seanlowe
Copy link
Contributor

seanlowe commented Apr 7, 2023

Hey, building a fullstack application that uses schemix and I wanted to see if there was a way to allow multiple directory locations for src files. I want to make my app extensible and provide clear locations for those extensions to live so anyone who may decide to contribute doesn't have to deal with adding code in my base models.

Maybe something like :

createSchema({
  basePath: [__dirname, 'somepath/to/models`],
  // other options
})

or possibly:

createSchema({
  basePath: __dirname,
  additionalPaths: ['somepath/to/models', 'secondpath/to/models']
  // other options
})

Let me know if you need/want any additional information or if this is just plain too hard to do. Thanks!

@seanlowe
Copy link
Contributor Author

seanlowe commented Apr 7, 2023

I looked through the source code a little bit. I think it should be fairly simple to add this. I'm looking at PrismaSchema.ts > toString.

Existing code:

if (this.basePath) {
  await importAllFiles(this.basePath, "enums");
  await importAllFiles(this.basePath, "models");
  await importAllFiles(this.basePath, "mixins");
}

Possible update:

constructor(
  // constructor stuff
  private readonly additionalPaths?: string[]
) {}

// other functions and stuff

public toString(): Promise<string> {
  return new Promise(async (resolve) => {
    const allPaths = [this.basePath, ...this.additionalPaths];

    allPaths.forEach((path) => {
      await importAllFiles(path, "enums");
      await importAllFiles(path, "models");
      await importAllFiles(path, "mixins");
    }

    // rest of function

I can put up a PR for this if you want.

@ridafkih
Copy link
Owner

I think the additionalPaths route is the way to go, should be easy enough to implement. @seanlowe have you given it a go yet?

@seanlowe
Copy link
Contributor Author

I haven’t actually tried. I’ll try to get one up today.

seanlowe added a commit to seanlowe/schemix that referenced this issue Apr 10, 2023
* adds support for using a new flag `additionalPaths` in `createSchema`
* adds new example for splitting the schema code across directories
* adds new test / snapshot
@seanlowe
Copy link
Contributor Author

@ridafkih I have created a PR for this issue when you have a chance to look at it. Let me know what you think.

seanlowe added a commit to seanlowe/schemix that referenced this issue Apr 21, 2023
* updated schema to use additionalPath as it's own path, not as a path relative to basePath
* updated the example readme / index
* noticed the second additionalPath in the example is missing somehow so I removed that
* updated the test
ridafkih pushed a commit that referenced this issue Apr 27, 2023
* adds support for using a new flag `additionalPaths` in `createSchema`
* adds new example for splitting the schema code across directories
* adds new test / snapshot
ridafkih pushed a commit that referenced this issue Apr 27, 2023
* updated schema to use additionalPath as it's own path, not as a path relative to basePath
* updated the example readme / index
* noticed the second additionalPath in the example is missing somehow so I removed that
* updated the test
@ridafkih
Copy link
Owner

Closing, #66 has been released in v1.12.0.

Thanks for the suggestion and implementation!

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

No branches or pull requests

2 participants