Created
August 3, 2018 15:43
-
-
Save koblas/e2d4228b41bc0816c3df6122ffab1800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func init() { | |
mutationConfig.AddFieldConfig("sentimentAnalysis", &graphql.Field{ | |
Type: graphql.NewObject(graphql.ObjectConfig{ | |
Name: "SentimentAnalysisResult", | |
Description: "Sentiment Analysis Response", | |
Fields: graphql.Fields{ | |
"score": &graphql.Field{ | |
Type: graphql.Int, | |
}, | |
}, | |
}), | |
Args: graphql.FieldConfigArgument{ | |
"text": &graphql.ArgumentConfig{ | |
Type: &graphql.NonNull{ | |
OfType: graphql.String, | |
}, | |
}, | |
"lang": &graphql.ArgumentConfig{ | |
Type: graphql.String, | |
}, | |
}, | |
Resolve: wrapIsAuth(wrapGraphQL(func(ctx context.Context, input struct { | |
Text string | |
Lang *string | |
}, _ []*ValidationError) (interface{}, error) { | |
logger := service.LoggerFromContext(ctx) | |
analyizer := service.GetSentimentAnalysis(ctx) | |
logger.Info("Calling SentimentAnalysis") | |
// https://godoc.org/github.com/cdipaolo/sentiment#Models.SentimentAnalysis | |
result := analyizer.SentimentAnalysis(input.Text, input.Lang) | |
return &result, nil | |
})), | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment