This repository has been archived by the owner on Jul 10, 2019. It is now read-only.
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.
Open
Description
Hi,
I'm wondering if there is anything like an Object type for plain objects, just like you have Int, String, Boolean ?
I'm storing a "session" field in my local apollo state, containing a loggedIn
boolean and a currentUser
object :
function mutate(cache, payload) {
cache.writeData({ data: payload })
}
const localState = {
resolvers: {
Mutation: {
updateSession(_, { loggedIn, currentUser }, { cache }) {
mutate(cache, {
session: {
__typename: 'Session',
loggedIn,
currentUser
}
})
return null
}
}
},
defaults: {
session: {
__typename: 'Session',
loggedIn: false,
currentUser: null
}
}
}
// Then :
withClientState({
cache,
...localState
})
I wanna mutate this state just after login :
const login = gql`
mutation($email: String!, $password: String!) {
login(email: $email, password: $password) {
_id
email
name
token
}
}
`
const updateSession = gql`
mutation($loggedIn: Boolean!, $currentUser: CurrentUser!) {
updateSession(loggedIn: $loggedIn, currentUser: $currentUser) @client
}
`
// ... then when submitting login form :
this.props.login({
variables: {
email,
password
}
}).then(({ data: { login } }) => {
localStorage.setItem('liveql-token', login.token)
this.props.updateSession({
variables: {
loggedIn: true,
currentUser: {
__typename: 'CurrentUser',
...pick(login, ['_id', 'email', 'name'])
}
}
})
})
Look at the mutation type def for $currentUser
: what type should I write ?
I found out that it works with any type, but I'm afraid that this behaviour will break in future release since there's nothing in the doc about this (or, is there ?)
Thanks a lot for your insight.
Olivier