Fork me on GitHub

@hlship Has there been any discussion of implementing custom directives (particularly schema directives) in Lacinia?


I’ve been looking for this in the issue tracker, seems like the answer so far is no. Have you found a use case for schema directives? Some frameworks use them but I’m not sure if they are an anti pattern. Also I believe the spec says that custom directives should not be supported?


Not sure what you mean that the spec says they should not be supported. They are part of the spec.


Sorry, mistyped. I recall but not 100% sure that the spec provides two built in directives, and state that there is no envisioned need for custom directives yet, and they are discouraged.


But in any case, seems like people actually use them, so I just wonder what the use cases are?


No, that's inaccurate. The spec has three built-in directives: two query (`@skip` and @include) and one schema (`@deprecated`). It fully supports adding additional query and schema directives as of June 2018.


Directives are useful because they are the primary mechanism by which most things can be extended in GraphQL, beyond the normal specification. Personally, I'm using them to generate clojure.spec specs.


Even just updating the parser to be compliant with the June 2018 spec would be useful. Currently, it chokes on valid GraphQL SDL.


Which version of Lacinia, and you provide an example?


The most recent RC. The @ character does not appear in schema.g4.


Get me an issue and examples, I'd love to make this work in some way. At the very least, we need to be able to parse valid GraphQL SDL even if we don't quite know what to do with directives in the SDL.


Right, I might remember the previous spec then...


So you are starting with the official SDL and parsing it, rather than going with the EDN flavor? I toyed with the idea of doing that but it seems it’s easier to start with EDN, the you can generate all you want directly from it.


Generating clojure.specs is very neat though.


This is for a library, not an application. It needs to ingest both Lacinia EDN and GraphQL SDL since both are commonly used.


Aaah, super cool then. We just started a new project in Clojure+Lacinia, and I am thinking similar thoughts. Is this a planned open source library?


I can (and have) make up my DSL for adding directives to Lacinia's EDN but I'd rather that be part of Lacinia itself.


Will be announced at the Conj but might be available prior to that


I’d love to have a sneak peek ;)


I had a look at lacinias parser about custom directives some time age and it seems there are no visible (to me) extension points at the moment. Skip and include are hard coded in a few places.


Also IIRC the current SDL parser was written by someone else, so I don’t believe it’s a high priority for Walmart...


I, too, am waiting for reasonable use cases before figuring out how to implement custom directives. There's big questions about what data can be safely exposed to a directive, and what changes it can make to the schema. I think a precursor to this will be providing more specs about what's in the compiled schema and/or the parsed query data structures ... we've been loathe to document these since that locks us down from changing the structure going forward. That's why we've introduced the "preview api" for example; we still have the freedom to change the internal representations as long as the preview api is also updated.


Have you seen the Apollo docs on schema directives? Here is one of their articles:


But, to be clear, I think supporting the parsing of directives and their inclusion in the compiled schema would be very useful (for me 😉 ) regardless of whether custom directive functionality is supported.