GQLEnum

GQLEnum

new GQLEnum()

GraphQL Enum types can be a bit picky when it comes to how scalar types
equate to enum values. Lattice makes this easier by allowing you to specify
a value or the key when your enum has a value other than the key; GraphQL
does not allow this by default.

Further more, when instantiating a GQLEnum type, you can pass a string or
value matching the enum key or value or you can pass an object with key of
value and the value being either the enum key or value. If any of those
things match, then your instance.value will equate to the enum's key. If,
on the other hand, your supplied values do not match then instance.value
will be null.

Source:

Members

(static, constant) ⬇︎⠀GQL_TYPE

Determines the default type targeted by this GQLBase class. Any
type will technically be valid but only will trigger special behavior

Source:

Methods

(static) .get(obj, key) → {mixed}

Get handler for the Map backed Array Proxy

Source:
Parameters:
Name Type Description
obj mixed

the object targeted by the Proxy

key string

key of the value being requested

Returns:
Type:
mixed

the value being requested

(static) .set(obj, key, value)

Set handler for the Map backed Array Proxy.

Source:
Parameters:
Name Type Description
obj mixed

the object the Proxy is targeting

key string

a string key being set

value mixed

the value being assigned to key

(static) valueFor(value, deprecationReason, description) → {Object}

Shorthand method to generate a GraphQLEnumValueDefinition implementation
object. Use this for building and customizing your values key/value
object in your child classes.

Source:
Parameters:
Name Type Description
value mixed

any nonstandard value you wish your enum to have

deprecationReason String

an optional reason to deprecate an enum

description String

a non Lattice standard way to write a comment

Returns:
Type:
Object

an object that conforms to the GraphQLEnumValueDefinition
defined here http://graphql.org/graphql-js/type/#graphqlenumtype

(static) ⬇︎⠀enums() → {Array.<Symbol>}

For easier use within JavaScript, the static enums method provides a
Symbol backed solution for each of the enums defined. Each Symbol
instance is wrapped in Object so as to allow some additional properties
to be written to it.

Source:
Returns:
Type:
Array.<Symbol>

an array of modified Symbols for each enum
variation defined.

(static) ⬇︎⠀name() → {mixed}

Retrieves the actual symbol stored name property from the internal
model object for this enum instance. That is a mouthfull, but it
basically means that if your enum is something like:

enum Person { TALL, SHORT }

and you create an instance using any of the following

p = new Person('TALL')
p = new Person(valueFor('TALL'))
p = new Person({value: 'TALL'})

that your response to p.name will equate to TALL.

Source:
Returns:
Type:
mixed

typically a String but any valid type supplied

(static) ⬇︎⠀value() → {mixed}

Much like the .name getter, the .value getter will typically
retreive the name of the enum key you are requesting. In rare cases
where you have defined values that differ from the name, the .value
getter will retrieve that custom value from the .value property on
the symbol in question.

This should do the right thing even if you instantiated the instance
using the name.

Source:
Returns:
Type:
mixed

the value of the enum type; this in all likihood should
be a String or potentially an object

(static) ⬇︎⠀values() → {Object|Null}

Each instance of GQLEnum must specify a map of keys and values. If this
method returns null or is not defined, the value of the enum will match
the name of the enum as per the reference implementation.

Example:

  static get values(): ?Object {
    const { valueOf } = this;

    return {
      NAME: valueOf(value)
    }
  }
Source:
Returns:
Type:
Object | Null

an object mapping with each key mapping to an object
possessing at least a value field, which in turn maps to the desired value

GenerateEnumsProxyHandler(map) → {Object}

Due to the complexity of being able to access both the keys and values
properly for an enum type, a Map is used as the backing store. The handler
returned by this method is to be passed to a Proxy.

Source:
Parameters:
Name Type Description
map Map

the map containing the key<->value and
value<->key mappings; the true storage backing the array in question.

Returns:
Type:
Object