2

Just started to experiment with nativescript-vue. Since it's pretty new, can't seem find good documentation on nativescript-vue integration with graphql. Tried vue-apollo, but can't install. When I do vue add apollo, it errors out. Is there any good docs on how to integrate nativescript-vue with graphql backend or more specifically via apollo?

1
  • 1
    I tried using Apollo with NS-Vue, there was some issue. But, It's working with axios. Commented May 14, 2019 at 5:14

1 Answer 1

2

I want to confirm that nativescript-vue is working properly with vue-apollo.

You should first install apollo-boost using npm or yarn

yarn add vue-apollo graphql apollo-boost

main.ts

import Vue from "nativescript-vue";
import routes from "./routes";
import store from "./store";
import * as ApplicationSettings from "tns-core-modules/application-settings";

import VueApollo from "vue-apollo";
import ApolloClient from "apollo-boost";

// GET TOKEN and Prepare for header bearer
const tokenInAppSet = ApplicationSettings.getString("token")
    ? ApplicationSettings.getString("token").replace(/['"]+/g, "")
    : false;

/////////////// APOLLO 
export const defaultClient = new ApolloClient({
    uri: "http://000.com/graphql",
    headers: {
        authorization: `Bearer ${tokenInAppSet}`,
    }
});

Vue.use(VueApollo);
const apolloProvider = new VueApollo({
    defaultClient,
});

new Vue({
    store,
    apolloProvider,
    render: (h) =>
        h("frame", [h(tokenInAppSet ? routes.entered : routes.login)]),
}).$start();

If you want to see some installed version.

Vue-Apollo with Nativescript examples:

https://github.com/kaanguru/apollo-jwt

https://github.com/kaanguru/simple-question

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, now I still need to get websockets for subscriptions to work. Any idea/repos?
I can suggest using tns debug android --no-hmr . Most errors were not nativescript-vue related vue-apollo.netlify.com/guide/apollo/subscriptions.html#setup
That didn't do it, I asked a separate question with the issue stackoverflow.com/questions/62357603/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.