-
Notifications
You must be signed in to change notification settings - Fork 333
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 support for enums and doc comments #551
Conversation
// "arrow-body-style": "error", | ||
complexity: 'error', | ||
complexity: ['error', 21], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous limit was 20, if you remove it and run the tests I think you'll understand why I simply increased it by 1
Thanks for contributing, we will play with it locally and come back to you. |
Hi @raycar5 thank you for the contribution. I'm start work on testing this feature, can you provide a simple subquery example with generated enum, demonstrate how to use the enum in the mapping function etc? Thank you |
Schema: enum TestEnum {
Foo
Bar
}
"""
Description
"""
type TestEntity @entity {
"""
Field description
"""
id: ID!
"""
Field description
"""
field: TestEnum!
} Mapping function: export async function handleEvent(event: SubstrateEvent): Promise<void> {
const blockId = block.block.header.number.toNumber();
const eventIdx = event.idx;
await TestEntity.create({
id: `${blockId}/${eventIdx}`,
field: blockId % 2 === 0 ? TestEnum.Foo : TestEnum.Bar,
}).save();
} Query: query {
testEntities(filter: { field: { equalTo: Foo } }) {
nodes {
id
field
}
}
} |
@raycar5 Hi I got this error when it try to create the enum for a new project.
I think what happen here is each time you are trying to remove the enum have the same name, however other projects in the same database maybe also rely on it.
|
@raycar5 We really appreciate your contribution, and we will adopt it. And we have some concerns here for the risks of the data, but we will continue to improve on the current implementation.
In another pr #532 we have tidy up the types in our packages, soon after merge yours, we will integrate it to our changes. |
Looking at the postgres docs indeed it seems enum order matters so the matching should be order sensitive. However I do not understand what you mean by "should use number for value instead of string , so this can be matching the implementation on the database layer", the database layer uses strings to interact with enum fields. If I understand your comment correctly, you're saying that you'll pick up where I left off right? So I shouldn't push the fix for the enum order checking. |
Yes, jiqiang90 will finish the rest along with the matching fix. The consideration of using number is for shortening the hashcode for enum fields. Depends on if pg accept number for enum field, we will change the enum to number or just do that in the |
* Add support for enums and doc comments * address PR comments
This PR adds support for enums as well as using doc comments on both entities and fields.
A few catches:
In it's current state it's good enough for our use-case.