`plugin.fields` does not return all project fields

In recent attempts to build a plugin that assembles a list of all linked records, I’ve found that the property plugin.fields fails (at least, intermittently) to return all the fields of the current project as documented, and rather returns only the fields of the current model. I believe this is the reason why Dato’s own “Inverse Relationships” plugin is currently not working

hi @lunelson I anonymized your other account, so that the posts are still visible. Watch this topic, so that you will receive updates :slight_smile:

Thanks for the tip @faber !!

Hi @lunelson thank you for reporting this issue!

You are right, at the moment the documentation is misleading because it says that plugin.fields returns all project fields, while it actually returns only cached project fields. That is why if you have only loaded a single record page, it will only return that record’s model fields.

About the Inverse Relationships plugin, I confirm that it is not working. We will soon release a fix, we will let you know :smiley:

Thanks @Souljuse, I’m glad for the confirmation. The cached project fields fact explains why the inverse relationships plugin intermittently works: it’s actually trying to look up information about the link field in the other model (the one that links to the current one), and depending on page load state I guess this information is sometimes present and sometimes not.

However, I must say I’m disappointed that there isn’t a way to get all the project’s fields: I hope you’ll reconsider this aspect of the plugin API and having it actually return all the project fields, because use-cases like this one can only be solved with that information. Even the content management API doesn’t seem to provide a way to get all the project’s fields (you apparently have to specify a model), and in any case doesn’t return all the relational data that the plugin API does

@lunelson I completely understand, but we have many projects with +1000 models and +10000 fields: having to return all fields leads to visible performance problems and delays, which can often be avoided with greater specificity. Having that said, we’re going add a method in the plugin SDK to fetch a model fields without having to resort to custom API tokens, AND, if you really want to download EVERY field, you actually can (we simply advise not to):

curl --request GET \
  --url 'https://site-api.datocms.com/site?include=item_types%2Citem_types.fields' \
  --header 'Accept: application/vnd.api+json' \
  --header 'Authorization: Bearer XXX'

I certainly agree that “greater specificity” is preferable! I just don’t see a way to do the kind of filtering that I want: what I want ultimately, is a list of all the records which link (via a Link or Links field) to the current one, listed by record name, but sorted and grouped by model name. I couldn’t see any way around querying the entire list of fields (at least, fields of those types) in the project

Agreed! We have also an undocumented endpoint that does just that, we should move it to public someday and/or add a section in the record sidebar that shows this info :slight_smile:

curl --request GET \
  --url 'https://site-api.datocms.com/items/:ID/references' \
  --header 'Accept: application/vnd.api+json' \
  --header 'Authorization: Bearer XXX'
1 Like

Oh wow, perfect! Yes a feature in the record sidebar would be great. In the meantime I’m going to develop a plugin that does exactly this :point_up:!

This is my implementation in Svelte https://github.com/lunelson/datocms-plugin-record-references

1 Like

Hi! The Inverse Relationships plugin should be fixed, now! Try updating to the last version, @lunelson let us know if everything is working as expected :slight_smile:

Thanks for the update! I’ll check it out as soon as I can :wink: