View Source Bonfire.Common.Needles (Bonfire v0.9.10-classic-beta.169)

Helpers for handling Needle Pointers

Summary

Functions

Resolves pointers for GraphQL API batch loading.

Checks if an object exists based on the given filters.

Filters a single pointer from a query result.

Applies filters to a query.

Follows one or more pointers and returns the schema struct.

Forge a pointer from a pointable object.

Forges a pointer to a participating meta entity

Retrieves an object by its ID.

Retrieves an object by its ID. Raises NotFound if the object cannot be found.

Filters an object by its binary ID.

Filters an object by its ID.

Retrieves a list of objects based on pointers or IDs.

Retrieves objects based on type and filters.

Retrieves a list of known IDs

Retrieves many objects based on the provided filters

Retrieves many objects based on the provided filters

Turns a thing into a pointer if it is not already or returns nil.

Turns a thing into a pointer if it is not already. Errors if it cannot be performed.

Resolves associations or fields based on the given parent and context.

Retrieves an object by its ID or pointer.

Retrieves a single object based on the provided filters with bang.

Preloads associations based on the given preloads option.

Prepares a query for pointers.

Follows one or more pointers and adds the pointed records to the pointed attrs.

Queries a dataset based on provided filters.

Functions

Resolves pointers for GraphQL API batch loading.

Examples

iex> Bonfire.Common.Needles.dataloader(context)
%Dataloader{...}
Link to this function

exists?(filters, opts \\ [])

View Source

Checks if an object exists based on the given filters.

Examples

iex> Bonfire.Common.Needles.exists?("some_id")
true

iex> Bonfire.Common.Needles.exists?("non_existent_id")
false

Filters a single pointer from a query result.

Examples

iex> Bonfire.Common.Needles.filter_one("http://url")
[canonical_uri: "http://url"]
Link to this function

filters(schema, id_filters, opts \\ [])

View Source

Applies filters to a query.

Examples

iex> Bonfire.Common.Needles.filters(query, filters)
%Ecto.Query{...}
Link to this function

follow!(pointer_or_pointers, opts \\ [])

View Source

Follows one or more pointers and returns the schema struct.

Examples

iex> Bonfire.Common.Needles.follow!(%Pointer{id: "some_id"})
%SomeRecord{}

iex> Bonfire.Common.Needles.follow!([%Pointer{id: "some_id"}])
[%SomeRecord{}]
Link to this function

follow_function_error(error, args)

View Source
@spec forge!(%{__struct__: atom(), id: binary()}) :: %Needle.Pointer{
  __meta__: term(),
  account: term(),
  accounted: term(),
  activities: term(),
  activity: term(),
  actor: term(),
  boost_count: term(),
  care_closure: term(),
  caretaker: term(),
  category: term(),
  character: term(),
  choices: term(),
  circle: term(),
  controlled: term(),
  created: term(),
  deleted_at: term(),
  direct_replies: term(),
  dummy: term(),
  edge: term(),
  encircle_subjects: term(),
  extra_info: term(),
  feed_publishes: term(),
  files: term(),
  follow_count: term(),
  geolocation: term(),
  id: term(),
  labelled: term(),
  like_count: term(),
  media: term(),
  message: term(),
  named: term(),
  peered: term(),
  pointed: term(),
  post: term(),
  post_content: term(),
  profile: term(),
  ranked: term(),
  replied: term(),
  seen: term(),
  sensitive: term(),
  settings: term(),
  stereotyped: term(),
  table: term(),
  table_id: term(),
  tagged: term(),
  tags: term(),
  tree: term(),
  user: term()
}

Forge a pointer from a pointable object.

Does not hit the database, is safe so long as the provided struct participates in the meta abstraction.

Examples

iex> Bonfire.Common.Needles.forge!(%{__struct__: MySchema, id: "some_id"})
%Pointer{id: "some_id", ...}
@spec forge!(table_id :: integer() | atom(), id :: binary()) :: %Needle.Pointer{
  __meta__: term(),
  account: term(),
  accounted: term(),
  activities: term(),
  activity: term(),
  actor: term(),
  boost_count: term(),
  care_closure: term(),
  caretaker: term(),
  category: term(),
  character: term(),
  choices: term(),
  circle: term(),
  controlled: term(),
  created: term(),
  deleted_at: term(),
  direct_replies: term(),
  dummy: term(),
  edge: term(),
  encircle_subjects: term(),
  extra_info: term(),
  feed_publishes: term(),
  files: term(),
  follow_count: term(),
  geolocation: term(),
  id: term(),
  labelled: term(),
  like_count: term(),
  media: term(),
  message: term(),
  named: term(),
  peered: term(),
  pointed: term(),
  post: term(),
  post_content: term(),
  profile: term(),
  ranked: term(),
  replied: term(),
  seen: term(),
  sensitive: term(),
  settings: term(),
  stereotyped: term(),
  table: term(),
  table_id: term(),
  tagged: term(),
  tags: term(),
  tree: term(),
  user: term()
}

Forges a pointer to a participating meta entity

Does not hit the database, is safe so long as the entry we wish to synthesise a pointer for represents a legitimate entry in the database.

Examples

iex> Bonfire.Common.Needles.forge!(:my_table, "some_id")
%Pointer{id: "some_id", ...}

Retrieves an object by its ID.

Examples

