markhuot / craftql

A drop-in GraphQL server for Craft CMS
Other
319 stars 53 forks source link

Craft Color FIelds returns an error #131

Open masato-arai opened 6 years ago

masato-arai commented 6 years ago

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

grumpyoldman-io commented 6 years ago

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 commented 6 years ago

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

simeon-smith commented 4 years ago

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.