Fork me on GitHub
#graphql
<
2018-10-01
>
domkm17:10:34

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

orestis17:10:10

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?

domkm17:10:45

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

orestis17:10:12

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.

orestis17:10:31

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

domkm17:10:46

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.

domkm17:10:56

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.

domkm17:10:06

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

hlship17:10:08

Which version of Lacinia, and you provide an example?

domkm17:10:37

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

hlship17:10:16

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.

orestis17:10:01

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

orestis17:10:15

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.

orestis17:10:37

Generating clojure.specs is very neat though.

domkm17:10:02

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

orestis17:10:12

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?

domkm17:10:13

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.

domkm17:10:39

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

orestis17:10:13

I’d love to have a sneak peek ;)

orestis17:10:09

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.

orestis17:10:57

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

hlship17:10:03

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.

domkm17:10:08

Have you seen the Apollo docs on schema directives? Here is one of their articles: https://www.apollographql.com/docs/graphql-tools/schema-directives.html

domkm17:10:00

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.