fikaproductions / fika-gatsby-source-cockpit

This is a Gatsby version 2.\*.\* source plugin that feeds the GraphQL tree with Cockpit Headless CMS collections and singletons data. Actually, it supports querying raw texts (and any trivial field types), Markdown, images, galleries, assets, sets, repeaters, layout(-grid)s (currently only without nested images/assets), objects, linked collections and internationalization.
GNU General Public License v3.0
23 stars 22 forks source link

feat(Singletons): Add singletons support (with configuration) #31

Closed WhippetsAintDogs closed 5 years ago

WhippetsAintDogs commented 5 years ago

What still need to be done:

DigitalGoldfish commented 5 years ago

Great progress - I am a tad busy with other at the moment but I should find some time towards the end of the week to have a look.

WhippetsAintDogs commented 5 years ago

@DigitalGoldfish I've looked more in details the name clashes that we were apprehending (collection and singleton with the same name or two collections/singletons with just a difference in capitalisation) and I think that we don't have to handle them since all of them are accessible even if names are clashing. For example, if I have a collection named Mountain (with a field named a), a singleton named Mountain (with a field named b) and a singleton named mountain (with a field named c), this query:

{
  allCockpitMountain {
    edges {
      node {
        id
        a {
          value
        }
        b {
          value
        }
        c {
          value
        }
      }
    }
  }
}

the response would be:

{
  "data": {
    "allCockpitMountain": {
      "edges": [
        {
          "node": {
            "id": AN-ID,
            "a": {
              "value": THE-VALUE
            },
            "b": null,
            "c": null,
          }
        },
        {
          "node": {
            "id": ANOTHER-ID-DIFFERENT-THAN-THE-FIRST-ONE,
            "a": null,
            "b": {
              "value": THE-VALUE
            },
            "c": null,
          }
        },
        {
          "node": {
            "id": ANOTHER-UNIQUE-ID,
            "a": null,
            "b": null,
            "c": {
              "value": THE-VALUE
            },
          }
        }
      ]
    }
  }
}

And every single one of these types (Mountain (collection), Mountain (singleton) and mountain) are accessible individually with the cockpitMountain(id/cockpitId: { eq: THE-ID-OF-THE-NODE-WE-WANT }) query. Keeping that in mind, do you still think that we should handle name clashes ?

DigitalGoldfish commented 5 years ago

Yes - because the above case is almost never what you want and will lead to unexpected behaviour; In case of property name clashes values might disappear due to type conflicts. Even if no properties clash it will severely hamper the autocomplete functionality in GrapiQL which we rely on extensively to create our queries.

But I think we can simplify it and don't need auto-renaming; it should be enough to

WhippetsAintDogs commented 5 years ago

You're right, I'll do it like you suggested ☺

mjoellnier commented 5 years ago

Any update on merging your pull request into the project? Using singletons would be an awesome feature!

WhippetsAintDogs commented 5 years ago

@mjoellnier Sorry for the delays, last months, my priorities kinda switched over another project and I forgot to put some time in the plugin. I'll try to implement to name clash mechanism during the next weekend and merge the singletons altogether ! ☺

mjoellnier commented 5 years ago

@WhippetsAintDogs Awesome! Thanks man :)

WhippetsAintDogs commented 5 years ago

@mjoellnier It's released :smile: ! (v.1.1.0)