Code Monkey home page Code Monkey logo

Comments (14)

Akryum avatar Akryum commented on April 27, 2024 5

Implemented in release 1.2.0.

from apollo.

Akryum avatar Akryum commented on April 27, 2024 3

Or maybe:

export default {
  ...
  apollo: {
    user: {
      query: FETCH_CURRENT_USER,
      skip() {
        return !this.isAuthenticated
      },
      // Or default value
      skip: false,
      ...
    }
  },
  methods: {
    disableUserQuery() {
      // Change skip value
      this.$apollo.queries.user.skip = true
    },
  },
}

The last part is about controlling the apollo query programmatically if needed.

from apollo.

gustawdaniel avatar gustawdaniel commented on April 27, 2024 3

In release note there is no comments about it

https://github.com/Akryum/vue-apollo/releases/tag/1.2.0

There is issue

#395

In documentation

https://vue-apollo.netlify.com/guide/apollo/special-options.html#skip-all

only skipAll is presented.

I spend some time to find proper usage example and I can't so there is

        apollo: {
            me: {
                skip: !isUerLoggedIn(),
                query: gql`query {
                  me { id name rating numberOfGrades }
                }`
            }
        },

Example like this could be placed on page because of there is only skipAll with $ sign.

https://vue-apollo.netlify.com/guide/apollo/special-options.html#skip-all

from apollo.

Rick-McClatchie avatar Rick-McClatchie commented on April 27, 2024 2

Hey everyone,

is the skip option also available in the apollo-composable Composition API for Vue 3? It does not seem to be implemented yet. https://v4.apollo.vuejs.org/api/use-query.html#parameters

Thanks.

from apollo.

Akryum avatar Akryum commented on April 27, 2024

This is a very good idea. I'm thinking of something like this:

export default {
  ...
  apollo: {
    user: {
      query: FETCH_CURRENT_USER,
      enabled() {
        return this.isAuthenticated
      },
      ...
    }
  },
  methods: {
    disableUserQuery() {
      this.$apollo.queries.user.enabled = false
    },
  },
}

from apollo.

sircharleswatson avatar sircharleswatson commented on April 27, 2024

Would you mind explaining that a bit? It seems a little cumbersome. I'm not sure about the disableUserQuery part. And I think skip() would be better than enabled() since that is the preferred term in the apollo docs.

from apollo.

sircharleswatson avatar sircharleswatson commented on April 27, 2024

I like that! :D I think it makes sense that way and will be a great feature :D

from apollo.

sircharleswatson avatar sircharleswatson commented on April 27, 2024

@Akryum Woot! I'll try this out and let you know how it goes. Can't wait! :)

from apollo.

julia-suarez-deel avatar julia-suarez-deel commented on April 27, 2024

Hello @Rick-McClatchie I need this option too but I can't find it, I guess it's missing, should we open a new feature request? it's reaaaally useful

from apollo.

julia-suarez-deel avatar julia-suarez-deel commented on April 27, 2024

I found a way to do it with the enabled option
image

from apollo.

r3plica avatar r3plica commented on April 27, 2024

That's not working for me.
I tried this:

export function useSearch(params) {
  const { result, loading, error, fetchMore } = useQuery(search, params, {
    enabled: computed(() => !!params.value?.searchTerm),
  });
  const response = useResult(result, null, (data) => data.search);
  return { response, loading, error, fetchMore };
}

And I get an error stating: Type 'ComputedRef' is not assignable to type 'boolean'

from apollo.

noque-lind avatar noque-lind commented on April 27, 2024

Has anyone found a way to integrate the skip option into their Vue js Apollo app? We need this feature badly for async validation. Kinda crazy that there is no way to skip first query without using enabled options (which automatically calls query when changed to true).

from apollo.

strickczq avatar strickczq commented on April 27, 2024

export type OptionsParameter<TResult, TVariables> = UseQueryOptions<TResult, TVariables> | Ref<UseQueryOptions<TResult, TVariables>> | ReactiveFunction<UseQueryOptions<TResult, TVariables>>

const optionsRef = paramToReactive(options)

Since the third argument options of useQuery can receive a Ref or a ReactiveFunction, there is no need to make the option enabled can too.

Instead of making enabled reactive, we can just make the whole options reactive.

Example:

const variables = ref(something);

useQuery(
  document,
  variables,
  () => ({ enabled: !!variables.value }), // make `options` reactive
);

from apollo.

Akryum avatar Akryum commented on April 27, 2024

Example in the docs here

from apollo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.