Code Monkey home page Code Monkey logo

Comments (17)

emolr avatar emolr commented on August 23, 2024 6

I needed this as well to show posts related to tags, so i created this (rather ugly but working) temporary solution in angular 2.
https://gist.github.com/emolr/f2eaf46612ca7bbb47b6a814180da719

It does the job for now, but it is pretty slow compared to a single request, but it works, so I'll spend the extra time on a good loading animation. It might help someone needing the same functionality until it's implemented

My temporary approach have some limitations though.
When i began implementing search i found that i can't both have my search filter: {id_in: ['1', '2']}
while using my tag posts lookup ids as they work on the same filter argument.

So dream scenario would be something like filter: {AND: [id_in: ['1','2'], tagId_in: ['73', '23']]}
I would then expect it to return only the posts which has related tags with id 73 & 23 and id 1 og 2, and if both post 1 and 2 has tags 73 and 23 the query would return both posts

from prisma1.

schickling avatar schickling commented on August 23, 2024 5

Very good point. This is already WIP. 🎉

from prisma1.

philcockfield avatar philcockfield commented on August 23, 2024 5

I'd really like this too - and is core to the kind of structure I'm wishing to manage within GraphQL. Here's some details my use-case…

image

I am representing a deep tree structure, with each node called say "Item" that has a collection of child Item's and a single parent Item.

I'd like to be able query for:

  • any item with a parent ID of x.
  • any item with a parent ID of undefined.
  • return the item with the children items including a specified depth of grand-children into the tree.

Thanks!

from prisma1.

sedubois avatar sedubois commented on August 23, 2024 2

Ahh that was nasty, those two missing braces 😄 thanks @marktani!

from prisma1.

sedubois avatar sedubois commented on August 23, 2024 1

Meanwhile @philcockfield you might be able to filter client-side: https://github.com/RelateNow/relate/blob/9dc89b460410b878bc2574af6043f79f86a1f5b3/containers/Users.js#L16

from prisma1.

marktani avatar marktani commented on August 23, 2024 1
{
  allUsers(filter: {
    OR: [{
     retreats_some: {
        id_not: "dummy"
      }
    }, {
      tracks_some: {
        id_not: "dummy"
      }
    }]
  }) {
    givenName
  }
}

You need to pass the different conditions as elements of the list argument OR.

from prisma1.

philcockfield avatar philcockfield commented on August 23, 2024

Hey guys - any clue as to whether this is something that might be implemented in the near-ish future? I need to make a decision somewhat soon as to whether to use Graph.cool, and this is a blocker for me.

Thanks!

from prisma1.

schickling avatar schickling commented on August 23, 2024

Hey @philcockfield! We're already working on this feature. We're expecting to release this in January. Hope that works for you?

from prisma1.

philcockfield avatar philcockfield commented on August 23, 2024

That's awesome @schickling. I really want to stick with graphcool.
What is the query parameters going to look like. Can you post your current API design/intentions? Even if they my change 😃

from prisma1.

philcockfield avatar philcockfield commented on August 23, 2024

@sedubois - thanks for that stop-gap for filtering on the client. To be clear, that's pulling the entire data-set, then just running filters client side right?

That will certainly let me proceed with GraphCool for everything else, then refactor this when this feature is complete (in Jan)

from prisma1.

sedubois avatar sedubois commented on August 23, 2024

@philcockfield yes, should work while you don't have too much data.

from prisma1.

sorenbs avatar sorenbs commented on August 23, 2024

We are starting the implementation of this feature this week.

Feedback is highly appreciated at https://gist.github.com/sorenbs/dec072b8b4df0ab6cbd441861a53eaf9

from prisma1.

schickling avatar schickling commented on August 23, 2024

This is now possible using both the Simple and the Relay API. 🎉

You can read more about this feature here: https://www.graph.cool/docs/reference/simple-api/filtering-by-field-xookaexai0#relation-filters

from prisma1.

sedubois avatar sedubois commented on August 23, 2024

Thanks @schickling for that documentation!

Let's say I have a User model and a Track model, with a one-to-many tracks relationship. How would I query all users which have at least one track?

from prisma1.

sedubois avatar sedubois commented on August 23, 2024

This works but is a bit smelly:

{
  allUsers(filter: {
    tracks_some: {
      id_not: "dummy"
    }
  }) {
    givenName
  }
}

from prisma1.

marktani avatar marktani commented on August 23, 2024

Something like that is the way to go. A different solution:

{
  allUsers(filter: {
    tracks_some: {
      # query all that have been created in the past (2017-02-06-16:13:39 is now)
      createdAt_lt: "2017-02-06-16:13:39"
    }
  }) {
    givenName
  }
}

from prisma1.

sedubois avatar sedubois commented on August 23, 2024

OK. Now I actually have a second relation retreats with model Retreat. How do I select all users who have at least one track or at least one retreat? This gives an empty list:

{
  allUsers(filter: {
    OR: [{
      retreats_some: {
        id_not: "dummy"
      }
      tracks_some: {
        id_not: "dummy"
      }
    }]
  }) {
    givenName
  }
}

from prisma1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.