amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

DataStore Query not working, impossible to pull data

Open PopeSilk opened this issue 10 months ago • 1 comments

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication, GraphQL API, DataStore

Amplify Version

v6

Amplify Categories

auth, storage, api

Backend

Amplify CLI

Environment information

# Put output below this line

System:
    OS: macOS 12.7.4
    CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
    Memory: 27.46 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 20.11.1 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.2.4 - /usr/local/bin/npm
  Browsers:
    Safari: 15.6.1
  npmPackages:
    @aws-amplify/react-native: ^1.0.26 => 1.0.26 
    @aws-amplify/ui-react: ^6.1.6 => 6.1.6 
    @aws-amplify/ui-react-internal:  undefined ()
    @babel/core: ^7.20.0 => 7.23.7 
    @react-native-async-storage/async-storage: ^1.21.0 => 1.21.0 
    @react-native-community/netinfo: ^11.1.0 => 11.1.0 
    @react-native-firebase/app: ^19.0.1 => 19.0.1 
    @react-native-firebase/auth: ^19.0.1 => 19.0.1 
    @react-navigation/bottom-tabs: ^6.5.12 => 6.5.12 
    @react-navigation/drawer: ^6.6.14 => 6.6.14 
    @react-navigation/native: ^6.1.10 => 6.1.10 (3.8.4)
    @react-navigation/stack: ^6.3.21 => 6.3.21 
    @types/react: ^18.2.56 => 18.2.61 
    @types/react-native: ^0.73.0 => 0.73.0 (0.70.19)
    HelloWorld:  0.0.1 
    aws-amplify: ^6.0.25 => 6.0.25 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    deprecated-react-native-prop-types: ^5.0.0 => 5.0.0 
    expo: ^50.0.7 => 50.0.7 
    expo-location: ~16.5.5 => 16.5.5 
    expo-status-bar: ~1.11.1 => 1.11.1 
    formik: ^2.4.5 => 2.4.5 
    lodash: ^4.17.21 => 4.17.21 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.0.0 => 18.2.0 
    react-native: ^0.73.4 => 0.73.4 
    react-native-animatable: ^1.4.0 => 1.4.0 
    react-native-elements: ^3.4.3 => 3.4.3 
    react-native-gesture-handler: ~2.14.0 => 2.14.1 
    react-native-get-location: ^4.0.1 => 4.0.1 
    react-native-get-random-values: ^1.11.0 => 1.11.0 
    react-native-google-places-autocomplete: ^2.5.6 => 2.5.6 
    react-native-maps: ^1.10.0 => 1.10.0 
    react-native-safe-area-context: ^4.8.2 => 4.8.2 
    react-native-swiper: ^1.6.0 => 1.6.0 
    react-native-tab-view: ^3.5.2 => 3.5.2 
    react-native-vector-icons: ^10.0.3 => 10.0.3 
    react-native-web: ^0.19.10 => 0.19.10 
    react-navigation: ^4.4.4 => 4.4.4 
    typescript: ^5.3.3 => 5.3.3 
  npmGlobalPackages:
    @aws-amplify/cli: 12.10.3
    corepack: 0.23.0
    eas-cli: 7.6.2
    expo-cli: 6.3.10
    npm: 10.2.4
    react-native-cli: 2.0.1
    yarn: 1.22.22

Describe the bug

For some reason my queries to fetch my data based on my data models are not working. At some point i was able to read the data from one of my two schemas but for some reason it didn't last long now I'm back to fetching null datas on both schemas. My app code is up to date pulled and pushed to make sure that the data on the cloud were up to date. I don't think anything is wrong with my syntax cause if it were the case I would have never been able to even get some results on of my schemas, authentication is also good, schema data are matching on all sides so I don't get why I when i try to fetch datas I get nothing ...

Expected behavior

I just want to be able to fetch my "list of products" = data to render them on my homepage through a custom component in a flatlist

Reproduction steps

i just make my query on my homepage, datastore and the needed schemas are imported, im using a useEffect and useState, tried with async and without always get the same result

Code Snippet

// Put your code below this line.

import { DataStore } from "aws-amplify/datastore";
import { Brand, Product } from "../../../../src/models"; // Import Product model

  const [products, setProducts] = useState([]);

useEffect(() => {
    DataStore.query(Product).then(setProducts)
  }, []);

const renderProductItem = ({ item }) => (
    <TouchableOpacity
      onPress={() => handleProductPress(item)}
      style={styles.flatListContainer}
    >
      <View style={styles.itemContainer}>
        <ClothCard productData={item} onPressProductCard={handleProductPress} />
      </View>
    </TouchableOpacity>
  );

____________________ down here is my ClothCard component code for reference

import React from "react";
import { Text, View, TouchableOpacity, Image, StyleSheet, Dimensions } from "react-native";

const screenWidth = Dimensions.get("window").width;

export default function ClothCard({ productData, onPressProductCard }) {
  const { name, brandID, price, image, description } = productData;

  // Calculate the width of each card based on screen width and desired spacing
  const cardWidth = (screenWidth - 20) / 2; // Assuming 10px spacing between cards

  return (
    <TouchableOpacity onPress={() => onPressProductCard(productData)}>
      <View style={[styles.cardView, { width: cardWidth }]}>
        <Image style={styles.imageCard} source={ image } />
        <View style={styles.textBox}>
          <Text style={styles.productText}>
            {brandID} - {name}
          </Text>
          <Text style={styles.priceText}>${price}</Text>
        </View>
      </View>
    </TouchableOpacity>
  );
}


### Log output

<details>

// Put your logs below this line


</details>


### aws-exports.js

_No response_

### Manual configuration

_No response_

### Additional configuration

_No response_

### Mobile Device

_No response_

### Mobile Operating System

_No response_

### Mobile Browser

_No response_

### Mobile Browser Version

_No response_

### Additional information and screenshots

_No response_

PopeSilk avatar Apr 09 '24 22:04 PopeSilk

@PopeSilk - thanks for opening this ticket! Can you please share the following with us so we can better understand / reproduce the issue?

  1. Your schema
  2. A code snippet demonstrating how you are creating records
  3. Logs demonstrating the output of your calls to DataStore.save
  4. A code snippet demonstrating how / where you are configuring Amplify and / or DataStore?
  5. Any other relevant logging that could help us understand / reproduce the issue?

Additionally, could you try calling await DataStore.query within a try / catch block outside of useEffect (i.e. by adding a button to the page that you can use to trigger this call after the app has loaded)?

Thank you!

david-mcafee avatar Apr 15 '24 21:04 david-mcafee

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!

chrisbonifacio avatar May 23 '24 05:05 chrisbonifacio