问题
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