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

Internal Values for Enum doesn't work with mergeSchema #1295

Closed
taddyhuo opened this issue Mar 9, 2020 · 2 comments
Closed

Internal Values for Enum doesn't work with mergeSchema #1295

taddyhuo opened this issue Mar 9, 2020 · 2 comments

Comments

@taddyhuo
Copy link

taddyhuo commented Mar 9, 2020

I was trying to follow https://www.apollographql.com/docs/graphql-tools/scalars/#internal-values

TypeDefs:

const typeDefs = `
  type Query {
    getTask(taskId: ID!): Task!
  }
  enum StatusEnum {
    ACTIVE
    INACTIVE
  }

  type TestTask {
    status: StatusEnum
  }
`

Resolvers:

const resolvers = {
  Query: {
    getTestTask: () => {
      return { status: 0 };
    },
  },

  StatusEnum: {
    ACTIVE: 0,
    INACTIVE: 1,
  }
}

query:

query GetTestTask($taskId: ID!) {
  getTestTask(taskId: $taskId) {
    status
  }
}

However, I got "Expected a value of type \"StatusEnum\" but received: \"ACTIVE\"". Any idea why?

graphql: 14.6.0
graphql-tools: 4.0.7
apollo-server-express: 2.11.0

FYI: I use mergeSchema from apollo-server-express to combine multiple schemas.

Here is full error log:

{
  "errors": [
    {
      "message": "Expected a value of type \"StatusEnum\" but received: \"ACTIVE\"",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "getTestTask",
        "status"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Expected a value of type \"StatusEnum\" but received: \"ACTIVE\"",
            "    at completeLeafValue (/code/xxx/node_modules/graphql/execution/execute.js:638:11)",
            "    at completeValue (/code/xxx/node_modules/graphql/execution/execute.js:579:12)",
            "    at completeValueCatchingError (/code/xxx/node_modules/graphql/execution/execute.js:495:19)",
            "    at resolveField (/code/xxx/node_modules/graphql/execution/execute.js:435:10)",
            "    at executeFields (/code/xxx/node_modules/graphql/execution/execute.js:275:18)",
            "    at collectAndExecuteSubfields (/code/xxx/node_modules/graphql/execution/execute.js:713:10)",
            "    at completeObjectValue (/code/xxx/node_modules/graphql/execution/execute.js:703:10)",
            "    at completeValue (/code/xxx/node_modules/graphql/execution/execute.js:591:12)",
            "    at completeValue (/code/xxx/node_modules/graphql/execution/execute.js:557:21)",
            "    at /code/xxx/node_modules/graphql/execution/execute.js:492:16"
          ]
        }
      }
    }
  ],
  "data": {
    "getTestTask": {
      "status": null
    }
  }
}
@taddyhuo taddyhuo changed the title Internal Values for Enum doesn't work Internal Values for Enum doesn't work with mergeSchema Mar 9, 2020
@yaacovCR
Copy link
Collaborator

yaacovCR commented Mar 9, 2020

This is a known issue with the upstream repository affecting transformSchema and mergeSchemas, fixed in graphql-tools-fork.

See #1056 and #1206

Apollo is not accepting bug fixes, unfortunately, but the fork should work as a drop in replacement.

@taddyhuo
Copy link
Author

taddyhuo commented Mar 9, 2020

Thank you! I will close this issue.

@taddyhuo taddyhuo closed this as completed Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants