3

I've created class with some ratings changing. Methods in this class should be static, but I have problem with calling it.

class Rating {
  static changeRating ( leftRating,rightRating){
    return(leftRating+rightRating);
 }
} 

and in another file I have

import { User, Team } from '../../models'
import mongoose from 'mongoose'
import { UserInputError, ApolloError } from 'apollo-server-core';
import Joi from 'joi'
import * as Validator from '../../validation'
import * as Config from '../../config'
import * as Rating from '../../rating'
export default {
Mutation:{
 changeRating: async (root, args, { req }, info) => {
        console.log(Rating.changeRating(1255,1244))
 }
}
}

Then I get

"Rating.changeRating is not a function."

I want to have number, this sum is to change in future of course.

Mikred
  • 98
  • 6
  • 4
    Works for me, by just copy and paste your code into the console. How can we replicate your issue? How are you importing Rating in the other file? – Federkun Oct 25 '19 at 19:53
  • 1
    have you included your class into the file that is calling it? – Dan Oct 25 '19 at 19:54
  • Can you post the code from the file you're using Rating in? As well as the rest of the code from the file you defined the class in to see if you're exporting it correctly. You may be importing/exporting something incorrectly. The code you have is all correct, so it is something else. – Adam LeBlanc Oct 25 '19 at 19:56
  • 2
    Did you `export` `Rating`? – Max Baldwin Oct 25 '19 at 20:07
  • Yes export is problem, thanks – Mikred Oct 25 '19 at 20:18
  • `import * as Rating from '../../rating'` is not how you import a class. [You shouldn't use a `class` with only static methods](https://stackoverflow.com/q/29893591/1048572) however anyway. If you write `export function changeRating ( leftRating,rightRating){ return(leftRating+rightRating); }`, your import syntax will work. – Bergi Oct 25 '19 at 21:54

0 Answers0