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

allCockpit* returns each node twice #27

Closed danielmilner closed 5 years ago

danielmilner commented 5 years ago

When I run any allCockpit query, each node is returned twice.

Example query:

{
  allCockpitProjects {
    edges {
      node {
        cockpitId
      }
    }
  }
}

Returns the following:

{
  "data": {
    "allCockpitProjects": {
      "edges": [
        {
          "node": {
            "cockpitId": "5c548b9b3162395098000393"
          }
        },
        {
          "node": {
            "cockpitId": "5c548a9f3162394dfe000341"
          }
        },
        {
          "node": {
            "cockpitId": "5c548a173162394c22000221"
          }
        },
        {
          "node": {
            "cockpitId": "5c548adb3162394eb7000387"
          }
        },
        {
          "node": {
            "cockpitId": "5c548b9b3162395098000393"
          }
        },
        {
          "node": {
            "cockpitId": "5c548a9f3162394dfe000341"
          }
        },
        {
          "node": {
            "cockpitId": "5c548a173162394c22000221"
          }
        },
        {
          "node": {
            "cockpitId": "5c548adb3162394eb7000387"
          }
        }
      ]
    }
  }
}

I have 4 entries in the Collection, the first 4 cockpitIds are unique, but the last 4 are repeats.

WhippetsAintDogs commented 5 years ago

Hi @danielmilner,

if you have at least one locale defined in the plugin configuration, you'll get a node for the default language and one for each locale defined (with each localized field translated in the corresponding language). Print or filter by the lang attribute and you should have only unique nodes ☺.

WhippetsAintDogs commented 5 years ago

For the default language, use the lang value any or any locale defined in the plugin configuration.

danielmilner commented 5 years ago

@WhippetsAintDogs That was it! If I set the local to an empty array in the config, I get one of each node. Thanks!

WhippetsAintDogs commented 5 years ago

You're welcome! ☺

sudhanshug16 commented 4 years ago

Hey guys, Can you give an example for the query to run?

I added lang parameter to my query as such:

allCockpitWorks(lang: { eq: "en" }) {
  edges {
    node {
      Title {
        value
      }
      Image {
        value {
          childImageSharp {
            fluid {
              ...GatsbyImageSharpFluid
            }
          }
        }
      }
      Description {
        value
      }
      Featured {
        value
      }
    }
  }
}

This is giving me the following error: Unknown argument "lang" on field "allCockpitWorks" of type "Query"

My config looks like this:

{
  resolve: "@fika/gatsby-source-cockpit",
  options: {
    token: "0160ee9ee9f43905a38abe64040c28",
    baseUrl: "http://localhost:8888",
    collections: []
  },
},

I even tried adding locales: ["en"] to the config but no luck so far.

By the way, I have not defined any language in Cockpit (I dont even know how to do that :P)

sudhanshug16 commented 4 years ago

About the previous comment, I made the query work with the following snippet: allCockpitWorks(filter: { lang: { eq: "en" } }) {...} This is what was intended, right? Or is there something else to it too?

WhippetsAintDogs commented 4 years ago

Hi @sudhanshu16, you got it.

When you make an 'all' query, the way to filter by the lang is filter - lang - eq - LOCALE and when you do a regular query, you'll specify cockpitId - eq - ID, lang - eq - LOCALE. The LOCALE can be any value you put in the locales option or any.

I even tried adding locales: ["en"] to the config but no luck so far. By the way, I have not defined any language in Cockpit (I dont even know how to do that :P)

The locales option have to be identical to your Cockpit configuration, so if you have locales: ["en"], you should have that Cockpit configuration (config.php):

<?php

$configs = [];

$configs['languages'] = [
    'default' => 'English',
];

return $configs;