d-exclaimation / pioneer

GraphQL for Swift.
https://pioneer.dexclaimation.com
Apache License 2.0
40 stars 8 forks source link

Custom Directives #86

Open Sherlouk opened 2 years ago

Sherlouk commented 2 years ago

This is probably one of those features which needs adopting at both the Graphiti level and in Pioneer but it would be awesome if we could create our own directives.

The most obvious and helpful one would be some form of Auth directive documented here. This could feed into Vapor's authentication solution to allow us to only return certain types or fields if the user is authenticated to view them.

This is kind of possible loosely with the validation rules released in #72, however that has a couple flaws:

  1. The rules are not made fully transparent to the end user which could cause them to make requests they're not eligible unintentionally and cause confusion
  2. An error thrown in a validation rule will prevent any of the request from being made. It would be nice if, for example, the user requested 5 fields and only one of them was protected to still return the other 4.
d-exclaimation commented 2 years ago

I'll look into this and see what I can do on both Pioneer and Graphiti level

Sherlouk commented 2 years ago

This could also feed into cost analysis by attributing a directive to a type or field it would indicate elegantly how much each type costs.

Type() {

} .description("") .directive(AuthDirective(...)) .directive(CostDirective(...))