graphql-dotnet/conventions

How to ignore or exclude CLR type properties

batesm opened this issue · 7 comments

Great work on this project! I have a question though and hope you can help?

When resolving a graph type from a CLR type what is the correct approach to filtering out certain properties so that they are ignored or excluded from the resolved graph type and do not appear as fields?

Thank you.

Thanks for this. However, I realise I should have been clearer in my original question.

In my case I would like to avoid decorating the member with the attribute declaratively. I would like to achieve the same thing but leaving the POCO unblemished. Is there a way to associate the attribute with the member in some other way. An example would be intercepting the type resolver or metadata handler somehow? I will be referring to a "schema policy" which dynamically controls what types and fields are exposed dependent on permissions.

@batesm Have you looked at IDefaultAttribute? It will execute your custom attribute in every type/ member. And there you can apply any custom logic to filter your fields and set GraphEntityInfo.IsIgnored.

tlil commented

Yep, as @BilyachenkoOY says, @batesm, and for an example: NameAttribute.cs

Thanks both. Some time ago I did code up a IDefaultAttribute implementation as you describe but it did not appear to influence the IsIgnored property. It turns out that I had a field returning type Task< Customer > which clashed with a separate type Customer. IsIgnored = true was applied on one GraphTypeInfo but not on the other. The resultant schema has the property included rather than ignored.

You can also pass own TypeResolver to the engine and use TypeResolver.IgnoreTypesFromNamespacesStartingWith or check #171.

tlil commented

@batesm I'll close this one, however, feel free to reopen if you have any requests further to this.