Skip to content

Nested selected fields support for query #679

@JavertArdo

Description

@JavertArdo

This is follow up to #663. @pavelnikolov thanks for implementing a basic support for selected fields #673.

This request is to extend this feature to be able to get nested query fields. In most basic queries, like getting one item through GraphQL, it would be sufficient.

query getArticle {
  getArticle(id: 1) {
    id
    title
  }
}

So, the output of SelectedFieldNames will be: [id, title].

But, in real world example we are dealing with pagination where the actual content fetched from database is nested in query like this:

query getArticles {
  getArticles(first: 4, filter: {search: "some text"}) {
    totalCount
    edges {
      node {
        id
        title
        content(format: MARKDOWN)
      }
    }
    pageInfo {
      startCursor
      endCursor
      hasNextPage
      hasPrevPage
    }
  }
}

In this case SelectedFieldNames returns only: [totalCount, edges, pageInfo], which is not much helpful during selection of concrete fields of items from database.

I saw the comment in SelectedFieldNames function.

It is intentionally simple and does not expose the internal AST. If more detailed information is needed in the future (e.g. arguments per child, nested trees) a separate API can be added without breaking this one.

Would it be possible to extend this feature/function to return also nested fields in following manner: [totalCount, edges.node.id, edges.node.title, edges.node.content, pageInfo.startCursor, ...]. Holding values in complex structs is not needed and the most simple way is to have nested fields kept in string with 'dots' informing about nested level. MongoDB accepts following format when projection of values and this format seems to be flexible when processing on our own way like splitting by char, getting substring, etc.

As it was mentioned in comment, support for arguments in child items would also be appreciated.

version: v1.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions