GQLBase

GQLBase

new GQLBase()

All GraphQL Type objects used in this system are assumed to have extended
from this class. An instance of this class can be used to wrap an existing
structure if you have one.

Source:
GQLBase.js, line 148

Classes

⎆⠀constructor

Members

(static, constant) ⬇︎⠀[_PROXY_HANDLER] :Object

If ES6 Proxies are supported in your execution environment, all GQLBase
extended classes are also proxies. By default the internal proxy handler
provides backwards compatibility with the removal of the default getters
and setters for the 'model' property as long as you do not define a
top level 'model' property of your own.

Type:
  • Object
Since:
2.5.0
Source:
GQLBase.js, line 693

(static, constant) ⬇︎⠀ADJACENT_FILE

Source:
GQLBase.js, line 506
See:
GQLBase#SCHEMA

(static, constant) ⬇︎⠀DOC_CLASS :String

A constant key used to identify a comment for a class description

Type:
  • String
Source:
GQLBase.js, line 884

(static, constant) ⬇︎⠀DOC_FIELDS :String

A constant key used to identify a comment for a type field description

Type:
  • String
Source:
GQLBase.js, line 901

(static, constant) ⬇︎⠀DOC_MUTATORS :String

A constant key used to identify a comment for a mutator description

Type:
  • String
Source:
GQLBase.js, line 935

(static, constant) ⬇︎⠀DOC_QUERIES :String

A constant key used to identify a comment for a query description

Type:
  • String
Source:
GQLBase.js, line 918

(static, constant) ⬇︎⠀DOC_SUBSCRIPTIONS :String

A constant key used to identify a comment for a subscription description

Type:
  • String
Source:
GQLBase.js, line 952

(static, constant) ⬇︎⠀EVENT_MODEL_HAS_BEEN_SET :String

A constant used to register an event listener for when the internal
model object is assigned a new value. This event fires after the model
is set.

Type:
  • String
Source:
GQLBase.js, line 828

(static, constant) ⬇︎⠀EVENT_MODEL_PROP_CHANGE :String

A constant used to register an event listener for when a property of the
internal model object is set to a new or intial value.

Type:
  • String
Source:
GQLBase.js, line 847

(static, constant) ⬇︎⠀EVENT_MODEL_PROP_DELETE :String

A constant used to register an event listener for when a property of the
internal model object has been deleted. This event fires after the value
has been deleted.

Type:
  • String
Source:
GQLBase.js, line 865

(static, constant) ⬇︎⠀EVENT_MODEL_WILL_BE_SET :String

A constant used to register an event listener for when the internal
model object is assigned a new value. This event fires before the model
is set. Changes to the model value at this point will affect the contents
before the value assignment takes place.

Type:
  • String
Source:
GQLBase.js, line 808

