Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-06-03 23:00:52 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4ffd9252b301bb88ac6a1619c3020c422bbddfae
4ffd9252
1 parent
fe924c7a
update ApolloClient Setting
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
8 deletions
front/src/Apollo/Client.js
front/src/Apollo/Client.js
View file @
4ffd925
import
ApolloClient
from
"apollo-boost"
;
import
{
ApolloClient
}
from
"apollo-client"
;
import
{
InMemoryCache
}
from
"apollo-cache-inmemory"
;
import
{
HttpLink
}
from
"apollo-link-http"
;
import
{
WebSocketLink
}
from
"apollo-link-ws"
;
import
{
onError
}
from
"apollo-link-error"
;
import
{
ApolloLink
,
split
}
from
"apollo-link"
;
import
{
getMainDefinition
}
from
"apollo-utilities"
;
import
{
withClientState
}
from
"apollo-link-state"
;
import
{
defaults
,
resolvers
}
from
"./ClientState"
;
import
{
setContext
}
from
"apollo-link-context"
;
export
default
new
ApolloClient
({
const
httpLink
=
new
HttpLink
({
uri
:
"http://localhost:4000"
,
clientState
:
{
defaults
,
resolvers
,
}
,
header
s
:
{
Authorization
:
`Bearer
${
localStorage
.
getItem
(
"token"
)}
`
,
});
const
wsLink
=
new
WebSocketLink
({
uri
:
"ws://localhost:4000"
,
option
s
:
{
reconnect
:
true
,
},
});
const
setAuthorizationLink
=
setContext
((
request
,
previousContext
)
=>
({
headers
:
{
Authorization
:
`Bearer
${
localStorage
.
getItem
(
"token"
)}
`
},
}));
const
clientState
=
withClientState
({
defaults
,
resolvers
,
});
const
client
=
new
ApolloClient
({
link
:
ApolloLink
.
from
([
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
}
`
);
}),
setAuthorizationLink
,
clientState
,
split
(
({
query
})
=>
{
const
definition
=
getMainDefinition
(
query
);
return
(
definition
.
kind
===
"OperationDefinition"
&&
definition
.
operation
===
"subscription"
);
},
wsLink
,
httpLink
),
]),
cache
:
new
InMemoryCache
(),
});
export
default
client
;
...
...
Please
register
or
login
to post a comment