Skip to content

Federation Enum not parsing value 0, works other values #1617

@ShadyKutz

Description

@ShadyKutz

Enums fail to resolve correctly with a value of 0, when using Federation.

Versions:

    "@apollo/federation": "^0.9.4",
    "apollo-server": "^2.9.3",
    "graphql": "^14.1.1",
    "graphql-tools": "^4.0.4"

Example Repo:

https://github.com/postman-nz/gql-federation-issue

Server Code:

const { ApolloServer, gql } = require("apollo-server");
const { buildFederatedSchema } = require("@apollo/federation");

const typeDefs = gql`
  type Query {
    colorBad: AllowedColor
    colorGood: AllowedColor
  }

  enum AllowedColor {
    RED
    GREEN
    BLUE
  }
`;

const resolvers = {
  Query: {
    colorBad: () => 0,
    colorGood: () => 1
  },
  AllowedColor: {
    RED: 0,
    GREEN: 1,
    BLUE: 2
  }
};

// Works with this server
/*
const server = new ApolloServer({
  typeDefs,
  resolvers
});
*/
const server = new ApolloServer({
  schema: buildFederatedSchema({
    typeDefs,
    resolvers
  })
});

server.listen().then(({ url }) => {
  console.log(`🚀  Server ready at ${url}`);
});

Success when running the Query

query {
  colorGood
}

We get the expected result.

{
  "data": {
    "colorGood": "GREEN"
  }
}

Failure when running the query

query {
  colorBad
}

An error is returned: "Expected a value of type \"AllowedColor\" but received: 0"

Expected Behavior:

{
  "data": {
    "colorBad": "RED"
  }
}

If Federation is removed, both of the queries run as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions