View Source Versioned.Absinthe (Versioned v0.4.0)

Helpers for Absinthe schemas.

Link to this section Summary

Functions

Convert a list of ast lines into ast lines to be used for the version object.

Declare an object, versioned compliment, and interface, based off name name.

Link to this section Functions

Link to this macro

version_fields(fields)

View Source (macro)
Link to this macro

version_lines(lines_ast)

View Source (macro)

Convert a list of ast lines into ast lines to be used for the version object.

Link to this macro

versioned_object(name, opts \\ [], list)

View Source (macro)

Declare an object, versioned compliment, and interface, based off name name.

The caller should use Absinthe.Schema.Notation as here we return code which invokes its object macro.

Both objects belong to an interface which encompasses the common fields. All common fields (except :id and :inserted_at) are included under an interface, named by the entity name and suffixed _base.

The generated object will have the following fields:

  • :id - ID of the record.
  • :version_id - ID of the most recent record's version.
  • :inserted_at - Timestamp when the record was created.
  • :updated_at - Timestamp when the record was last updated.
  • Additionally, all fields declared in the block.

The generated version object will have the following fields:

  • :id - ID of the version record.
  • :foo_id - If the entity was :foo, then this would be the id of the main record for which this version is based.
  • :is_deleted - Boolean indicating if the record was deleted as of this version.
  • :inserted_at - Timestamp when the version record was created. Additionally, all fields declared in the block.

declaring-fields-for-version-object-only

Declaring Fields for Version Object Only

In order for a field to appear only in the version object, use the :version_fields option in the (optional) keyword list before the do block:

versioned_object :car,
  version_fields: [person_versions: non_null(list_of(non_null(:person_version)))] do
  ...
end