TryGhost / TryGhost/NQL

Aliases/expansions research

Open
#8 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Research
Dominant language
JavaScript
Stars
7
Forks
7
Avg merge
9h 4m
Merged PRs (30d)
22

Description

Background

nql-lang introduced aliases support mid of 2018. nql-lang is able to replace keys in a filter string.

State of NQL 0.2.1

A month a go we added the missing NQL features (e.g. relations, mongo json utility etc.). This is what you have to know:

Aliases are now called: expansions. We no longer use the wording aliases. The reason is that there are two requirements for replacing stuff in a filter:

  1. replace a key name e.g. filter=tags:x -> {tags.slug:x}
  2. expand a statement if a key name matches e.g. filter:primary_tag:de -> {$and: [{tags.slug:de}, {sort_order:0}]} (optional)

That means, the expansions feature is more than just a simple string replacement. It can expand the mongo JSON query.

When the merge json utility logic was moved over from Ghost to NQL, i noticed that we no longer use nql-lang to replace the aliases/expansions. The expansion logic does it now.

Why?

All string filters are parsed by nql-lang as first step. And afterwards we pass the parsed filters into the utility. As soon as a key matches the configured expansions, the expansion logic replaces the key in the mongo json object and adds/extends the expansion filter to the target statement

e.g.

filter=tags:bla+primary_tag:blub

should be

filter=tags.slug:bla+(tags.slug:blub+posts_tags.sort_order:0)

If nql-lang would replace the name independently of the expanded filter, we first would get:

{$and: [tags.slug:bla, tags.slug:blub]}

Now you don't know which part you need to expand?

Discussion/Research

We have not spend further time on this. Is it possible to use nql-lang again?
This needs a bit playing & thinking.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the alias support introduced in the nql-lang commit with the expansion logic in mongo-utils/lib/mongo-utils.js around line 114. Trace how parsed filters and merge-json expansion interact, starting with the tags and primary_tag example. Done means determining whether nql-lang can safely handle expansions again without losing the target statement context, and documenting the conclusion.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.