flutter应用中的店面api shopify(“节点”'nodes; amp;;

发布于 2025-02-06 21:52:22 字数 1389 浏览 0 评论 0原文

我的需求很简单。

我想使用Flutter查询Shopify的店面API,但是有一个捕获。

我的回答总是有多个节点和边缘。每个节点/边缘包含不同的对象。

现在,当我尝试在Android Studio中使用Jsontodart Generator并使用自己的模型创建每个类时,就会出现问题。包含不同的字段,它与其他节点类冲突。

屏幕截图附加了参考。 我想知道如何解决这个问题。

我的GraphQl查询是:

{
  products(first: 2) {
    nodes {
      id
      title
  createdAt
  description
  descriptionHtml
  featuredImage {
    id
    url
    width
    height
    altText
  }
  onlineStoreUrl
  options {
    id
    name
    values
  }
  priceRange {
    maxVariantPrice {
      amount
      currencyCode
    }
    minVariantPrice {
      amount
      currencyCode
    }
  }
  productType
  publishedAt
  requiresSellingPlan
  seo {
    title
    description
  }
  tags
  totalInventory
  updatedAt
  vendor
  images(first: 2) {
    nodes {
      id
      url
      width
      height
      altText
    }
  }
  media(first: 2) {
    nodes {
      alt
      mediaContentType
    }
  }
  variants(first: 2) {
    nodes {
      availableForSale
      barcode
      id
      image {
        id
        url
        width
        height
        altText
      }
      requiresShipping
      sku
      title
      weight
      weightUnit
    }
  }
}

} }

My need is very simple.

I want to query Shopify's Storefront api using Flutter, but there is a catch.

My response always have multiple nodes and edges. and each node/edge containing different objects.

Now the problem arise when i try to use JsonToDart generator in android studio and it creates each class with its own model. containing different fields and it conflicts with the other Node class.

screenshot is attached for reference.
i want to know how i can tackle this problem.

my graphQL query is:

{
  products(first: 2) {
    nodes {
      id
      title
  createdAt
  description
  descriptionHtml
  featuredImage {
    id
    url
    width
    height
    altText
  }
  onlineStoreUrl
  options {
    id
    name
    values
  }
  priceRange {
    maxVariantPrice {
      amount
      currencyCode
    }
    minVariantPrice {
      amount
      currencyCode
    }
  }
  productType
  publishedAt
  requiresSellingPlan
  seo {
    title
    description
  }
  tags
  totalInventory
  updatedAt
  vendor
  images(first: 2) {
    nodes {
      id
      url
      width
      height
      altText
    }
  }
  media(first: 2) {
    nodes {
      alt
      mediaContentType
    }
  }
  variants(first: 2) {
    nodes {
      availableForSale
      barcode
      id
      image {
        id
        url
        width
        height
        altText
      }
      requiresShipping
      sku
      title
      weight
      weightUnit
    }
  }
}

}
}

enter image description here

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

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

发布评论

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

评论(1

彩虹直至黑白 2025-02-13 21:52:22

您不应以相同的方式使用多个类别,这会在您的代码中造成混乱,如果出于任何原因,则必须在不同的文件中定义它们,并且每当您将它们导入某个地方时,您都必须选择正确的文件才能导入它来自

You shouldn't have multiple classes called the same way, this creates confusion in your code, and if for any reason you do, they have to be defined in different files and whenever you import them somewhere you have to pick the right file to import it from

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文