question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onCreate subscription returns null through `aws-amplify` API, but not through AppSync

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

GraphQL API

Amplify Categories

api

Environment information

# Put output below this line
  System:
    OS: macOS 11.5.2
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 21.10 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.0.0 - ~/.nvm/versions/node/v16.0.0/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 7.19.0 - ~/.nvm/versions/node/v16.0.0/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 92.0.4515.159
    Edge: 92.0.902.78
    Firefox: 84.0.2
    Safari: 14.1.2
  npmPackages:
    @creativelayer/chalk-icons: ^1.1.2 => 1.1.2
    @creativelayer/chalk-ui: ^1.36.0 => 1.36.1
    @types/jest: ^26.0.24 => 26.0.24
    @typescript-eslint/eslint-plugin: ^4.29.3 => 4.29.3
    @typescript-eslint/parser: ^4.29.3 => 4.29.3
    @vitejs/plugin-vue: ^1.4.0 => 1.4.0
    @vue/compiler-sfc: ^3.2.4 => 3.2.4
    @vue/eslint-config-standard: ^6.1.0 => 6.1.0
    @vue/eslint-config-typescript: ^7.0.0 => 7.0.0
    @vue/test-utils: ^2.0.0-rc.12 => 2.0.0-rc.12
    @xstate/vue: ^0.8.0 => 0.8.0
    autoprefixer: ^10.3.2 => 10.3.2
    aws-amplify: ^4.2.4 => 4.2.4
    buffer: ^6.0.3 => 6.0.3 (4.9.2)
    cypress: ^8.3.0 => 8.3.0
    dynamic-import-polyfill: ^0.1.1 => 0.1.1
    eslint: ^7.32.0 => 7.32.0
    eslint-plugin-cypress: ^2.11.3 => 2.11.3
    eslint-plugin-import: ^2.24.1 => 2.24.1
    eslint-plugin-jest: ^24.4.0 => 24.4.0
    eslint-plugin-vue: ^7.16.0 => 7.16.0
    jest: ^26.6.3 => 26.6.3
    mockdate: ^3.0.5 => 3.0.5
    postcss: ^8.3.6 => 8.3.6
    tailwindcss: ^2.2.7 => 2.2.7
    ts-jest: ^26.5.5 => 26.5.6
    typescript: ^4.3.5 => 4.3.5
    vite: ^2.5.0 => 2.5.0
    vue: ^3.2.4 => 3.2.4
    vue-jest: ^5.0.0-alpha.10 => 5.0.0-alpha.10
    vue-loader: ^16.5.0 => 16.5.0
    vue-router: ^4.0.11 => 4.0.11
    vue-router-mock: 0.0.3 => 0.0.3
    xstate: ^4.23.1 => 4.23.1
  npmGlobalPackages:
    @aws-amplify/cli: 5.2.1
    np: 7.5.0
    npm: 7.19.0

Describe the bug

When subscribing to a subscription with the graphqlOperation, and not specifying any variables, the returned data is always null, whereas subscribing in AppSync to the same thing without variables does actually yield the proper result.

Expected behavior

To be able to subscribe without variables and still get data returned.

Reproduction steps

Subscribe to something like onCreateTodo without any parameters, this should fire every time a todo is created, regardless of condition.

In AppSyn the result will be correct, in Amplify it won’t:

    const subscription = API.graphql(
      graphqlOperation(subscriptions.onCreateTodo)
    ).subscribe({
      next: (data) => console.log(data),
      error: error => console.warn(error),
    })

data will be data: { onCreateBusiness: null } through API.graphql

Code Snippet

    const subscription = API.graphql(
      graphqlOperation(subscriptions.onCreateTodo)
    ).subscribe({
      next: (data) => console.log(data),
      error: error => console.warn(error),
    })

Log output

// Put your logs below this line


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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
TheDutchCodercommented, Aug 31, 2021

@chrisbonifacio Okay that seems to work now indeed, that’s good!

1reaction
TheDutchCodercommented, Aug 30, 2021

@TheDutchCoder I noticed that you have a createdAt field in your Business model. I believe AppSync handles createdAt and updatedAt automatically for you. Could you try removing that field and see if you receive the actual data from the payload then?

I think those were required to generate the proper types with codegen. I’m actually in the process of moving the whole project over to TS so hopefully that will remedy that problem.

I’ll ping you when that’s done and then we can explore this further. Appreciate the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amplify GraphQL subscriptions returns null - Stack Overflow
I just ran into this too. I get the event, but the onCreateXXX is null and I've had to similarly trace out event.value.errors...
Read more >
Build real-time multi-user experiences using GraphQL on ...
AWS Amplify is the fastest and easiest way to build cloud-powered mobile and web apps ... No ? Here is the GraphQL API...
Read more >
API (GraphQL) - Subscribe to data - JavaScript - Amplify Docs
Using Amplify GraphQL client. Subscriptions is a GraphQL feature allowing the server to send data to its clients when a specific event happens....
Read more >
Create a cloud-enabled GraphQL API with AWS Amplify and ...
By using AWS AppSync, teams can quickly create highly scalable serverless GraphQL data-driven apps for mobile and web while leaving the heavy lifting...
Read more >
GraphQL APIs with AppSync, Amplify and Angular - YouTube
AWS AppSync automatically updates the data in web and mobile applications in real time, and updates data for offline users as soon as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found