Replies: 4 comments
-
Related issues: |
Beta Was this translation helpful? Give feedback.
0 replies
-
Prototypes for a type safe API: |
Beta Was this translation helpful? Give feedback.
0 replies
-
Prototype for a simple API, not type safe: #918 |
Beta Was this translation helpful? Give feedback.
0 replies
-
We will go with #918 first, the simplest API. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The problem
As experienced with GraphQL federation, users of sangria often needs to add custom directives to fields, object types...
current API is not user-friendly
The current way for doing is using the
copy
method and is not friendly:current API is not type safe
Furthermore, custom directives declare locations, restricting where they can be applied.
Currently, a custom directive can be used on any types that accepts
ast.Directive
.For example, the following compiles although the
Key
directive should not be applied to aField
:possible solutions
Relying on the author of the directive providing helpers
We can rely on the author of the directive to provide type helpers. Example:
Issues with that approach:
copy
method to apply the directive on any other types.In theory, it would be possible to add extension methods through implicit conversions for a better API:
but scalac is not clever enough to infer the right types:
We need to help it, and the result is not optimal:
Adding type safe directive on builders
Another way would be to tag directive to indicate where they can be applied:
or:
and then we could add those in
apply
method:That way, we could use a directive directly:
or on a method:
This approach seems to most promising:
I still have to check if this approach can compile ;)
Next steps
Once this API stabilized, we need to check how to support custom directives with auto-derivation.
Beta Was this translation helpful? Give feedback.
All reactions