Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataStore.observequery does not return nested belongsTo fields, but DataStore.query does. #10211

Closed
3 tasks done
AlexChaseJones opened this issue Aug 15, 2022 · 4 comments
Closed
3 tasks done
Labels
DataStore Related to DataStore category Expo For issues where expo is in use React Native React Native related issue

Comments

@AlexChaseJones
Copy link

AlexChaseJones commented Aug 15, 2022

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

DataStore

Amplify Categories

api

Environment information

# Put output below this line
  System:
    OS: macOS 12.2.1
    CPU: (10) x64 Apple M1 Pro
    Memory: 38.94 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.19.0 - ~/.nvm/versions/node/v14.19.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.19.0/bin/yarn
    npm: 6.14.16 - ~/.nvm/versions/node/v14.19.0/bin/npm
    Watchman: 2022.07.04.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 104.0.5112.79
    Safari: 15.3
  npmPackages:
    @babel/core: ^7.12.9 => 7.18.10 
    @react-native-async-storage/async-storage: ^1.17.7 => 1.17.8 
    @react-native-community/netinfo: ^9.3.0 => 9.3.0 
    @react-navigation/bottom-tabs: ^6.3.2 => 6.3.2 
    @react-navigation/drawer: ^6.4.3 => 6.4.3 
    @react-navigation/material-top-tabs: ^6.2.2 => 6.2.2 
    @react-navigation/native: ^6.0.11 => 6.0.11 
    @react-navigation/stack: ^6.2.2 => 6.2.2 
    HelloWorld:  0.0.1 
    aws-amplify: ^4.3.30 => 4.3.30 
    axios: ^0.27.2 => 0.27.2 (0.26.0)
    example:  0.0.1 
    expo: ^45.0.8 => 45.0.8 
    expo-image-manipulator: ~10.3.1 => 10.3.1 
    expo-image-picker: ~13.1.1 => 13.1.1 
    expo-image-picker-multiple: git+https://github.com/NickRance/expo-image-picker-multiple.git => 1.4.1 
    expo-media-library: ^14.2.0 => 14.2.0 
    expo-status-bar: ~1.3.0 => 1.3.0 
    expo-updates: ^0.13.4 => 0.13.4 
    hermes-inspector-msggen:  1.0.0 
    i: ^0.3.7 => 0.3.7 
    ini: ^1.3.5 => 1.3.8 
    inquirer: ^6.5.1 => 6.5.2 
    react: ^17.0.2 => 17.0.2 
    react-dom: 17.0.2 => 17.0.2 
    react-native: ^0.68.2 => 0.68.3 
    react-native-collapsible-tab-view: ^4.5.2 => 4.5.2 
    react-native-gesture-handler: ~2.2.1 => 2.2.1 
    react-native-image-viewing: ^0.2.2 => 0.2.2 
    react-native-loading-spinner-overlay: ^3.0.1 => 3.0.1 
    react-native-pager-view: ^5.4.25 => 5.4.25 
    react-native-radio-buttons-group: ^2.2.11 => 2.2.11 
    react-native-reanimated: ~2.8.0 => 2.8.0 
    react-native-safe-area-context: ^4.3.1 => 4.3.1 
    react-native-search-filter: ^0.1.5 => 0.1.5 
    react-native-snap-carousel: ^3.9.1 => 3.9.1 
    react-native-swipe-gestures: ^1.0.5 => 1.0.5 
    react-native-tab-view: ^3.1.1 => 3.1.1 
    react-native-web: 0.17.7 => 0.17.7 
    typescript: ^4.7.4 => 4.7.4 
  npmGlobalPackages:
    bspeasy: 2.2.3
    corepack: 0.10.0
    expo-cli: 5.4.12
    fony: 1.1.0
    node-gyp: 9.0.0
    nodemon: 2.0.19
    npm: 6.14.16
    serverless: 3.16.0
    webpack-cli: 4.9.2
    webpack: 5.70.0
    yarn: 1.22.19

Describe the bug

DataStore.observequery is not returning belongsto items.

Expected behavior

I expect the belongsto (message) field to be populated in the observequery response, as it is in the query response.

Reproduction steps

My (relevant) models look like this:

