Im having problem querying wix studio with groaphql

Question:
im having issues querying my wix studio with graphql

Product:
Wix Studio Editor

What are you trying to achieve:

export async function fetchAllProducts() {
	try {
		const { data, errors } = await wix.graphql(
			`
      query {
     Products(queryInput: {}) {
          items {
            name
          }
        }
      }
    `
		);

		if (errors) {
			console.error("GraphQL errors:", errors);
			return [];
		}

		console.log("Fetched data:", data); // Debugging log to inspect the structure

		// Adjust the path to the items array if necessary
		if (
			!data ||
			!data.storesProductsV1Products ||
			!data.storesProductsV1Products.items
		) {
			console.error("Unexpected response structure:", data);
			return [];
		}

		return data.storesProductsV1Products.items;
	} catch (error) {
		console.error("Error fetching products:", error);
		return [];
	}
}

Hey @Hussain_Yusuf!

Saw you mentioned you’re using this within the Wix Studio Editor.

I’ll share the link here for the Wix GraphQL docs - GraphQL API Reference | Wix Docs

But, perhaps Velo is what you’re looking for - Introduction - Velo API Reference - Wix.com

Velo is Wix JavaScript-based development platform and is the platform used within the Studio and Wix editors.

Hope this helps :slight_smile: