Company
Date Published
Author
Leonardo Losoviz
Word count
3635
Language
-
Hacker News points
None

Summary

An @export directive in GraphQL aims to enhance query performance by allowing the value of a field to be exported into a variable for use elsewhere in the query, thus enabling the combination of two queries into one. This functionality, which has not yet been officially incorporated into the GraphQL specification due to technical challenges, can be implemented in servers like Gato GraphQL that control field resolution order. The directive supports exporting single values, lists, dictionaries, and lists of dictionaries, using a dynamic variable that begins with an underscore to differentiate it from static variables. The implementation involves design decisions such as using a "self" field to manipulate the order of field execution and ensuring dynamic variables are declared with default values. Additionally, @export can make directives like @skip and @include dynamic by conditionally executing based on object properties, although it currently only works for single values, not lists. The article highlights the importance of supporting custom directives in GraphQL servers to improve API performance, despite the absence of an official solution for the @export directive.