View Source Bonfire.Common.Needles (Bonfire v0.9.11-social-beta.3)

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

dataloader(context)

Resolves pointers for GraphQL API batch loading.

Examples

iex> Bonfire.Common.Needles.dataloader(context)
%Dataloader{...}

exists?(filters, opts \\ [])

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

filter_one(filters)

Filters a single pointer from a query result.

Examples

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

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

Applies filters to a query.

Examples

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

follow!(pointer_or_pointers, opts \\ [])

Follows one or more pointers and returns the schema struct.

Examples

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

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

follow_function_error(error, args)

forge!(pointed)

@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", ...}

forge!(table_id, 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", ...}

get(id, opts \\ [])

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}

get!(id, opts \\ [])

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) ...

id_binary(id)

Filters an object by its binary ID.

Examples

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

id_filter(query, id)

Filters an object by its ID.

Examples

iex> Bonfire.Common.Needles.id_filter(query, id: "some_id")

list!(pointers, opts \\ [])

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", ...}]

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

Retrieves objects based on type and filters.

Examples

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

list_ids()

Retrieves a list of known IDs

Examples

iex> Bonfire.Common.Needles.list_ids()
["id1", "id2"]

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

Retrieves many objects based on the provided filters

Examples

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

> Bonfire.Common.Needles.many([id: "non_existing_id"])
{:ok, []}

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

Retrieves many objects based on the provided filters

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

maybe_forge(thing)

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

maybe_forge!(thing)

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) ...

maybe_resolve(parent, field, args, context)

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}

one(id, opts \\ [])

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", ...}}

one!(filters, opts \\ [])

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", ...}

pointer_preloads(query, preloads)

Preloads associations based on the given preloads option.

Examples

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

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

pointer_query(q, opts)

Prepares a query for pointers.

Examples

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

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

preload!(pointer_or_pointers, opts \\ [])

@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.

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

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

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

Queries a dataset based on provided filters.

Examples

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