webiny-js icon indicating copy to clipboard operation
webiny-js copied to clipboard

Headless CMS/Programmatic Usage Error: `There is no default plugin to create CmsModelManager`

Open adrians5j opened this issue 3 years ago • 2 comments

At the moment, an error is being thrown if one would try to create a new content model programmatically, within the GraphQL handler (Lambda function).

For example - if we were to run this code (a simple GraphQL resolver where we use CMS API), the following error would occur:

image

After some investigation, here are my thoughts.

First of all, I noticed we have these plugins imported on the GraphQL handler side: https://github.com/webiny/webiny-js/blob/cms-models-creation-gql/api/code/graphql/src/index.ts#L87-L93

Which is different from what is imported here: https://github.com/webiny/webiny-js/blob/cms-models-creation-gql/api/code/headlessCMS/src/index.ts#L40-L46

To some extent, I think I understand why the difference in plugins. These are simply different types of functionality that are needed and applied within these two handlers.

Moving on, if we were to dive deeper into the code, we can see different plugins that are applied behind the scenes. And, in case of the createAdminHeadlessCmsContext, we can see that there is no modelManager() called, like it's the case in the createContentHeadlessCmsContext (here).

This, and also the fact that we have an updateManager call in the createModel function, could explain why the above shown error is occurring.

For now, if possible, I'd just like to hear some thoughts from @brunozoric @Pavel910 on the subject. Do you maybe have some ideas on how to best approach this? Are we "just" missing the modelManager call or there's more things involved / some additional testing would be needed?

I can continue working on this, but yeah, before doing any further work, I decided to ask you guys to quickly chime in with at least some high-level ideas.

Thanks!

adrians5j avatar Apr 26 '22 08:04 adrians5j

The graphql and headlessCMS lambda used to be quite different as the graphql was used to install the headless cms and headlessCMS was used to actually do something with the cms groups, models and entries. We could possibly have a single createHadlessCmsContext() for both lambdas. The createGraphQL should be separated as it is now.

brunozoric avatar Apr 26 '22 08:04 brunozoric

Just checking in @brunozoric - as you can imagine, this has us stalled in trying to migrate to using the headlessCMS on our app.

Where does the real fix fit into the dev schedule? If it's not coming soon, since the way that we were trying to do this isn't working - is there another work around that we can use in the meantime that will fit in nicely when it is fixed?

timruppert avatar May 02 '22 08:05 timruppert