(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:
GQLBase.js, line 720

(static, constant) ⬇︎⠀joinLines :function

A shortcut to the utils/joinLines function to make it easier to get
the tools to write docs for your types in a friendly fashion.

Type:
  • function
Source:
GQLBase.js, line 969

(static, constant) ⬇︎⠀module

Returns the module object where your class is created. This needs to be
defined on your class, as a static getter, in the FILE where you are
defining your Class definition.

Source:
GQLBase.js, line 750
See:
https://nodejs.org/api/modules.html

Methods

(static) apiDocs() → {Object}

Until such time as the reference implementation of Facebook's GraphQL
SDL AST parser supports comments, or until we take advantage of Apollo's
AST parser, this is how comments will be applied to a built schema.

Several constants are defined on the GQLBase object itself, and thereby
all its subclasses. They pertain to how to define description fields
for various parts of your GQL implementation.

// To define a description on the top level class 
[this.DOC_CLASS]: String 

// To define a description on a field (getter, function or async function)
[this.DOC_FIELDS]: {
  fieldName: String
}

// To define a description on a query, mutation or subscription field 
[this.DOC_QUERIES || this.DOC_MUTATORS || this.DOC_SUBSCRIPTIONS]: {
  fieldName: String
}

To make writing code easier, the joinLines() template function is
available so your source code can look nice and neat and your descriptions
won't get annoying line breaks and spaces as part of that process.

Returns:
( Object )

an object with various keys and values denoting
description fields that should be applied to the final schema object

Source:
GQLBase.js, line 321

(static) ⌾⠀IDLFilePath(path, [extension='.graphql'])

Creates an appropriate Symbol crafted with the right data for use by
the IDLFileHandler class below.

Parameters:
Name Type Attributes Default Description
path string

a path to the IDL containing file

[extension='.graphql'] String optional
'.graphql'

an extension, including the
prefixed period, that will be added to the supplied path should it not
already exist.

Returns:

Symbol

Source:
GQLBase.js, line 523
See:
GQLBase#SCHEMA

(static) ⌾⠀MUTATORS(requestData) → {Promise}

This method should return a promise that resolves to an object of
functions matching the names of the mutation operations. These are to be
injected into the root object when used by GQLExpressMiddleware.

Parameters:
Name Type Description
requestData Object

typically an object containing three
properties; {req, res, gql}

Returns:
( Promise )

a promise that resolves to an object; see above for more
information.

Deprecated:
Place all resolvers in RESOLVERS()
Source:
GQLBase.js, line 424

(static) ⌾⠀RESOLVERS(requestData) → {Promise}

This method should return a promise that resolves to an object of
functions matching the names of the query operations. These are to be
injected into the root object when used by GQLExpressMiddleware.

Parameters:
Name Type Description
requestData Object

typically an object containing three
properties; {req, res, gql}

Returns:
( Promise )

a promise that resolves to an object; see above for more
information.

Source:
GQLBase.js, line 464

(static) ⌾⠀setupModel(instance)

The internal data model has some custom EventEmitter code wrapped
it here. When the data model is set via setModel or by accessing it
via instance[MODEL_KEY], an event EVENT_MODEL_SET is emitted. Any
listener listening for this event receives an object with two keys

{
  model: The actual model being set; changes are persisted
  instance: The GQLBase instance the model is associated with
}

Subsequently, the events EVENT_MODEL_PROP_CHANGE and
EVENT_MODEL_PROP_DELETE can be listened to if your version of node
supports Proxy objects. They allow you to be notified whenever your
model has a property changed or deleted, respectively.

The callback for change receives an object with four properties

{
  model: The model object the value is being changed on
  old: The old value being replaced; undefined if it is the first time
  key: The property key for the value being changed
  value: The new value being set
}

The callback for delete receives an object with four properties

{
  model: The model object the value is deleted from
  key: The property key for the deleted value
  deleted: The deleted value
}
Parameters:
Name Type Description
instance GQLBase

typically this as passed in from a call in
the constructor

Source:
GQLBase.js, line 562

(static) ⬇︎⠀handler() → {IDLFileHandler}

A file handler for fetching the IDL schema string from the file system
for those GQLBase extended classes that have indicated to do so by
returning a Symbol for their SCHEMA property.

Returns:

instance of IDLFileHandler, created if one does
not already exist, for fetching the contents from disk.

Source:
GQLBase.js, line 545

(static) ⬇︎⠀SCHEMA() → {string|Symbol}

Defined in a base class, this getter should return either a String
detailing the full IDL schema of a GraphQL handler or one of two
types of Symbols.

The first Symbol type is the constant ADJACENT_FILE. If this Symbol is
returned, the system assumes that next to the source file in question is
a file of the same name with a .graphql extension. This file should be
made of the GraphQL IDL schema definitions for the object types being
created.

Example:

  static get SCHEMA(): String | Symbol {
    return GQLBase.ADJACENT_FILE
  }

The primary advantage of this approach is allowing an outside editor that
provides syntax highlighting rather than returning a string from the
SCHEMA getter.

Alternatively, the static method IDLFilePath can be used to point to an
alternate location where the GraphQL IDL file resides. The extension can
also be changed from .graphql to something else if need be using this
method.

Example:

  static get SCHEMA(): String | Symbol {
    return GQLBase.IDLFilePath('/path/to/file', '.idl')
  }
Returns:
( string | Symbol )

a valid IDL string or one of the Symbols
described above.

Source:
GQLBase.js, line 373
See:
GQLBase#ADJACENT_FILE
GQLBase#IDLFilePath

⌾⠀extendModel(extensions) → {GQLBase}

Uses Object.assign to modify the internal backing data store for the
object instance. This is a shortcut for
Object.assign(instance[MODEL_KEY], ...extensions)

Parameters:
Name Type Description
extensions mixed

n-number of valid Object.assign parameters

Returns:

this is returned

Since:
2.5
Source:
GQLBase.js, line 247

⌾⠀getModel(value)

Getter for the internally stored model data. The contents of this
object are abstracted away behind a Symbol key to prevent collision
between the underlying model and any GraphQL Object Definition properties.

Parameters:
Name Type Description
value Object

any object you wish to use as a data store

Since:
2.5
Source:
GQLBase.js, line 207

⌾⠀setModel(value)

Setter for the internally stored model data. The contents of this
object are abstracted away behind a Symbol key to prevent collision
between the underlying model and any GraphQL Object Definition properties.

Parameters:
Name Type Description
value Object

any object you wish to use as a data store

Since:
2.5
Source:
GQLBase.js, line 227

⬆︎⠀requestData(value)

A setter that assigns a value to the inner request data object. When
used with GQLExpressMiddleware, this is an object matching {req, res, gql}.

Parameters:
Name Type Description
value Object

an object, usually matching { req, res, gql }

Source:
GQLBase.js, line 289

⬇︎⠀requestData() → {Object}

A getter that retrieves the inner request data object. When used with
GQLExpressMiddleware, this is an object matching {req, res, gql}.

Returns:
( Object )

an object, usually matching { req, res, gql }

Source:
GQLBase.js, line 272