Hi! I'm running into an issue with setting up a su...
# prisma-whats-new
b
Hi! I'm running into an issue with setting up a subscription that checks for changes to a field that references another type. For example, this subscription works fine (data is received if the "username" field is ever updated for the current user):
Copy code
subscription userPosts {
  User(
    filter: {
      updatedFields_contains: "username"
    }
  ) {
    mutation
    node {
    	posts {
        createdBy {
          name
        }
        description
        status
    	}
    }
    updatedFields
  }
}
But when I switch
updatedFields_contains
to a field that references another type (i.e. "posts" field in User type references many Posts), any updates to my Post data will not be intercepted by the subscription:
Copy code
subscription userPosts {
  User(
    filter: {
      updatedFields_contains: "posts" <----- nothing happens when Post data is updated
    }
  ) {
    mutation
    node {
    	posts {
        createdBy {
          name
        }
        description
        status
    	}
    }
    updatedFields
  }
}
Here is my User schema:
Copy code
type User implements Node {
  auth0UserId: String @isUnique
  comments: [Comment!]! @relation(name: "CommentsByUser")
  createdAt: DateTime!
  id: ID! @isUnique
  name: String!
  posts: [Post!]! @relation(name: "PostsByUser")
  updatedAt: DateTime!
  username: String
}
Is there another way to use
updatedFields_contains
with a field that references another type? Thanks!
a
@bobbyt You can't use a second subscription on Posts?
Also, what do you mean changes in 'post data'? Changes to the posts COLLECTION (so adding/removing posts), or to the posts themselves?
b
Hi @agartha yes, sorry I meant any changes to a user's posts (adding/updating/deleting) should cause the subscription to return data
a
Then you need a seperate subscription on Posts
Because the User object does not update when you update a post
So a subscription on User would never fire
Maybe creating a new post will trigger the subscription, because the posts collection is changed (did you try that?) but I doubt it...
b
Understood. I tried doing a subscription on Post, but it only returns the created/updated Post, when what I really want is something similar to allPosts:
Copy code
subscription allUserPosts {
	Post (
  	filter: {
      mutation_in: [CREATED, UPDATED, DELETED]
    }
  ) {
  	mutation
  	node {
    	description
  	}
  }
}
meaning I want every post returned, not just the single Post that was updated
a
Then you need to combine your subscription with a refetch strategy
Subscription tells you something happened, you refetch all posts if you want to
b
I'm using this in a React Native app (with Apollo) where the data returned will update a UI list component
a
The data returned should be merged into your local data store
And that should be tied to your list
Apollo has as subscribeToMore strategy
b
ok, great thanks! i will look at the example and the Apollo docs
a
yw
I read a blog earlier where subscriptions were described like this: "Relationships: Subscriptions provide a stream of nodes, but no relationships, making them promiscuous sluts that we should shame with a bell"
Someone else probably faced a similar issue to yours 😄
b
ha, nice 😆