diff --git a/README.md b/README.md index 37bebb2fb9ea667ed4a6c55b6f327208e990b295..099cced09a03c05241a478a41c75e34fdfa5db6b 100644 --- a/README.md +++ b/README.md @@ -94,4 +94,6 @@ $ git push Il suffit de créer un fichier `./pages/mapage.vue` pour que la nouvelle page soit accessible directement sur http://localhost/mapage. Pensez à insérer la logique pour le fil d'ariane dans ce fichier et à mettre à jour le menu dans la variable `menus` du fichier `./layouts/default.vue`. 3 pages d'exemple sont fournies pour montrer l'utilisation de l'API graphQL et de chartJS. ## GraphQL -Tout ce qui touche à GraphQL se trouve dans le dossier `./graphql`. Le fichier endpoints.js contient la liste des serveurs graphQL, le fichier queries.js contient toutes les requêtes de l'application. \ No newline at end of file +All conf files for Apollo Graphql are stored in `./graphql`. +The file `queries.js` contains all queries. +If you want to add a 2nd graphQL server, edit the file `./graphql/clients/endpoints.js` to put your URL and uncomment the line concerning the `apollo.clientConfigs.myotherclient` option in `nuxt.config.js`. I have not tested this functionnality. \ No newline at end of file diff --git a/graphql/index.js b/graphql/clients/coindufeu.js similarity index 94% rename from graphql/index.js rename to graphql/clients/coindufeu.js index 178821e8bcf123a52aff4c0835f8fcc72e7344a8..f0db19e5532df85ae88b8398ebbf5cacea686497 100644 --- a/graphql/index.js +++ b/graphql/clients/coindufeu.js @@ -3,7 +3,7 @@ import { setContext } from 'apollo-link-context' import { from } from 'apollo-link' import {ENDPOINT1} from './endpoints' -import {cache} from './cache' +import {cache} from '../cache' export default ctx => { const ssrMiddleware = setContext((_, { headers }) => { diff --git a/graphql/clients/endpoints.js b/graphql/clients/endpoints.js new file mode 100644 index 0000000000000000000000000000000000000000..5108540880d199f55081198080c3b35016fe0af8 --- /dev/null +++ b/graphql/clients/endpoints.js @@ -0,0 +1,4 @@ +module.exports = { + ENDPOINT1 : 'https://wwgql.coinduf.eu', + ENDPOINT2 : 'https://myserver.com' +} \ No newline at end of file diff --git a/graphql/clients/otherclient.js b/graphql/clients/otherclient.js new file mode 100644 index 0000000000000000000000000000000000000000..1a6b095dcfdabaac9e8b4c1a92fdbf306ad16b3d --- /dev/null +++ b/graphql/clients/otherclient.js @@ -0,0 +1,28 @@ +import { HttpLink } from 'apollo-link-http' +import { setContext } from 'apollo-link-context' +import { from } from 'apollo-link' + +import {ENDPOINT2} from './endpoints' +import {cache} from '../cache' + +export default ctx => { + const ssrMiddleware = setContext((_, { headers }) => { + if (process.client) return headers + return { + headers + } + }) + + const httpLink = new HttpLink({ + uri: ENDPOINT2 + }) + + const link = from([ssrMiddleware, httpLink]) + + return { + link, + cache, + // https://github.com/nuxt-community/apollo-module/issues/306#issuecomment-607225431 + defaultHttpLink: false + } +} \ No newline at end of file diff --git a/graphql/endpoints.js b/graphql/endpoints.js deleted file mode 100644 index 907db9d47944eedcecea676125c08e5f4ec0c8bb..0000000000000000000000000000000000000000 --- a/graphql/endpoints.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - ENDPOINT1 : 'https://wwgql.coinduf.eu' -} \ No newline at end of file diff --git a/graphql/schemaQuery.js b/graphql/schemaQuery.js index d9ef29c71401c15579fda20874a7f7073556a311..736bec3631da0f08197899d88b21753c161108bd 100644 --- a/graphql/schemaQuery.js +++ b/graphql/schemaQuery.js @@ -1,4 +1,4 @@ -const {ENDPOINT1} = require('./endpoints'); +const {ENDPOINT1} = require('./clients/endpoints'); const fetch = require('node-fetch'); const fs = require('fs'); diff --git a/nuxt.config.js b/nuxt.config.js index 6ce6da7552501280f64abd1d589b75e5cf811c33..2b2f1f8ebd4e847de35894bce07baeb95a810bb8 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -79,7 +79,9 @@ export default { apollo: { clientConfigs: { - default: '~/graphql' + default: '~/graphql/clients/coindufeu' + //you can setup multiple clients with arbitrary names + //, myotherclient : '~/graphql/clients/otherclient' }, },