craftql icon indicating copy to clipboard operation
craftql copied to clipboard

Craft Color FIelds returns an error

Open masato-arai opened this issue 7 years ago • 3 comments

I'm trying to get a color fields' HEX code but I got an error below.

{
  "error": "String cannot represent non scalar value: instance of craft\\fields\\data\\ColorData"
}

My code is something like this and the 'bgColor' in slides block is the color fields. Color fields' type returns string but I can't get return the HEX code somehow.

{
  entries(section: [screensaver]) {
    ... on Screensaver {
      id
      title
      slides {
        ... on SlidesBlock {
          __typename
          bgColor
        }
      }
    }
  }
}

Cheers, Masato

masato-arai avatar Aug 14 '18 00:08 masato-arai

I'm running in to the same issue, I believe the Color field should't be a string but use the following structure: https://docs.craftcms.com/api/v3/craft-fields-data-colordata.html#public-properties

so when using the code above it would be like this:

{
  entries(section: [screensaver]) {
    ... on Screensaver {
      id
      title
      slides {
        ... on SlidesBlock {
          __typename
          bgColor {
            hex
          }
        }
      }
    }
  }
}

grumpyoldman-io avatar Aug 23 '18 13:08 grumpyoldman-io

I've opened a PR: https://github.com/markhuot/craftql/pull/141 that fixes the bug, but is has no support for color channels yet

grumpyoldman-io avatar Aug 23 '18 14:08 grumpyoldman-io

FYI, in the Schema explorer it still shows these fields as coming back string.

They should have a subselection of:

FIELD {
        hex
        rgb
        luma
        r
        g
        b
}

I spent a while trying to troubleshoot this error because the schema explorer shows it as type string.

simeon-smith avatar Apr 08 '20 16:04 simeon-smith