graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

How to skip adding enums to the generated schema?

Open juiceo opened this issue 5 years ago • 1 comments

I've defined some fields in my mongoose Schemas like the following:

{
  country:  {
    type: 'String',
    enum: ['United States', 'Great Britain', ...]
  }
}

which apparently doesn't conform to the GraphQL enum validation criteria, since I'm seeing the following error when trying to composeWithMongoose a schema with the above enum:

Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "United States" does not.

I would like to keep my database-level validation as-is, so is there a way I can generate a GraphQL schema which would just ignore any enum validation?

juiceo avatar Jan 20 '20 18:01 juiceo

There is no such ability right now.

But if you have time you may do a Pull Request.

Need to pass 4rd arg opts.field to convertModelToGraphQL method: https://github.com/graphql-compose/graphql-compose-mongoose/blob/f819521650e8ed7c528acf1190500907ed04eec9/src/composeWithMongoose.js#L139-L147

And move prepareFields logic which skips or keeps fields to convertModelToGraphQL method (before field will be converted to graphql type): https://github.com/graphql-compose/graphql-compose-mongoose/blob/f819521650e8ed7c528acf1190500907ed04eec9/src/fieldsConverter.js#L144-L150

nodkz avatar Feb 04 '20 13:02 nodkz