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

Explore ways to prevent relationships from creating dependency cycles #294

Open
joelalejandro opened this issue Jun 24, 2021 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@joelalejandro
Copy link
Member

joelalejandro commented Jun 24, 2021

Using direct resource imports to set the type in a relationship can produce a dependency cycle.

// book.ts
import Author from './author';

class Book extends Resource {
  static schema = {
    attributes: {
      title: String;
    },
    relationships: {
      authors: {
        hasMany: true,
        type: () => Author
      }
    }
  }
}
// author.ts
import Book from './book';

class Author extends Resource {
  static schema = {
    attributes: {
      firstName: String;
      lastName: String;
    },
    relationships: {
      books: {
        hasMany: true,
        type: () => Book
      }
    }
  }
}

We might want to replace type: () => Resource with a string resolver to prevent this and use resourceFor() to resolve the type internally.

We can accept both syntaxes to prevent this from becoming a breaking change.

@joelalejandro joelalejandro added the enhancement New feature or request label Jun 24, 2021
@joelalejandro joelalejandro changed the title Explore ways to prevent relationships from forcing dependency cycles Explore ways to prevent relationships from creating dependency cycles Jun 24, 2021
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

1 participant