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

problem with oneOf when set on the root schema #2

Open
kapouer opened this issue Oct 28, 2016 · 1 comment
Open

problem with oneOf when set on the root schema #2

kapouer opened this issue Oct 28, 2016 · 1 comment

Comments

@kapouer
Copy link

kapouer commented Oct 28, 2016

Something like http://stackoverflow.com/a/25033301/4312202
gives TestPropertiesEnum values must be an object with value names as keys.

(This is a reference for future PR - i know you're busy).

@kapouer
Copy link
Author

kapouer commented Oct 30, 2016

graphql equivalent of oneOf is more explicit about how to choose the right schema, but i think oneOf is implementable using something like

const isValidJSValue = require('graphql/src/utilities').isValidJSValue;
var PetType = new GraphQLUnionType({
  name: 'Pet',
  types: [ DogType, CatType ],
  resolveType(value) {
    return [ DogType, CatType ].find(function(type) {
      return isValidJSValue(type, value);
    });
  }
});

There might be an issue with the type when it is GraphQLObjectType, since isValidJSValue expects Input types.

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

1 participant