question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@searchable transforms and connections

See original GitHub issue

Is there a way to get the @searchable to also work with @connection. Say I have these models.

type Post @model @searchable {
    id: ID!
    text: String
    votes: [Vote] @connection(name: "PostVotes")
}

type Vote @model @searchable {
    id: ID!
    vote: Int!
    post: Post! @connection(name: "PostVotes")
}

The generated searchVotes query would then only be able to filter on id and vote. But say I want to get all the votes for a certain postId.

Likewise the ListVotes query doesn’t either provide a filter on the post connection.

So how would I in this case go about to get all the Votes on a certain post?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
josefaidtcommented, Apr 5, 2022

Hey y’all 👋 I wanted to follow-up on this one and show how this is now possible with GraphQL Transformer v2 and the new relational directives! Using the following schema we will be able to create a Post, create a Vote linked to the Post, then run a search query by post ID.

type Post @model @searchable {
  id: ID!
  text: String
  votes: [Vote] @hasMany
}

type Vote @model @searchable {
  id: ID!
  vote: Int!
  post: Post!
}

Then we can execute the following in order to ultimately search Votes by Post ID

mutation CREATE_POST {
  createPost(input: {text: "my first post"}) {
    id
  }
}

mutation CREATE_VOTE {
  createVote(input: {vote: 10, postVotesId: "a7173361-d420-44fd-abb9-88b26f7a506b"}) {
    id
  }
}

query SEARCH_BY_ID {
  searchVotes(filter: {postVotesId: {eq: "a7173361-d420-44fd-abb9-88b26f7a506b"}}) {
    items {
      id
      postVotesId
      vote
    }
  }
}

Where the search query will return:

{
  "data": {
    "searchVotes": {
      "items": [
        {
          "id": "34caeece-2530-452c-8965-0f3d097b545c",
          "postVotesId": "a7173361-d420-44fd-abb9-88b26f7a506b",
          "vote": 10
        }
      ]
    }
  }
}

Closing issue 🙂 if you feel this does not quite cover your use case please reply back to this thread and we can re-open to investigate further!

1reaction
Hoxnicommented, May 18, 2022

How to search votes by text in related posts? For example how to get votes, where related post contains word “test” in field text?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[1902.01280] A New Class of Searchable and Provably ... - arXiv
This new family is a special case of a more general class of transformations based on context adaptive alphabet orderings, a concept introduced ......
Read more >
Transforming data | Elasticsearch Guide [8.5] | Elastic
Transforms enable you to convert existing Elasticsearch indices into summarized indices, which provide opportunities for new insights and analytics.
Read more >
transforms.conf - Splunk Documentation
Use this name when you configure field extractions, lookup tables, and event routing in props.conf. For example, if you are setting up an ......
Read more >
Transform Data by Example - Microsoft Research
Moreover, you can add your own data transformation code into the collection, and Transform-Data-by-Example will make them instantly searchable ...
Read more >
API (GraphQL) - Overview - AWS Amplify Docs
You are currently viewing the legacy GraphQL Transformer documentation. ... The GraphQL Transform provides a simple to use abstraction that helps you quickly ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found