Hi all - still learning DGraph and quite enjoying it. But here’s something that is stumping me a bit although I feel there has to be something I am missing. I tried going through the docs and tutorials but I haven’t figured out a good way to do this. I am trying to ask myself very specific questions to feel confident enough to use it in production applications.
What I want to do
So imagine that we are building an Instagram clone (Modeling an Instagram clone using GraphQL and Dgraph Cloud - Dgraph Blog) again but this time, instead of modelling comments, I want to see if people are reposting the same image over and over again, and let’s say we have a way to compute image-hashes such that similar images map to the same “hash-key”.
What would be the best way to query for all posts made by username X with an image hash H? My data model is modelled after the blog post - and I am wondering if this is a wrong way to model it.
type User {
username: String! @id
name: String!
about: String
email: String!
avatarImageURL: String!
posts: [Post!] @hasInverse(field: postedBy)
following: Int!
follower: Int!
}
type Post {
id: ID!
postedBy: User!
image: Image!
description: String
likes: Int!
}
type Image {
id: ID!
imageEmbeddedHash: String! @id
}
I feel this should be doable without having to change the schema but here are some things I have tried and failed.
- Getting a user first (with getUser), and then looking at all their posts - but i can’t seem to figure out where the “imageEmbeddedHash” filter would go in this query.
query {
getUser(username: “X”) {
username
posts (filter: {image: {imageEmbeddedHash: {eq: “H”}}})
}
}
but this obviously doesn’t work because the filtering needs to happen on the image ^
There seems to be another way where I can grab all the ID for the image-hash in a separate query and then filter somewhere?
This can always be done downstream but I feel in my fake application, we should be able to access just the right data with the proper filters.
Is my data modelling wrong here? Or am I missing something really simple?