iex> Bonfire.Common.Needles.get("existing_id")
{:ok, %Pointer{id: "existing_id", ...}}

iex> Bonfire.Common.Needles.get("non_existent_id")
{:error, :not_found}

Retrieves an object by its ID. Raises NotFound if the object cannot be found.

Examples

iex> Bonfire.Common.Needles.get!("existing_id")
%Pointer{id: "existing_id", ...}

iex> Bonfire.Common.Needles.get!("non_existent_id")
** (Needle.NotFound) ...

Filters an object by its binary ID.

Examples

iex> Bonfire.Common.Needles.id_binary(id: "some_id")

Filters an object by its ID.

Examples

iex> Bonfire.Common.Needles.id_filter(query, id: "some_id")
Link to this function

list!(pointers, opts \\ [])

View Source

Retrieves a list of objects based on pointers or IDs.

Examples

iex> Bonfire.Common.Needles.list!(["id1", "id2"])
[%Pointer{id: "id1", ...}, %Pointer{id: "id2", ...}]

iex> Bonfire.Common.Needles.list!([%Pointer{id: "id1"}, %Pointer{id: "id2"}])
[%Pointer{id: "id1", ...}, %Pointer{id: "id2", ...}]
Link to this function

list_by_type!(table_id_or_schema, filters \\ [], opts \\ [])

View Source

Retrieves objects based on type and filters.

Examples

iex> Bonfire.Common.Needles.list_by_type!(:my_table, [filter: value])
[%Pointer{...}, %Pointer{...}]

Retrieves a list of known IDs

Examples

iex> Bonfire.Common.Needles.list_ids()
["id1", "id2"]
Link to this function

many(filters \\ [], opts \\ [])

View Source

Retrieves many objects based on the provided filters

Examples

iex> Bonfire.Common.Needles.many([id: "some_id"])
{:ok, [%Pointer{id: "some_id", ...}]}

iex> Bonfire.Common.Needles.many([id: "non_existing_id"])
{:ok, []}
Link to this function

many!(filters \\ [], opts \\ [])

View Source

Retrieves many objects based on the provided filters

iex> Bonfire.Common.Needles.many!([id: "some_id"])
[%Pointer{id: "some_id", ...}]

Turns a thing into a pointer if it is not already or returns nil.

Examples

iex> Bonfire.Common.Needles.maybe_forge(%Pointer{id: "existing_id"})
%Pointer{id: "existing_id"}

iex> Bonfire.Common.Needles.maybe_forge(%{pointer_id: "existing_id"})
%Pointer{id: "existing_id"}

iex> Bonfire.Common.Needles.maybe_forge(%{id: "existing_id"})
nil

Turns a thing into a pointer if it is not already. Errors if it cannot be performed.

iex> Bonfire.Common.Needles.maybe_forge!(%Pointer{id: "existing_id"})
%Pointer{id: "existing_id"}

iex> Bonfire.Common.Needles.maybe_forge!(%{pointer_id: "existing_id"})
%Pointer{id: "existing_id"}

iex> Bonfire.Common.Needles.maybe_forge!(%{id: "non_existing_id"})
** (RuntimeError) ...
Link to this function

maybe_resolve(parent, field, args, context)

View Source

Resolves associations or fields based on the given parent and context.

Examples

iex> Bonfire.Common.Needles.maybe_resolve(parent, field, args, context)
{:ok, resolved_data}

Retrieves an object by its ID or pointer.

Examples

iex> Bonfire.Common.Needles.get("some_id")
{:ok, %Pointer{id: "some_id", ...}}

iex> Bonfire.Common.Needles.get([id: "some_id"])
{:ok, %Pointer{id: "existing_id", ...}}
Link to this function

one!(filters, opts \\ [])

View Source

Retrieves a single object based on the provided filters with bang.

iex> Bonfire.Common.Needles.one!("some_id")
%Pointer{id: "some_id", ...}

iex> Bonfire.Common.Needles.one!([id: "some_id"])
%Pointer{id: "some_id", ...}
Link to this function

pointer_preloads(query, preloads)

View Source

Preloads associations based on the given preloads option.

Examples

iex> Bonfire.Common.Needles.pointer_preloads(query, :with_creator)
%Ecto.Query{...}

iex> Bonfire.Common.Needles.pointer_preloads(query, :tags)
%Ecto.Query{...}

Prepares a query for pointers.

Examples

iex> Bonfire.Common.Needles.pointer_query(query, opts)
%Ecto.Query{...}

iex> Bonfire.Common.Needles.pointer_query([id: "some_id"], opts)
%Ecto.Query{...}
Link to this function

preload!(pointer_or_pointers, opts \\ [])

View Source
@spec preload!(Needle.Pointer.t() | [Needle.Pointer.t()], list()) ::
  Needle.Pointer.t() | [Needle.Pointer.t()]

Follows one or more pointers and adds the pointed records to the pointed attrs.

iex> Bonfire.Common.Needles.preload!(%Pointer{id: "some_id"})
%Pointer{id: "some_id", pointed: %SomeRecord{}}

iex> Bonfire.Common.Needles.preload!([%Pointer{id: "some_id"}])
[%Pointer{id: "some_id", pointed: %SomeRecord{}}]
Link to this function

query(schema, filters, opts \\ [])

View Source

Queries a dataset based on provided filters.

Examples

iex> Bonfire.Common.Needles.query(filters)
%Ecto.Query{...}