diff --git a/graphql/cache.js b/graphql/cache.js new file mode 100644 index 0000000000000000000000000000000000000000..a8035d3c198393e5177968142328cac93b35cb06 --- /dev/null +++ b/graphql/cache.js @@ -0,0 +1,21 @@ +import { InMemoryCache, IntrospectionFragmentMatcher, defaultDataIdFromObject } from 'apollo-cache-inmemory' +import introspectionQueryResultData from './fragmentTypes.json'; + +const fragmentMatcher = new IntrospectionFragmentMatcher({ + introspectionQueryResultData + }) + + // Apparemment il faut utiliser la syntaxe Apollo v2 +export const cache = new InMemoryCache({ + addTypename: false, + fragmentMatcher, + dataIdFromObject: object => { + switch (object.__typename) { + case 'Identity': return object.hash + case 'Event': return object.block.number + case 'EventId': return `${object.member.hash}:${object.inOut}` + case 'Forecast': return `${object.member.hash}:${object.date}:${object.after}:${object.proba}` + default: return defaultDataIdFromObject(object); // fall back to default handling + } + } +}) \ No newline at end of file diff --git a/graphql/endpoint.js b/graphql/endpoint.js deleted file mode 100644 index 2d504da26cc3306285d993adb1a47aa4ae1b16fc..0000000000000000000000000000000000000000 --- a/graphql/endpoint.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - ENDPOINT : 'https://wwgql.coinduf.eu' -} \ No newline at end of file diff --git a/graphql/endpoints.js b/graphql/endpoints.js new file mode 100644 index 0000000000000000000000000000000000000000..907db9d47944eedcecea676125c08e5f4ec0c8bb --- /dev/null +++ b/graphql/endpoints.js @@ -0,0 +1,3 @@ +module.exports = { + ENDPOINT1 : 'https://wwgql.coinduf.eu' +} \ No newline at end of file diff --git a/graphql/index.js b/graphql/index.js index 03471a55969e25e4a0e095059d5323424611a572..c8e399173da6b2a2b63c741516f3327e94cef104 100644 --- a/graphql/index.js +++ b/graphql/index.js @@ -1,10 +1,9 @@ import { HttpLink } from 'apollo-link-http' import { setContext } from 'apollo-link-context' import { from } from 'apollo-link' -import { InMemoryCache, IntrospectionFragmentMatcher, defaultDataIdFromObject } from 'apollo-cache-inmemory' -import {ENDPOINT} from './endpoint' -import introspectionQueryResultData from './fragmentTypes.json'; +import {ENDPOINT1} from './endpoints' +import {cache} from './cache' export default ctx => { const ssrMiddleware = setContext((_, { headers }) => { @@ -15,33 +14,13 @@ export default ctx => { }) const httpLink = new HttpLink({ - uri: ENDPOINT + uri: ENDPOINT1 }) const link = from([ssrMiddleware, httpLink]) - const fragmentMatcher = new IntrospectionFragmentMatcher({ - introspectionQueryResultData - }) - - // Apparemment il faut utiliser la syntaxe Apollo v2 - const cache = new InMemoryCache({ - addTypename: false, - fragmentMatcher, - dataIdFromObject: object => { - switch (object.__typename) { - case 'Identity': return object.hash - case 'Event': return object.block.number - case 'EventId': return `${object.member.hash}:${object.inOut}` - case 'Forecast': return `${object.member.hash}:${object.date}:${object.after}:${object.proba}` - default: return defaultDataIdFromObject(object); // fall back to default handling - } - } - }) - return { link, - cache, - defaultHttpLink: false + cache } } \ No newline at end of file diff --git a/graphql/schemaQuery.js b/graphql/schemaQuery.js index 1745426e31f734f2e533978ffdb1994d2ffb682a..d9ef29c71401c15579fda20874a7f7073556a311 100644 --- a/graphql/schemaQuery.js +++ b/graphql/schemaQuery.js @@ -1,8 +1,8 @@ -const {ENDPOINT} = require('./endpoint'); +const {ENDPOINT1} = require('./endpoints'); const fetch = require('node-fetch'); const fs = require('fs'); -fetch(ENDPOINT, { +fetch(ENDPOINT1, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({