type Message @model @auth(rules: [{allow: public}]) {
  id: ID!
  subject: String!
  content: String!
  contentType: String!
  MessageRecipients: [MessageRecipient] @hasMany(indexName: "byMessage", fields: ["id"])
}

type MessageRecipient @model @auth(rules: [{allow: public}]) {
  id: ID!
  isRead: Boolean!
  usergroupID: ID @index(name: "byUserGroup")
  messageID: ID! @index(name: "byMessage")
  message: Message @belongsTo(fields: ["messageID"])
}

If i run this query

DataStore.query(
  MessageRecipient,
  m => m.usergroupID('eq', loggedInUserGroupId)
).then((items) => {
  console.log('query results: ', items)
})

I get this response

query results:  Array [
  MessageRecipient {
    "_deleted": null,
    "_lastChangedAt": 1660588574065,
    "_version": 1,
    "createdAt": "2022-08-15T18:36:14.035Z",
    "id": "c528324c-17f2-469d-9d8c-bee4c7e59272",
    "isRead": false,
    "message": Message {
      "_deleted": null,
      "_lastChangedAt": 1660588573834,
      "_version": 1,
      "content": "test content",
      "contentType": "text",
      "createdAt": "2022-08-15T18:36:13.811Z",
      "id": "70db748f-2ba6-420a-a996-d9c381f82b45",
      "subject": "-",
      "updatedAt": "2022-08-15T18:36:13.811Z",
    },
    "updatedAt": "2022-08-15T18:36:14.035Z",
    "usergroupID": "08a6e978-9946-4b6e-83d2-b4d975fbcd3e",
  }
]

but with observequery: (same filter, same model)

DataStore.observeQuery(
  MessageRecipient,
  m => m.usergroupID('eq', loggedInUserGroupId)
).subscribe(({items}) => {
  console.log('subscribe results', items) 
});

I get this response:

subscribe results: Array [
    MessageRecipient {
      "_deleted": null,
      "_lastChangedAt": 1660588574065,
      "_version": 1,
      "createdAt": "2022-08-15T18:36:14.035Z",
      "id": "c528324c-17f2-469d-9d8c-bee4c7e59272",
      "isRead": false,
      "messageID": "70db748f-2ba6-420a-a996-d9c381f82b45",
      "updatedAt": "2022-08-15T18:36:14.035Z",
      "usergroupID": "08a6e978-9946-4b6e-83d2-b4d975fbcd3e",
    }
]

Am i doing something wrong? or is this expected behavior?

oddly, if I query first then run observequery, the response has the belongsto messages. But any subsequent messageRecipients created that trigger the observequery listener do not have the belongsto message reference.

@AlexChaseJones AlexChaseJones changed the title DataStore.observequery does not return nested belongTo fields, but DataStore.query does. DataStore.observequery does not return nested belongsTo fields, but DataStore.query does. Aug 15, 2022
@AlexChaseJones
Copy link
Author

AlexChaseJones commented Aug 15, 2022

It seems that observequery for some reason doesn't have a reference to the message in the messageID field. But I save the Message (using DataStore.save) before creating the MessageRecipient object:

const messageObj = await DataStore.save(
  new Message(message)
);

await DataStore.save(
  new MessageRecipient({
    isRead: false,
    message: messageObj,
    messageID: messageObj.id,
    usergroupID
  })
)

So i'm not sure why it wouldn't

@AlexChaseJones
Copy link
Author

AlexChaseJones commented Aug 15, 2022

this other issue seems related, but it was for amplify-flutter and seems to be resolved: aws-amplify/amplify-flutter#943. and one for amplify-android: aws-amplify/amplify-android#1566

@chrisbonifacio
Copy link
Member

Possibly related: #9682

@nadetastic nadetastic added the Expo For issues where expo is in use label Feb 8, 2023
@dpilch
Copy link
Member

dpilch commented Feb 16, 2023

I'm not able to reproduce this. It may have been incidentally fixed with the lazy loading change. Please comment if you are still experiencing this issue.

@dpilch dpilch closed this as completed Feb 16, 2023
@chrisbonifacio chrisbonifacio removed the pending-triage Issue is pending triage label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataStore Related to DataStore category Expo For issues where expo is in use React Native React Native related issue
Projects
None yet
Development

No branches or pull requests

4 participants