1

I have to import a gql file based on a data or computed property but I did not find any suitable working sample to do that. Please help me if you have a method in mind.

Example:

    <script> 
        // if isEmployee is true import a file named isEmployee.gql else import isNotEmployee.gql
        export default {
            data(){
                isEmployee: true
            }
        } 
   <script>
kissu
  • 40,416
  • 14
  • 65
  • 133

1 Answers1

1

You could have a watcher, looking at your state and triggering a dynamic import. Not sure if Apollo will handle this properly tho (reactive).

watch: {
  async isEmployee() {
    const myGqlQuery = await import('~/apollo/queries/query.gql')
  },
},

Here is how to make such thing: https://stackoverflow.com/a/67825061/8816585

kissu
  • 40,416
  • 14
  • 65
  • 133