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

computed attribute not updating after query runs, when using manual: false #1368

Closed
twelve17 opened this issue Jun 9, 2022 · 1 comment
Closed

Comments

@twelve17
Copy link

twelve17 commented Jun 9, 2022

Given this option API reactive query:

  apollo: {
    message: {
      query,
      variables: { id: 1 },
    },
  },

And this computed property, which references the above reactive query property:

  computed: {
   messageSubstr() {
     return this.message?.text?.substr(0, 2);
   },
 },

The messageSubstr property does not seem to be called when the query is complete.

However, if manual is set to true and a result function is added to simply update the reactive property presumably as it would have been done via the automatic mode, then the computed property does get called:

      manual: true,
      result ({ data }, key) {
        this[key] = data.message;
      },

To Reproduce

I have created a minimal app in this code sandbox:

https://codesandbox.io/s/apollo-vue-computed-reactivity-8co7ec

Note that I ran into this issue in the sandbox, which required frequent manual reloading.

Alternatively, you can use this copy to run locally

  1. Clone https://github.com/twelve17/avue
  2. run yarn install, then npm run serve
  3. Navigate to http://localhost:8080/

Tested with node v14.19.2, yarn 1.22.18.

Expected behavior

In the UI, both the apollo reactive property (message) is printed, and a contrived computed property as well (messageSubstr, which just does message.substr(0, 2)).

The messageSubStr computed property should be "He", e.g. the substring of "Hello World".

Actual Results

If manual = false, messageSubStr does not change from its initial (undefined) value.

If manual = true and a result callback is implemented, the expected behavior is achieved.

Versions
vue: 3.2.33
vue-apollo: @vue/[email protected]
@apollo/client: 3.6.6

(Note that for the sandbox version of the app, graphql 17.0.0-alpha1 is used, due to issues running older versions in the sandbox. graphql 16.5.0 is used in the github version.

Additional context

@Akryum
Copy link
Member

Akryum commented Jul 18, 2022

I don't see the issue anymore using alpha 18 in your repro codesandbox :)

@Akryum Akryum closed this as completed Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants