sarkistlt / mongoose-schema-to-graphql

Use Mongoose schema to generate graphQL type.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add RegExp support for "exclude" option

kettanaito opened this issue · comments

What

I would like to suggest to add a support for regular expressions in exclude option.

Why

There is a particular use case I can give you: with the recent update of graphql, it will no longer accept fields which start with __, as it is used internally for the library. For that matter, when converting schemas to types you would need to exclude each schema field starting with __ manually.

I find this tedious and non future-proof. No one can predict the changes in both libraries in the future, so the exclusion on our side should be as simple and minimal as possible.

Managing this exclusion with the RegExp would be a good option to go:

const schema = { ... };

const type = createType({
  schema,
  exclude: /^__[^_]\S+/
});

So all fields starting with two underscores are excluded from the generated type.

Please let me know what do you think of this. Thanks.

sure, looks good. You can submit PR if you want. I'll be able to implement it in a couple weeks probably.

@sarkistlt I've submitted a pull request here. Could you please take a look?

looks good, thanks!