Graphql-tools: Enums with custom values fail to stitch correctly

Created on 28 Nov 2017  路  5Comments  路  Source: ardatan/graphql-tools

Cross-issue with https://github.com/artsy/metaphysics/issues/836

Likely related to https://github.com/apollographql/graphql-tools/issues/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.

bug schema stitching

Most helpful comment

+1 Happened to us too.

All 5 comments

Thanks!

+1 Happened to us too.

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!

I have this problem with graphql-compose also. From this discussion https://github.com/graphql/graphql-js/issues/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

Folded into #1306, fixed by #1307

Was this page helpful?
0 / 5 - 0 ratings