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

fix(medusa): Plugin repository loader #3345

Merged
merged 3 commits into from
Mar 1, 2023
Merged

Conversation

adrien2p
Copy link
Member

FIXES CORE-1177

@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2023

🦋 Changeset detected

Latest commit: 87de3c0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@medusajs/medusa Patch
@medusajs/inventory Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@olivermrbl
Copy link
Contributor

@adrien2p Is this ready for review?

@adrien2p
Copy link
Member Author

@olivermrbl I did not test it yet, i ll do that tomorrow morning

@adrien2p
Copy link
Member Author

adrien2p commented Mar 1, 2023

@olivermrbl I ve just tested it and it worked

// src/repositories/user-test.ts

import { dataSource } from "@medusajs/medusa/dist/loaders/database";
import { User } from "@medusajs/medusa";

const UserRepository = dataSource.getRepository(User).extend({
  test() {
    return { test: "test" }
  }
})

export default UserRepository

and in the API directory

  route.get('/test', async (req, res) => {
    const userTestRepo = req.scope.resolve("userTestRepository")
    const test = userTestRepo.test()
    res.json(test)
  })

I have also tested to override an existing repo

// src/repositories/user.ts

import UserRepository from "@medusajs/medusa/dist/repositories/user";

const UserRepo = UserRepository.extend({
  test() {
    return { test: "test" }
  }
})

export default UserRepo

and in the API

  route.get('/test', async (req, res) => {
    const userTestRepo = req.scope.resolve("userTestRepository")
    const test = userTestRepo.test()

    const userRepo = req.scope.resolve("userRepository")
    const test2 = userRepo.test()

    res.json([test, test2])
  })

Screenshot 2023-03-01 at 10 34 01

@adrien2p adrien2p marked this pull request as ready for review March 1, 2023 10:06
@adrien2p adrien2p requested a review from a team as a code owner March 1, 2023 10:06
@olivermrbl olivermrbl added version: minor status: needs docs Needs internal documentation (as a minimum) labels Mar 1, 2023
Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

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

LGTM, we could add an integration test :)

@olivermrbl olivermrbl merged commit e143a86 into develop Mar 1, 2023
@olivermrbl olivermrbl deleted the fix/plugin-repo-loader branch March 1, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs docs Needs internal documentation (as a minimum) version: minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants