-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-browser.js
60 lines (51 loc) · 1.55 KB
/
gatsby-browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React /*, { Component } */ from 'react'
import { Provider } from 'react-redux'
// import If from 'react-ifs'
import fetch from 'node-fetch'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloProvider } from 'react-apollo'
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { onError } from 'apollo-link-error'
import { HttpLink } from 'apollo-link-http'
import { ApolloLink } from 'apollo-link'
import store from './src/store/'
// const client = new ApolloClient({
// link: createHttpLink({
// uri: 'https://graphql.org/swapi-graphql/',
// fetch: fetch,
// fetchOptions:{mode:'no-cors'}
// }),
// cache: new InMemoryCache(),
// })
// const URL = "https://graphql-wrap-rest.herokuapp.com/";
const URL = 'https://cfcurve.azurewebsites.net/graphql'
const httpLink = createHttpLink({
uri: URL,
})
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
)
}
if (networkError) {
console.log(`[Network error]: ${networkError}`)
}
})
const link = ApolloLink.from([errorLink, httpLink])
const cache = new InMemoryCache()
const client = new ApolloClient({
link,
cache,
// fetchOptions:{mode:'no-cors'}
})
export const wrapRootElement = ({ element }) => (
<ApolloProvider client={client}>
<Provider store={store}>
{element}
</Provider>
</ApolloProvider>
)