0

I am trying to get a cursor for a post given the postId but in return I am getting cursors of all posts. Note that this query works fine when I hardcode the id into the query.

query:

export const GET_POST_CURSOR = gql `
  query GetPostById($id: Int) {
    posts(where: {id: $id}) {
      edges {
        cursor
      }
      
    }
  }
`;

React

let postId = 138
const postCursor = useQuery(GET_POST_CURSOR, {variables: {postId}}) 
  
  if (!postCursor.loading) { 
    console.log("cursor: ", postCursor)
  }
sash
  • 101
  • 7

1 Answers1

0

React

let postId = 138;
const postCursor = useQuery(GET_POST_CURSOR, {variables: {id: postId}}) 
TBR_Yu
  • 71
  • 6
  • what do you mean? – sash Jun 07 '23 at 01:56
  • the gql filter data by `id`. set the variables like this `{variables: {postId}}` means the gql receives `postId` not `id`, you need to change to `{variables: {id: postId}}` – TBR_Yu Jun 07 '23 at 02:03