import log from 'loglevel';
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';

export default {
  methods: {
    addSchoolClass(store, schoolClass) {
      const query = ME_QUERY;
      if (schoolClass) {
        log.debug('updating school class', schoolClass);
        const { me } = store.readQuery({ query });
        if (me) {
          let schoolClasses = [...me.schoolClasses, schoolClass];
          const selectedClass = {
            id: schoolClass.id,
            __typename: 'SchoolClassNode',
          };
          const data = {
            me: {
              ...me,
              schoolClasses,
              selectedClass,
            },
          };
          store.writeQuery({ query, data });
        }
      }
    },
  },
};
