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

factorization of the graphQL layer for future alt servers

parent e66ac8f5
No related branches found
No related tags found
No related merge requests found
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
module.exports = {
ENDPOINT : 'https://wwgql.coinduf.eu'
ENDPOINT1 : 'https://wwgql.coinduf.eu'
}
\ No newline at end of file
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
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({
......
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