Skip to content
Snippets Groups Projects
Commit cf28a0ba authored by Pierre-Jean CHANCELLIER's avatar Pierre-Jean CHANCELLIER
Browse files

Multiple endpoints

parent 55c64b64
No related branches found
No related tags found
1 merge request!22Multiple endpoints
Showing
with 132 additions and 111 deletions
...@@ -50,7 +50,7 @@ The schema documentation is stored in the `./graphql/doc/graphQLschema.txt` file ...@@ -50,7 +50,7 @@ The schema documentation is stored in the `./graphql/doc/graphQLschema.txt` file
In `queries.js` you'll find all queries. In `queries.js` you'll find all queries.
If you want to add a 2nd graphQL server, edit `./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. If you want to add a 2nd graphQL server, edit `./graphql/endpoints.js` to put your URL.
### Special Directories ### Special Directories
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
@import "~bootstrap/scss/forms/form-select"; @import "~bootstrap/scss/forms/form-select";
@import "~bootstrap/scss/forms/form-check"; @import "~bootstrap/scss/forms/form-check";
// @import "~bootstrap/scss/forms/form-range"; // @import "~bootstrap/scss/forms/form-range";
// @import "~bootstrap/scss/forms/floating-labels"; @import "~bootstrap/scss/forms/floating-labels";
@import "~bootstrap/scss/forms/input-group"; @import "~bootstrap/scss/forms/input-group";
// @import "~bootstrap/scss/forms/validation"; // @import "~bootstrap/scss/forms/validation";
......
<template>
<div class="form-floating">
<select
class="form-select"
id="selectClient"
@change="setClient($event)"
v-model="currentClient">
<option
:value="clientName"
v-for="(clientObject, clientName) in $nuxt.$apolloProvider.clients"
:key="clientName">
{{
clientName
.split(/(?=[A-Z])/)
.map((s) => s.toLowerCase())
.join(".")
}}
</option>
</select>
<label for="selectClient">{{ $t("wotwizard.nodeselect") }}</label>
</div>
</template>
<script>
export default {
data() {
return {
currentClient: this.$getApolloClient()
}
},
methods: {
setClient(e) {
localStorage.setItem("apollo-client", e.target.value)
location.reload()
}
}
}
</script>
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
</div> </div>
</nuxt-link> </nuxt-link>
<div class="p-3 border-bottom border-2 text-muted"> <div class="p-3 border-bottom border-2 text-muted">
<ApolloList />
<div class="small mt-2">API graphQL v{{ version }}</div> <div class="small mt-2">API graphQL v{{ version }}</div>
<div class="small" v-if="countMax"> <div class="small" v-if="countMax">
{{ $t("bloc.title") }}<span class="font-weight-bold">{{ {{ $t("bloc.title") }}<span class="font-weight-bold">{{
...@@ -78,6 +79,9 @@ export default { ...@@ -78,6 +79,9 @@ export default {
} }
}, },
apollo: { apollo: {
$client() {
return this.$getApolloClient()
},
countMax: { countMax: {
query: LAST_BLOCK query: LAST_BLOCK
}, },
......
import { import {
InMemoryCache,
IntrospectionFragmentMatcher, IntrospectionFragmentMatcher,
defaultDataIdFromObject defaultDataIdFromObject
} from "apollo-cache-inmemory" } from "apollo-cache-inmemory"
...@@ -10,7 +9,7 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({ ...@@ -10,7 +9,7 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({
}) })
// Apparemment il faut utiliser la syntaxe Apollo v2 // Apparemment il faut utiliser la syntaxe Apollo v2
export const cache = new InMemoryCache({ export const cache = {
addTypename: false, addTypename: false,
fragmentMatcher, fragmentMatcher,
dataIdFromObject: (object) => { dataIdFromObject: (object) => {
...@@ -35,4 +34,4 @@ export const cache = new InMemoryCache({ ...@@ -35,4 +34,4 @@ export const cache = new InMemoryCache({
return defaultDataIdFromObject(object) // fall back to default handling return defaultDataIdFromObject(object) // fall back to default handling
} }
} }
}) }
import { HttpLink } from 'apollo-link-http'
import { setContext } from 'apollo-link-context'
import { from } from 'apollo-link'
import { ENDPOINT1 } 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: ENDPOINT1
})
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
module.exports = {
ENDPOINT1: 'https://wwgql.coinduf.eu',
ENDPOINT2: 'https://myserver.com'
}
\ No newline at end of file
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
import { cache } from "./cache"
import * as endpoints from "./endpoints"
let clientConfigs = {}
for (const key in endpoints) {
if (key != "default")
clientConfigs[key] = {
httpEndpoint: endpoints[key],
inMemoryCacheOptions: cache,
httpLinkOptions: {
credentials: "same-origin"
}
}
}
export default { clientConfigs }
module.exports = {
coindufEu: "https://wwgql.coinduf.eu",
trentesauxFr: "https://gql.wotwizard.trentesaux.fr/"
}
const { ENDPOINT1 } = require('./clients/endpoints'); const endpoints = require("./endpoints")
const fetch = require('node-fetch'); const fetch = require("node-fetch")
const fs = require('fs'); const fs = require("fs")
fetch(ENDPOINT1, { fetch(Object.values(endpoints)[0], {
method: 'POST', method: "POST",
headers: { 'Content-Type': 'application/json' }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
variables: {}, variables: {},
query: ` query: `
{ {
__schema { __schema {
types { types {
...@@ -19,21 +19,28 @@ fetch(ENDPOINT1, { ...@@ -19,21 +19,28 @@ fetch(ENDPOINT1, {
} }
} }
} }
`, `
}), })
}) })
.then(result => result.json()) .then((result) => result.json())
.then(result => { .then((result) => {
const filteredData = result.data.__schema.types.filter( const filteredData = result.data.__schema.types.filter(
type => type.possibleTypes !== null (type) => type.possibleTypes !== null
) )
result.data.__schema.types = filteredData; result.data.__schema.types = filteredData
fs.writeFile('./graphql/fragmentTypes.json', JSON.stringify(result.data), err => { fs.writeFile(
if (err) { "./graphql/fragmentTypes.json",
console.error('Error writing fragmentTypes file', err); JSON.stringify(result.data),
} else { (err) => {
console.log('Fragment types successfully extracted!'); if (err) {
} console.error("Error writing fragmentTypes file", err)
}); } else {
}); console.log("Fragment types successfully extracted!")
\ No newline at end of file }
}
)
})
.catch(function (error) {
console.log(error.message)
})
...@@ -279,5 +279,8 @@ ...@@ -279,5 +279,8 @@
"wot": { "wot": {
"desc": "Gesamtheit der Mitglieder und der Zertifizierungen, die sie miteinander verbinden", "desc": "Gesamtheit der Mitglieder und der Zertifizierungen, die sie miteinander verbinden",
"title": "Vertrauensnetz" "title": "Vertrauensnetz"
},
"wotwizard": {
"nodeselect": "Wählen Sie einen Server"
} }
} }
...@@ -280,5 +280,8 @@ ...@@ -280,5 +280,8 @@
"wot": { "wot": {
"desc": "Set of the individuals recognized as such by their peers including the links that bind them together through certifications", "desc": "Set of the individuals recognized as such by their peers including the links that bind them together through certifications",
"title": "Web of trust" "title": "Web of trust"
},
"wotwizard": {
"nodeselect": "Select a server"
} }
} }
...@@ -280,5 +280,8 @@ ...@@ -280,5 +280,8 @@
"wot": { "wot": {
"desc": "Conjunto de los seres humanos reconocidos como tales por sus pares incluyendo los vínculos que las unen a través de certificaciones (Web of Trust en inglés WOT)", "desc": "Conjunto de los seres humanos reconocidos como tales por sus pares incluyendo los vínculos que las unen a través de certificaciones (Web of Trust en inglés WOT)",
"title": "Red De Confianza(RdC)" "title": "Red De Confianza(RdC)"
},
"wotwizard": {
"nodeselect": "Seleccione un servidor"
} }
} }
...@@ -280,5 +280,8 @@ ...@@ -280,5 +280,8 @@
"wot": { "wot": {
"desc": "Ensemble des membres et des certifications qui les relient entre eux (<a href='https://www.youtube.com/watch?v=8GaTKfa-ADU' target='_blank'>en savoir plus</a>)", "desc": "Ensemble des membres et des certifications qui les relient entre eux (<a href='https://www.youtube.com/watch?v=8GaTKfa-ADU' target='_blank'>en savoir plus</a>)",
"title": "Toile de confiance" "title": "Toile de confiance"
},
"wotwizard": {
"nodeselect": "Sélectionnez un serveur"
} }
} }
...@@ -280,5 +280,8 @@ ...@@ -280,5 +280,8 @@
"wot": { "wot": {
"desc": "Insieme di esseri umani riconosciuti come tali dai loro coetanei, compresi i collegamenti che li uniscono attraverso le certificazioni (Web of Trust in inglese WOT)", "desc": "Insieme di esseri umani riconosciuti come tali dai loro coetanei, compresi i collegamenti che li uniscono attraverso le certificazioni (Web of Trust in inglese WOT)",
"title": "Rete Di Fiducia(RdF)" "title": "Rete Di Fiducia(RdF)"
},
"wotwizard": {
"nodeselect": "Seleziona un server"
} }
} }
import i18n from "./i18n" import i18n from "./i18n"
import pkg from "./package.json" import pkg from "./package.json"
import APOLLO_CONFIG from "./graphql/config"
export default { export default {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
...@@ -33,7 +34,8 @@ export default { ...@@ -33,7 +34,8 @@ export default {
plugins: [ plugins: [
"~plugins/favourites.js", "~plugins/favourites.js",
"~plugins/filters.js", "~plugins/filters.js",
"~plugins/bootstrap.js" "~plugins/bootstrap.js",
"~plugins/getApolloClient.js"
], ],
// Auto import components: https://go.nuxtjs.dev/config-components // Auto import components: https://go.nuxtjs.dev/config-components
...@@ -67,10 +69,10 @@ export default { ...@@ -67,10 +69,10 @@ export default {
file: "en.json" file: "en.json"
}, },
{ {
code: "it", code: "it",
name: "Italiano", name: "Italiano",
file: "it.json" file: "it.json"
}, },
{ {
code: "fr", code: "fr",
...@@ -87,11 +89,9 @@ export default { ...@@ -87,11 +89,9 @@ export default {
name: "Deutsch", name: "Deutsch",
file: "de.json" file: "de.json"
} }
] ],
,
detectBrowserLanguage: { detectBrowserLanguage: {
alwaysRedirect: true alwaysRedirect: true,
,
fallbackLocale: "en" fallbackLocale: "en"
}, },
vueI18n: i18n vueI18n: i18n
...@@ -130,13 +130,7 @@ export default { ...@@ -130,13 +130,7 @@ export default {
} }
}, },
apollo: { apollo: APOLLO_CONFIG,
clientConfigs: {
default: "~/graphql/clients/coindufeu"
//you can setup multiple clients with arbitrary names
//, myotherclient : '~/graphql/clients/otherclient'
}
},
router: { router: {
linkExactActiveClass: "active" linkExactActiveClass: "active"
...@@ -151,5 +145,3 @@ export default { ...@@ -151,5 +145,3 @@ export default {
} }
} }
} }
{ {
"name": "wotwizard-ui", "name": "wotwizard-ui",
"version": "2.3.1", "version": "2.4.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "nuxt", "dev": "nuxt",
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"@nuxtjs/pwa": "^3.3.5", "@nuxtjs/pwa": "^3.3.5",
"apollo-link-context": "^1.0.20", "apollo-link-context": "^1.0.20",
"apollo-link-http": "^1.5.17", "apollo-link-http": "^1.5.17",
"bootstrap": "^5.1.3", "bootstrap": "5.1.3",
"core-js": "^3.15.1", "core-js": "^3.15.1",
"graphql-tag": "^2.12.6", "graphql-tag": "^2.12.6",
"nuxt": "^2.15.8", "nuxt": "^2.15.8",
......
...@@ -72,7 +72,7 @@ export default { ...@@ -72,7 +72,7 @@ export default {
}, },
{ {
title: "traducteurs", title: "traducteurs",
contrib: ["paidge", "kapis", "Trayeur"] contrib: ["paidge", "kapis", "Trayeur", "wellno1"]
}, },
{ {
title: "graphql", title: "graphql",
...@@ -119,6 +119,8 @@ export default { ...@@ -119,6 +119,8 @@ export default {
cgeek: cgeek:
"E35D142DBC3B967FED049B6CCF48782440AC2F5230352D194BFB0DA62A80259C", "E35D142DBC3B967FED049B6CCF48782440AC2F5230352D194BFB0DA62A80259C",
poka: "D01102D1D649EE65A027BC47FD1FB5BB6FECE7B6230414DB66EC490B51DBED7A", poka: "D01102D1D649EE65A027BC47FD1FB5BB6FECE7B6230414DB66EC490B51DBED7A",
wellno1:
"751F817B36AAE403EC4BAE95D15B55132D8CED7ED05F58E791189B0348AE6FE2",
Trayeur: "", Trayeur: "",
Spiranne13: "", Spiranne13: "",
philmarg1: "" philmarg1: ""
......
...@@ -74,6 +74,9 @@ export default { ...@@ -74,6 +74,9 @@ export default {
} }
}, },
apollo: { apollo: {
$client() {
return this.$getApolloClient()
},
favoris: { favoris: {
query: FAVORIS, query: FAVORIS,
variables() { variables() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment