我该如何查询一对一的关系查询aws

发布于 2025-01-31 07:54:53 字数 1185 浏览 4 评论 0原文

如何从客户端从屏幕截图中进行此查询。

这是我尝试进行查询的方式,但是我不知道该怎么做,

const CategoriesProducts = async ()=>{
const fetchData = await API.graphql({
    query: listProductCategories, variables: {id: '1cb76030-0ee0-432a-b3ee-4087d33eaaf3'}
})
setCategoryProduct(fetchData.data.listProductCategories.items)}

这是我的架构

“

”查询

这是ListProductCategories查询

“在此处输入图像说明”

当我在TE AWS Console中进行查询时,我获得了结果,但是我无法在Visual Studio Code中执行相同的查询

谢谢您的支持

how can i make this query in the screenshot from the client side.
this is the query i want to perform.

this is how i tried to do the query, but i don't know what to do next

const CategoriesProducts = async ()=>{
const fetchData = await API.graphql({
    query: listProductCategories, variables: {id: '1cb76030-0ee0-432a-b3ee-4087d33eaaf3'}
})
setCategoryProduct(fetchData.data.listProductCategories.items)}

this is my schema

enter image description here

and this is the getProductCategories queries

enter image description here

and this is the listProductCategories queries

enter image description here

i get the result when i make the query in te aws console, but i can't perform the same query in visual studio code

thank you for your support

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偷得浮生 2025-02-07 07:54:53

在您的GraphQL目录中由AWS-CLI自动生成,创建新文件,casure-ceries.js

- graphql/
  - mutations.js
  - subscriptions.js
  - queries.js
  - custom-queries.js << Create this new file

定义以下自定义gruber graphql查询code> code> code-queries.js

 export const ListProductCategoriesByCategoryId = /* Graphql */ `
    query listProductCategories(
      $filter = ModelProductCategoryFilterInput
       ){
         listProductCategories( filter : $filter) {
           items {
              product {
                        price
                        image
                        id
                        title
                      }
                }
          }
        }
    `;

现在您应该能够在代码中导入list ProductCategoriesByCategoryId ,并以此为单位:

   import { API, graphqlOperation } from 'aws-amplify';
   import { ListProductCategoriesByCategoryId } from '../custom-queries.js';
.
.
.
   const fetchData = await API.graphql(
    graphqlOperation(
     ListProductCategoriesByCategoryId, 
           { filter : { categoryID : { eq : "1cb76....." }}
     )
   );
   console.log(fetchData);

In your graphql directory auto-generated by aws-cli, create new file, custom-queries.js :

- graphql/
  - mutations.js
  - subscriptions.js
  - queries.js
  - custom-queries.js << Create this new file

define the following custom graphql query inside custom-queries.js :

 export const ListProductCategoriesByCategoryId = /* Graphql */ `
    query listProductCategories(
      $filter = ModelProductCategoryFilterInput
       ){
         listProductCategories( filter : $filter) {
           items {
              product {
                        price
                        image
                        id
                        title
                      }
                }
          }
        }
    `;

Now you should be able to import ListProductCategoriesByCategoryId in your code and call it like this :

   import { API, graphqlOperation } from 'aws-amplify';
   import { ListProductCategoriesByCategoryId } from '../custom-queries.js';
.
.
.
   const fetchData = await API.graphql(
    graphqlOperation(
     ListProductCategoriesByCategoryId, 
           { filter : { categoryID : { eq : "1cb76....." }}
     )
   );
   console.log(fetchData);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文