Vincit / objection-graphql

GraphQL schema generator for objection.js
MIT License
307 stars 35 forks source link

problem with oneOf when set on the root schema #2

Open kapouer opened 8 years ago

kapouer commented 8 years ago

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 commented 8 years ago

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.