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?
-
1I tried using Apollo with NS-Vue, there was some issue. But, It's working with axios.Lucifer– Lucifer2019-05-14 05:14:14 +00:00Commented May 14, 2019 at 5:14
Add a comment
|
1 Answer
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:
3 Comments
Sebastian Roy
Thanks, now I still need to get websockets for subscriptions to work. Any idea/repos?
Cem Kaan
I can suggest using
tns debug android --no-hmr . Most errors were not nativescript-vue related vue-apollo.netlify.com/guide/apollo/subscriptions.html#setupSebastian Roy
That didn't do it, I asked a separate question with the issue stackoverflow.com/questions/62357603/…