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

Question: createDocumentUpdateResolver uses repository Insert instead of Update? #246

Open
jsimnz opened this issue Jun 28, 2019 · 3 comments

Comments

@jsimnz
Copy link

jsimnz commented Jun 28, 2019

disclosure: I don't have a running instance of PrimeCMS, but I've been extensively pouring through the code for the last few days.

When looking at your generated resolvers for the Document mutations, I came across the createDocumentUpdateResolver, which as I understand it creates the update$SCHEMA mutation for the GraphQL API. This mutation should simply update a field in a document (as I understand it)

Notably, this is separate from the create$SCHEMA endpoint which uses the createDocumentCreateResolver, which creates a new document for a given schema.

My question: In both resolvers you use the repositort.insert on your Document TypeORM repository instance. According to TypeORM, the insert( ... ) call always creates a new row/record without checking if the entity already exists.

So does PrimeCMS constantly keep inserting full duplicates of a Document whenever you update something? Is this to support versioning? I have a suspicion it is since in the DocumentResolver you use FindOne and order it by DESC on the created_at field but wanted to check with you.

Thanks for reading. Really great project and codebase! I'm getting lots of inspiration from it.

@birkir
Copy link
Owner

birkir commented Jun 28, 2019

Yes, this is for versioning.
All documents have the two fields, id and documentId.

id is the auto generated uuid of each row in the table.
documentId is something I create dynamically when creating documents.
https://github.com/birkir/prime/blob/master/packages/prime-core/src/modules/external/resolvers/createDocumentCreateResolver.ts#L25

When querying for all documents, I add a GROUP BY + HAVING with a subquery to select the latest published uuid in the database.

This is one of the most performant way of having revision AND releases without creating multiple tables.

@agustif
Copy link

agustif commented Jun 30, 2019

https://github.com/birkir/prime/blob/master/packages/prime-core/src/modules/external/resolvers/createDocumentCreateResolver.ts#L25

This is so cool

Btw, the // todo: add User line is in order to be able to assign each revision to a user so you can do something lie git blame?

@birkir
Copy link
Owner

birkir commented Jul 1, 2019

Yes, that's is the idea.

It's still in @todo for external, because I haven't figured out what to do with unauthenticated users. But for internal we have this of course.

https://github.com/birkir/prime/blob/master/packages/prime-core/src/modules/internal/resolvers/DocumentResolver.ts#L184

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

3 participants