Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums with custom values fail to stitch correctly #510

Closed
orta opened this issue Nov 28, 2017 · 5 comments
Closed

Enums with custom values fail to stitch correctly #510

orta opened this issue Nov 28, 2017 · 5 comments

Comments

@orta
Copy link
Contributor

orta commented Nov 28, 2017

Cross-issue with artsy/metaphysics#836

Likely related to #501 - the comment from @freiksenet seems to be exactly the conclusion we came to

An enum like this:

const HomePageHeroUnitType = new GraphQLObjectType({
  name: "HomePageHeroUnit",
  fields: {
    ...GravityIDFields,
    cached,
    mode: {
      type: new GraphQLEnumType({
        name: "HomePageHeroUnitMode",
        values: {
          LEFT_DARK: {
            value: "left white",
          },
          LEFT_LIGHT: {
            value: "left black",
          },
          CENTERED_DARK: {
            value: "center white",
          },
          CENTERED_LIGHT: {
            value: "center black",
          },
          RIGHT_DARK: {
            value: "right white",
          },
          RIGHT_LIGHT: {
            value: "right black",
          },
        },
      }),
      resolve: ({ type, menu_color_class }) => {
        return type.toLowerCase() + " " + menu_color_class.toLowerCase()
      },
    },

When accessed via a stitched schema gets these errors:

  "errors": [
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_DARK"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_LIGHT"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_DARK"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_DARK"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_LIGHT"
    }
  ],

Where it expects the lower case value, but is given the upper case enum string.

@freiksenet
Copy link
Contributor

Thanks!

@kvnvelasco
Copy link

+1 Happened to us too.

@renatobenks-zz
Copy link

This is really happening, I seems like a bug, I caught this as well, but, has a tricky to you pass for this error. Try set your field enum values with the same name of your enum names, like:

import { GraphQLEnumType } from 'graphql';

export default new GraphQLEnumType({
  name: 'IndicatorRegisterReportEnum',
  values: {
    FIRST: {
      value: 'FIRST',
    },
    SECOND: {
      value: 'SECOND',
    },
  },
});

For me this following approach is working good! It's a way to ignore this even to be fixed!

@trungtin
Copy link

I have this problem with graphql-compose also. From this discussion graphql/graphql-js#435 and digging it out I see that they use Object as the internal represented value of enums. Then mergeSchemas will replace the object with the string of name

@yaacovCR
Copy link
Collaborator

Folded into #1306, fixed by #1307

@yaacovCR yaacovCR mentioned this issue Mar 29, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants