Skip to content

Is it possible to return values that are computed from other db columns? #1264

Discussion options

You must be logged in to vote

For posterity, I was able to accomplish this with simple computed fields.

I used the normal column title to put the computed database value into, then I did computed resolvers on title and titleHighlight to accomplish what I needed.

 t.field('title', {
      type: 'String',
      resolve: (item) => {
        // Strip out highlight strings
      },
})

t.field('titleHighlight', {
      type: 'String',
      resolve: (item) => {
        // If their is a highlight string in title, return the title
        // else return empty string
      },
})

And in my SQL select statement:

...
ts_headline(title, q) as title
...

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by special-character
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant