Odd query issue, different data output

prisma

#1

Hi, I’m trying to query posts, and get posts of logged in user and friends.

query getFeed($id: ID) {
  posts(where: {OR:[{ author: { friends_some: { id: $id }}} ]}) {
    author { name }
    text
  }
}

Results for User1’s ID:

{
  "data": {
    "posts": []
  }
}

Results for User2’s ID:

{
  "data": {
    "posts": [
      {
        "author": {
          "name": "Sarah"
        },
        "text": "I like turtles."
      }
    ]
  }
}

datamodel.graphql

type User {
 friends: [User!]!
}

schema.graphql

type User {
 friends: [User]!
}

Here’s my resolver but since the issue is at prisma.io playground also I don’t think its a flaw here causing it.

feed(parent, { id }, ctx, info) {

      const queryId = id ? id : getUserId(ctx)
      return ctx.db.query.posts(
        { where: {
          OR: [
            { author: { id: queryId }},
            { author: { friends_some: { id: queryId }}}
          ]
        }, orderBy: 'createdAt_DESC'}, info
      )
  },

#2

I am not sure if I see where the problem is, can you spell that out for me explicitely? :slight_smile:


#3

The problem is that even tho the users are friends, only 1 of them can see the posts.
I might have forgot that part in the original post.


#4

I see! There is a change about the behaviour for single field self-relations in 1.10-beta.

Quote from the PR (emphasis mine):

Before the change we interpreted this as a special case of a symmetric relationship. Connecting A2 to A1’s a field would mean that both nodes are connected to each other over their respective field a.

Now this schema is interpreted as a relation without a backrelationfield. Connecting A2 to A’s a field will set the relation, but it is then not possible to access A from A2 since there is no back relation.

What’s the version you’re currently on?


#5

prisma/1.9.0 (windows-x64) node-v9.7.1


#6

Can you try this out with the 1.10-beta version? :slight_smile: