0

I'm setting up my graphql client using Appolo-vue. I passed my authorization token in my http headers but i get 200 ok status code but did not get back any data.

I'm setting up my graphql client using Appolo-vue. I passed my authorization token in my http headers but i get 200 ok status code but did not get back any data.

here is my main.js code.

import App from './App.vue'
import router from './router'
import store from './store/store'
import './registerServiceWorker'

import axios from 'axios'
import VueProgressBar from 'vue-progressbar'

import VueSVGIcon from 'vue-svgicon'
import 'uikit/dist/js/uikit.js'
import 'uikit/dist/js/uikit-icons.js'
import './custom-icons'
//uikit css and javascript

import VueContentPlaceholders from 'vue-content-placeholders'

Vue.use(VueContentPlaceholders)
import './theme/theme.less'

Vue.use(VueSVGIcon)
Vue.prototype.$http = axios

const options = {
  color: '#21D397',
  failedColor: '#874b4b',
  thickness: '8px',
  transition: {
    speed: '0.2s',
    opacity: '0.6s',
    termination: 300
  },
  autoRevert: true,
  location: 'top',
  inverse: false
}
import VueApollo from 'vue-apollo'
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { setContext } from 'apollo-link-context';


// Cache implementation
const cache = new InMemoryCache()


// HTTP connection to the API
const httpLink = createHttpLink({
  // You should use an absolute URL here
  uri: 'http://127.0.0.1:8000/',


})


// Create a new Middleware Link using setContext

const authLink = setContext((_, { headers }) => {
  // get the authentication token from local storage if it exists
  const token = localStorage.getItem('token');
  // return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : "",

    }
  }
});

//  const token = localStorage.getItem('token');
// const authLink = setContext(() => ({
//   headers: {
//     authorization: `Bearer ${token}`
//   }
// }));


// Change your link assignment from
// const link = httpLink;
// to
// Create the apollo client
const apolloClient = new ApolloClient({
  link: authLink.concat(httpLink),
  cache,
  connectToDevTools: true
})

const apolloProvider = new VueApollo({
  defaultClient: apolloClient,

})



Vue.use(VueApollo)
Vue.use(VueProgressBar, options)


Vue.config.productionTip = false

new Vue({
  router,
  store,
  apolloProvider,
  render: h => h(App)
}).$mount('#app')

i get a 200 status ok in my console. but i get GraphQL execution errors for query 'profile'

Udemezue John
  • 128
  • 2
  • 12
  • Your main.js code look good, but you should provide information about your graphql query for 'profile'. Here we cannot help you. – ManUtopiK Aug 26 '19 at 09:10
  • here is the error i get from my console. export const USER_PROFILE = gql` { account { id fullName email profile { id username avatar country status location coverPhoto } } skills { id skill level } certifications { id organization yearObtained } posts { id text photo createdAt } } `; – Udemezue John Aug 26 '19 at 23:01
  • I get a 200 ok but my data refuses to render...it asks me to authenticate... after which i have sent the authorization token along with the request in my headers – Udemezue John Aug 26 '19 at 23:54

0 Answers0