change structure apis

pull/1/head
saeid_01 5 years ago
parent f2c43ebaf1
commit ac32a232e9

25
package-lock.json generated

@ -1299,6 +1299,22 @@
"normalize-path": "2.1.1"
}
},
"apollo-boost": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/apollo-boost/-/apollo-boost-0.4.3.tgz",
"integrity": "sha512-XE7hx4aXRnyZ4OGM8I7DjYq9SYLYWrVBoYpEFsv0GBtfIl6tipyks2Yo2/TEWKw7mhGmi1eFB2F3pbhIZbzKuQ==",
"requires": {
"apollo-cache": "1.3.2",
"apollo-cache-inmemory": "1.6.2",
"apollo-client": "2.6.3",
"apollo-link": "1.2.12",
"apollo-link-error": "1.1.11",
"apollo-link-http": "1.5.15",
"graphql-tag": "2.10.1",
"ts-invariant": "0.4.4",
"tslib": "1.9.3"
}
},
"apollo-cache": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/apollo-cache/-/apollo-cache-1.3.2.tgz",
@ -1346,12 +1362,13 @@
"zen-observable-ts": "0.8.19"
}
},
"apollo-link-context": {
"version": "1.0.18",
"resolved": "https://registry.npmjs.org/apollo-link-context/-/apollo-link-context-1.0.18.tgz",
"integrity": "sha512-aG5cbUp1zqOHHQjAJXG7n/izeMQ6LApd/whEF5z6qZp5ATvcyfSNkCfy3KRJMMZZ3iNfVTs6jF+IUA8Zvf+zeg==",
"apollo-link-error": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/apollo-link-error/-/apollo-link-error-1.1.11.tgz",
"integrity": "sha512-442DNqn3CNRikDaenMMkoDmCRmkoUx/XyUMlRTZBEFdTw3FYPQLsmDO3hzzC4doY5/BHcn9/jdYh9EeLx4HPsA==",
"requires": {
"apollo-link": "1.2.12",
"apollo-link-http-common": "0.2.14",
"tslib": "1.9.3"
}
},

@ -12,11 +12,8 @@
"dependencies": {
"@fortawesome/fontawesome-free": "^5.5.0",
"ajv": "^6.10.0",
"apollo-boost": "^0.4.3",
"apollo-cache-inmemory": "^1.6.2",
"apollo-client": "^2.6.3",
"apollo-link": "^1.2.12",
"apollo-link-context": "^1.0.18",
"apollo-link-http": "^1.5.15",
"axios": "^0.18.0",
"bootstrap": "^4.1.3",
"bootstrap-select": "^1.13.3",

@ -1,6 +1,6 @@
{
"/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=e11c94b631fa8e23411d",
"/js/vue/Home/app.js": "/js/vue/Home/app.js?id=8a41fb4476589b3a6cff",
"/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=26118082661767a7bdc6",
"/js/vue/User/app.js": "/js/vue/User/app.js?id=4d34a4ac917830fbaa36"
"/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=ada36e14123738cce4a1",
"/js/vue/Home/app.js": "/js/vue/Home/app.js?id=4389447314d810908e49",
"/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=24bffeddf17eab24a833",
"/js/vue/User/app.js": "/js/vue/User/app.js?id=32e40e7920eba25a4bb2"
}

@ -1,6 +1,5 @@
import axiosApi from '@Global/utils/api/factory/axios/axiosApi'
import apolloApi from '@Global/utils/api/factory/apollo/apolloApi'
import apiHandler from '@Global/utils/api/apiHandler'
import axiosApi from '@Global/utils/api/request/axiosApi'
import apolloApi from '@Global/utils/api/request/apolloApi'
export const api = (url) => {
let apiClass;
@ -12,8 +11,7 @@ export const api = (url) => {
throw 'parameter "' + url['type'] + '" must be axios or apollo.';
}
let APIHandler = new apiHandler();
return APIHandler.request(apiClass);
return apiClass.init();
}
export default {

@ -1,7 +0,0 @@
export default class apiHandler {
request(apiMethod) {
return apiMethod.Handle();
}
}

@ -1,18 +0,0 @@
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import VueApollo from 'vue-apollo'
const httpLink = new HttpLink({
// URL to graphql server, you should use an absolute URL here
uri: '/graphql'
})
// create the apollo client
const apolloClient = new ApolloClient({
link: httpLink,
cache: new InMemoryCache()
})
// install the vue plugin
Vue.use(VueApollo)

@ -1,7 +0,0 @@
export default class apiFactory {
Handle() {
return this.init();
}
}

@ -0,0 +1,7 @@
import ApolloClient from 'apollo-boost'
import { InMemoryCache } from "apollo-cache-inmemory";
export default new ApolloClient({
uri: '/graphql',
cache: new InMemoryCache()
});

@ -1,9 +1,8 @@
import apiFactory from "../apiFactory";
import apollo from "@Global/utils/api/init/apollo";
export default class apolloApi extends apiFactory {
export default class apolloApi {
constructor(urlObj) {
super();
this.staticMethods = ["query", "mutations"];
this.method = urlObj.method;
@ -24,6 +23,7 @@ export default class apolloApi extends apiFactory {
query() {
const query = this.gql;
const variables = this.variables;
return apollo.query({
query,
variables

@ -1,11 +1,10 @@
import apiFactory from "../apiFactory";
import axios from "axios";
export default class axiosApi extends apiFactory {
export default class axiosApi {
constructor(urlObj) {
super();
this.staticMethods = ["get", "post", "put", "delete"];
this.baseURL = '/';
this.method = urlObj.method;
this.url = urlObj.url;
@ -13,6 +12,8 @@ export default class axiosApi extends apiFactory {
}
init() {
axios.defaults.baseURL = this.baseURL;
if (this.checkMethod()) {
return this[this.method]();
}
Loading…
Cancel
Save