Namespace: pxdb

pxdb

PXDB library namespace.

Source:

Classes

engine

Methods

(static) create_backbone_classes(engine, typespec, queries, rpb) → {object}

Generates Backbone model and collection classes using the types in TYPESPEC and the GraphQL queries in QUERIES. Returns an object with the model and collection classes, with the keys being the class names. The model classes will be named for the type; collection classes will have the type name with "_collection" appended.

NOTE: This function is called automatically by engine.init().

Parameters:
Name Type Description
engine object

PXDB engine instance.

typespec object

Type specification from extract_types_from_schema

queries object

GraphQL query templates from generate_gql_queries

rpb boolean

If true, this is for the roles_pbac schema; false otherwise.

Source:
Returns:

Backbone classes object.

Type
object

(static) extract_types_from_schema(schema) → {object}

Returns an object containing the type specification for each defined type in the GraphQL schema. This excludes introspection and builtin scalar types. The type map will look like this:

 {types: TYPENAME: TYPENAME | {
       ATTRIBNAME: ATTRIBTYPE | [ATTRIBTYPE],
       ...},
  ...},
  inputs: INPUT-TYPENAME: {
    ATTRIBNAME: ATTRIBTYPE | [ATTRIBTYPE],
    ...},
  ...},
  mutations: {MUTATIONNAME: {ARGNAME: ARGTYPE, ...}}
 }

If TYPENAME names a scalar, its value will be the same as the key. If ATTRIBTYPE is a scalar or object type, it will be given as a string name; a list will be given as an array containing the element type.

NOTE: This function is called automatically by engine.init().

Parameters:
Name Type Description
schema object

GraphQL introspection schema.

Source:
Returns:

Type specification for the schema.

Type
object

(static) generate_gql_queries(typespec, max_recursion) → {object}

Returns an object containing the query/mutation templates for each of the defined types (i.e., not introspection or scalar types) in the provided schema TYPESPEC. The GraphQL templates will have accompanying information on the available fields; for queries, this will be the available fields in the query type, while for mutations, the input fields will be provided.

The resulting object will have this structure:

{
    TYPENAME: {
        create: MUTATION,
        read: QUERYSPEC,
        update: MUTATION,
        delete: MUTATION
    },
    ...
}

QUERYSPEC will be an object with this structure:

{
     query: QUERYSTRING,
     fields: FIELDLIST
}

MUTATION will be a templated string.

The templates will be used to generate query functions for each query or mutation type by Backbone.sync. The fields list will be used to create the available field list for use by model or collection classes in the .fields() method.

MAX_RECURSION, which defaults to Infinity, sets the maximum level to which the code will descend in "nested" types, such as collections or object references on a given type. If this is set to 0, no "nested" types, including types that represent complex scalar objects (such as FileObjects or Geometries) will be included; if set to 1, only the first "level" of nested types will be included, and so forth.

NOTE: This function is called automatically by engine.init().

Parameters:
Name Type Description
typespec object

Type specification from extract_types_from_schema

max_recursion integer

Maximum level to recurse into nested types.

Source:
Returns:

GraphQL query templates.

Type
object