import ME_QUERY from '@/graphql/gql/queries/meQuery';

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