DreaMinder / nuxt-payload-extractor

Nuxt.js module that makes `nuxt generate` command to store html and payload separately.
MIT License
145 stars 18 forks source link

Any solution with Graphql? #3

Closed mishingo closed 5 years ago

mishingo commented 5 years ago

Currently the module works with an axios request but is there a pattern that allows for Apollo with graphql?

DreaMinder commented 5 years ago

@mishingo it depends on how do you use apollo. It should work if you are making apollo request inside of asyncData. But you'll need axios installed anyway. Please, share example of your page component.

mishingo commented 5 years ago

I went ahead and figured it out:

async asyncData({ $axios, $payloadURL, route, app }) {
    if (process.static && process.client) {
      return await $axios.$get($payloadURL(route))
    }
    let gqlData = await app.apolloProvider.defaultClient.query({
      query: gqlquery
    })
    return {
      gqlData
    }
  }

Great plugin! Cut my page load in half

altryne commented 5 years ago

Could this be added to documentation?

DreaMinder commented 5 years ago

@altryne added