Apollo-module: Validate GraphQL response before render

Created on 9 Oct 2017  路  2Comments  路  Source: nuxt-community/apollo-module

Hello, thanks for module!

I have a question: is there a way to validate apollo response before render?

I have a page /pages/users/_username.vue and I want to render proper Not Found page along with 404 status code if username is not found (when graphql returns null).

Currently I have to something like this:

<template>
  <div>
    <div v-if="user">
      <h1>{{user.fullName}}</h1>
    </div>
    <div v-else >
      User is not found :(
    </div>
  </div>
</template>

It'd be great to handle graphql response in the same way nuxt's validate hook works.

This question is available on Nuxt.js community (#c28)

All 2 comments

@minibikini how about redirect the user with

apollo:{
  user:{
    query:UserQueryGql,
    result({data}){
      if(!data){
        this.$router.push('/404') // redirect if data not found
       }
     }
  }
}

I will close this issue due to inactivity. Personally I think its part of vue-apollo rather than this repo to provide guidance on your issue. Maybe you can even make use of Nuxt validate functionality

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanielLourie picture DanielLourie  路  4Comments

Billybobbonnet picture Billybobbonnet  路  4Comments

gbouteiller picture gbouteiller  路  6Comments

drewbaker picture drewbaker  路  6Comments

gomezmark picture gomezmark  路  9Comments