import gql from 'graphql-tag'

export const typeDefs = gql`
  extend type Query {
    isLoggedIn: Boolean!
  }
`

const LOCAL_STATE_QUERY = gql`
  query {
    menuOpen @client
  }
`

const TOGGLE_MENU_MUTATION = gql`
  mutation {
    toggleMenu @client
  }
`

export const resolvers = {
  Mutation: {
    toggleMenu(_, variables, { chache }) {
      const { menuOpen } = cache.readQuery({
        query: LOCAL_STATE_QUERY
      })
      const data = {
        data: { menuOpen: !menuOpen }
      }
      cache.writeData(data)
      return data
    }
  }
}
