1

Hi im Using GraphCms to use GraphQl API and when i try to use data of image.url i get null or a void string. I check and the assets are published.
this my react code:

i get this error on console: {"errors":[{"message":"input:1: Field \"image\" of type \"Asset!\" must have a selection of subfields. Did you mean \"image { ... }\"?\n"}],"data":null,"extensions":{"requestId":"cl5lie2g17tgn0blzlvcey8mb"}}

import { useGetProductsQuery } from "../../graphql/generated";
import { Product } from "../Product/Product";

export function Products() {
  const { data } = useGetProductsQuery()
  return (
    <article className="h-[40rem] text-center" id="products">
      <h2 className="text-3xl pt-2 pb-7">Produtos</h2>

    <div className="flex flex-wrap lg:flex-nowrap justify-center lg:gap-7 lg:p-5  sm:gap-7 gap-10">

  
  
  {data?.products.map(product  => {

    return (
      <>
        <Product key={product.id} id={product.id} name={product.name} price={product.price} pricecent={product.pricecent} image={product.image.url} slug={product.slug} />
        <button onClick={() => console.log(product.image.url)}>check error</button>
      </>
      
    )
    })}
  </div>
</article>

) }

The query:

query GetProducts {
    products {
        id
        name
        price
        pricecent
        slug
        image {
            url
        }
    }
}

Its all Published

1 Answers1

3

in GraphCMS you must be sure sure that you publish both content and assets. Please check the assets were published in the assets tab