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

enum resolver error on graphql-tools@4.0.0 #962

Closed
sixmen opened this issue Sep 27, 2018 · 4 comments · May be fixed by project-accelerate/accelerate#285
Closed

enum resolver error on graphql-tools@4.0.0 #962

sixmen opened this issue Sep 27, 2018 · 4 comments · May be fixed by project-accelerate/accelerate#285
Labels
bug has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository

Comments

@sixmen
Copy link
Contributor

sixmen commented Sep 27, 2018

For the following simple code

import { makeExecutableSchema } from 'graphql-tools';
import { graphql } from 'graphql';

const schema = makeExecutableSchema({
  typeDefs: `
  type Query {
    test(status: Status): Status
  }
  enum Status {
   OK
   ERROR
  }
  `,
  resolvers: {
    Query: {
      test(source, args) {
        console.log(args);
        return 1
      },
    },
    Status: {
      OK: 1,
      ERROR: 2,
    } 
  },
});

graphql(schema, '{ test(status: OK) }')
  .then((result) => {
    console.log(result);
  });

graphql-tools@3.1.1 & graphql@0.13.2 gave following output:

{ status: 1 }
{ data: { test: 'OK' } }

But with graphql-tools@4.0.0 & graphql@14.0.2, I got an unexpected result

{ status: 'OK' }
{ errors: 
   [ { Error: Expected a value of type "Status" but received: 1 } ],
data: { test: null } }

If I returns 2 insteadof 1, I get { data: { test: 'ERROR' } }.
I think it is a bug of addResolveFunctionsToSchema.
enumValueMap[type.name] = { [fieldName]: resolverValue[fieldName] }; removes all fields except for the last one.

I don't know what should I do if I want to get { status: 1 }.

@ghost ghost added has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository bug labels Sep 27, 2018
tgriesser added a commit to tgriesser/graphql-tools that referenced this issue Oct 12, 2018
hwillson added a commit that referenced this issue Oct 12, 2018
Fix #962, Enum internal value mapping
@hwillson
Copy link
Contributor

This should now be fixed in graphql-tools 4.0.1.

@sixmen
Copy link
Contributor Author

sixmen commented Oct 14, 2018

I can get { data: { test: 'OK' } } with graphql-tools 4.0.1.

But it still prints { status: 'OK' }, but I want to get { status: 1 }.
What should I do?

@jkdowdle
Copy link

@hwillson

I am not sure if I see the fix yet. Or is there something I am doing wrong here? Or does Apollo Server need to update it's dependencies? Here is a minimal repo.

https://github.com/jkdowdle/graphql-tools-enum-issue

@jkdowdle
Copy link

jkdowdle commented Oct 18, 2018

Ok, I can get it to work by upgrading to graphql-tools@4.0.2 and forcing apollo-server to use that version.

I suppose we will just need apollo-server to update it's dependency versions, which looks like it was here apollographql/apollo-server@2abff34.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants