GQLDirective.java

  1. package net.morimekta.providence.graphql.gql;

  2. /**
  3.  * A directive represents some modification on a GQL field. It can for
  4.  * the most part be handled in-line, as the query and arguments are
  5.  * parsed, but may be (some time in the future) required to be kept
  6.  * along the field selection.
  7.  */
  8. public enum GQLDirective {
  9.     /**
  10.      * <code>&#64;include(if: $var)</code>
  11.      *
  12.      * Include the field only if 'if' resolves to true.
  13.      */
  14.     include,
  15.     /**
  16.      * <code>&#64;include(if: $var)</code>
  17.      *
  18.      * Include the field only if 'if' resolves to false.
  19.      */
  20.     skip,
  21.     ;

  22.     /**
  23.      * Find directive by the name, not including the '@'.
  24.      *
  25.      * @param name The directive name.
  26.      * @return The directive, or null if not found.
  27.      */
  28.     public static GQLDirective findByName(String name) {
  29.         for (GQLDirective directive : values()) {
  30.             if (directive.name().equals(name)) {
  31.                 return directive;
  32.             }
  33.         }
  34.         return null;
  35.     }
  36. }