簡體   English   中英

如何在 Graphql 查詢中傳遞唯一 ID

[英]How to pass Unique Id in Graphql query

I'm trying to pass a unique id to graphql query to get all data against the id. But when I print the console it shows undefined. Note that if I want to see all posts the then it becomes successful by another query.

在我的 query.js 文件中,我寫了下面的查詢:

export const  Unique_Post_Query= gql`
  query SampleQueries($id: ID!) {
      
    post(_id: $id) {
        id
        data {
          title
          body {
            text
          }
        }
      } 
  }
  `;

以及我試圖查看查詢結果的另一個文件中的以下代碼:

 const id='e42fd2b5-b84a-4417-afd2-36cdbaa204dd';
      const {  data , error,loading} = useQuery(Unique_Post_Query, { variables: {id ,},  });
      //const { error, loading, data } = useQuery(PROFILE_QUERY);
      
      console.log('yourrrrr f data',data);

請檢查以下參考

const id='e42fd2b5-b84a-4417-afd2-36cdbaa204dd';

const { loading, data } = useQuery(Unique_Post_Query, {
    variables: { id: id},
  });

useEffect(() => {
    if (data && data?.post) {
       console.log("data: ", data?.post);
    }
}, [data]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM