JSONAPIPlug.QueryParser.Ecto.Include (jsonapi_plug v2.0.3)

Copy Markdown View Source

JSON:API include query parameter parser implementation for Ecto

Parses a comma-separated JSON:API include string and converts it into a nested keyword list suitable for use as the :preload option to Ecto.Repo functions.

For example, the query string:

?include=author,bestComments.user.company,bestComments.user.topPosts

is parsed into:

[author: [], best_comments: [user: [company: [], top_posts: []]]]

Relationship names are converted from camelCase to snake_case. Paths that share an intermediate relationship node are deep-merged so that all leaf preloads are preserved.

Summary

Functions

check_relationship_include(resource, valid_relationships_includes, allowed_includes, include_name, path, relationship_includes)