Skip to content

Provide a way to replace an object with a single value #2807

@stefanfransen

Description

@stefanfransen

Hi, for my use case I've got images saved to products as an edge.
I can't use string lists because I'm saving a hash with the image used for image based searches.
Often I need to only get the image URLs when retrieving a product, at the moment this adds an unnecessary object for every image.

Discussion with some interesting ideas by @MichelDiz
https://discuss.dgraph.io/t/expended-edges-as-string-list/3687

What you wanted to do

I want to get this output:

{
  "product": [
    {
      "name": "Bissell Multi-oppervlaktereiniger",
      "description": "De veelzijdige CrossWave stofzuigt, dweilt en helpt bij het drogen van vloeren. \n- zowel natte als droge reiniging \n- geen stofzak",
      "image": [
        "https://www.alternate.nl/p/450x450/n/ntzrza9k_30.jpg",
        "https://www.alternate.nl/p/450x450/1/1ss9a04z_30.jpg",
        "https://www.alternate.nl/p/450x450/9/9gsheq09_30.jpg"
      ]
    }
  ]
}

With the following query:

{
  product(func: uid(0x70980)) {
    name : <http://schema.org/name>
    description : <http://schema.org/description>
    image {
      url
    }
  }
}

What you actually did

This is the output I got.

{
  "product": [
    {
      "name": "Bissell Multi-oppervlaktereiniger",
      "description": "De veelzijdige CrossWave stofzuigt, dweilt en helpt bij het drogen van vloeren. \n- zowel natte als droge reiniging \n- geen stofzak",
      "image": [
        {
          "url": "https://www.alternate.nl/p/450x450/n/ntzrza9k_30.jpg"
        },
        {
          "url": "https://www.alternate.nl/p/450x450/1/1ss9a04z_30.jpg"
        },
        {
          "url": "https://www.alternate.nl/p/450x450/9/9gsheq09_30.jpg"
        }
      ]
    }
  ]
}

So at the moment I'm modifying this output of objects into a array of strings.

Why that wasn't great, with examples

This adds extra unnecessary code.

Any external references to support your case

No references, think the reason for a function that minimizes the output is always a great addition

If this a feature more people are interested in I would love to open a PR for this.
Let me know what your thoughts are.

Stefan Fransen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/querylangIssues related to the query language specification and implementation.kind/featureSomething completely new we should consider.priority/P3Low priority, something to be done once everything else seems fixed.status/acceptedWe accept to investigate/work on it.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions