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" "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": { "apollo-cache": {
"version": "1.3.2", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/apollo-cache/-/apollo-cache-1.3.2.tgz", "resolved": "https://registry.npmjs.org/apollo-cache/-/apollo-cache-1.3.2.tgz",
@ -1346,12 +1362,13 @@
"zen-observable-ts": "0.8.19" "zen-observable-ts": "0.8.19"
} }
}, },
"apollo-link-context": { "apollo-link-error": {
"version": "1.0.18", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/apollo-link-context/-/apollo-link-context-1.0.18.tgz", "resolved": "https://registry.npmjs.org/apollo-link-error/-/apollo-link-error-1.1.11.tgz",
"integrity": "sha512-aG5cbUp1zqOHHQjAJXG7n/izeMQ6LApd/whEF5z6qZp5ATvcyfSNkCfy3KRJMMZZ3iNfVTs6jF+IUA8Zvf+zeg==", "integrity": "sha512-442DNqn3CNRikDaenMMkoDmCRmkoUx/XyUMlRTZBEFdTw3FYPQLsmDO3hzzC4doY5/BHcn9/jdYh9EeLx4HPsA==",
"requires": { "requires": {
"apollo-link": "1.2.12", "apollo-link": "1.2.12",
"apollo-link-http-common": "0.2.14",
"tslib": "1.9.3" "tslib": "1.9.3"
} }
}, },

@ -12,11 +12,8 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.5.0", "@fortawesome/fontawesome-free": "^5.5.0",
"ajv": "^6.10.0", "ajv": "^6.10.0",
"apollo-boost": "^0.4.3",
"apollo-cache-inmemory": "^1.6.2", "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", "axios": "^0.18.0",
"bootstrap": "^4.1.3", "bootstrap": "^4.1.3",
"bootstrap-select": "^1.13.3", "bootstrap-select": "^1.13.3",

@ -1,6 +1,6 @@
{ {
"/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=e11c94b631fa8e23411d", "/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=ada36e14123738cce4a1",
"/js/vue/Home/app.js": "/js/vue/Home/app.js?id=8a41fb4476589b3a6cff", "/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=26118082661767a7bdc6", "/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=4d34a4ac917830fbaa36" "/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 axiosApi from '@Global/utils/api/request/axiosApi'
import apolloApi from '@Global/utils/api/factory/apollo/apolloApi' import apolloApi from '@Global/utils/api/request/apolloApi'
import apiHandler from '@Global/utils/api/apiHandler'
export const api = (url) => { export const api = (url) => {
let apiClass; let apiClass;
@ -11,9 +10,8 @@ export const api = (url) => {
} else { } else {
throw 'parameter "' + url['type'] + '" must be axios or apollo.'; throw 'parameter "' + url['type'] + '" must be axios or apollo.';
} }
let APIHandler = new apiHandler(); return apiClass.init();
return APIHandler.request(apiClass);
} }
export default { 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) { constructor(urlObj) {
super();
this.staticMethods = ["query", "mutations"]; this.staticMethods = ["query", "mutations"];
this.method = urlObj.method; this.method = urlObj.method;
@ -23,7 +22,8 @@ export default class apolloApi extends apiFactory {
query() { query() {
const query = this.gql; const query = this.gql;
const variables = this.variables; const variables = this.variables;
return apollo.query({ return apollo.query({
query, query,
variables variables

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