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

processing entity undefined #474

Closed
lookfirst opened this issue Apr 12, 2020 · 4 comments
Closed

processing entity undefined #474

lookfirst opened this issue Apr 12, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@lookfirst
Copy link
Contributor

Describe the bug

Noticed this in the logs...

>  [discovery] - processing entity undefined
>  [discovery] - using cached metadata for entity undefined

Looking in the cache directory, I see undefined.json

{"data":{"properties":{},"hooks":{},"indexes":[],"uniques":[],"class":{"NEW":"NEW","RUNNING":"RUNNING","REPAIR":"REPAIR","REMOVED":"REMOVED","MOVED":"MOVED"},"constructorParams":[],"toJsonParams":[],"useCache":true,"path":"./build/src/db/entities/RigStatus.js"},"origin":"./build/src/db/entities/RigStatus.js","hash":"b840d15999f116addec6f1f0a4530197"}

Which contains...

import { registerEnumType } from "type-graphql";

export enum RigStatus {
	NEW = 'NEW',
	RUNNING = 'RUNNING',
	REPAIR = 'REPAIR',
	REMOVED = 'REMOVED',
	MOVED = 'MOVED',
}

registerEnumType(RigStatus, {
	name: "RigStatus", // this one is mandatory
});

Now, one could say that I shouldn't do that. =) Or another could say... throw an error if we're going to make something undefined...

Note that RigStatus is used as an enum field in the entities.

Versions

Dependency Version
mikro-orm 3.6.5
@lookfirst lookfirst added the bug Something isn't working label Apr 12, 2020
@lookfirst
Copy link
Contributor Author

Kind of another issue, but the documentation also states:

"For schema generator to work properly in case of string enums, you need to define the enum is same file as where it is used, so its values can be automatically discovered. If you want to define the enum in another file, you should reexport it also in place where you use it."

  1. Note that putting the enum into its own file, does seem to work... I just get the extra json file.
  2. Can you also add an example of reexporting it? I'm confused by that.

@B4nan
Copy link
Member

B4nan commented Apr 12, 2020

It depends on how you register the enum. If you do @Enum(() => RigStatus), then you do not have to care about anything.

That note is about using ts-morph discovery with just @Enum(), where the RigStatus will be read as a string and then it will try to require it from the file where entity was defined.

Reexporting simply means that in the context of the file there will be the enum available, so just this in your entity source file:

export { RigStatus } from './enum.ts';

Regarding the issue itself, I guess I will just ignore plain objects in the discovery, valid entity needs to export either class or instance of EntitySchema.

@lookfirst
Copy link
Contributor Author

Cool, I'm doing the first bit. Might be good to expand the docs a bit to explain that so it is a little more clear.

Agreed on the main issue fix. =) Should be able to mix files in my entities directory since this enum is primarily used from there.

@B4nan B4nan closed this as completed in 0226137 Apr 12, 2020
@lookfirst
Copy link
Contributor Author

Thanks @B4nan . =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants