Nativescript-vue graphql backend?

我是研究僧i 提交于 2020-07-19 08:47:13

问题


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:


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



来源:https://stackoverflow.com/questions/56122341/nativescript-vue-graphql-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!