Skip to content

Instantly share code, notes, and snippets.

@betaflag
Last active January 18, 2019 20:36
Show Gist options
  • Save betaflag/5fba89433d7bab1ce6a6e7dfa4db47d1 to your computer and use it in GitHub Desktop.
Save betaflag/5fba89433d7bab1ce6a6e7dfa4db47d1 to your computer and use it in GitHub Desktop.
Simple GraphQL Server using Apollo Server for sentiment analysis that fits in a single
const { ApolloServer, gql } = require("apollo-server");
var Sentiment = require("sentiment");
var sentiment = new Sentiment();
const typeDefs = gql`
type SentimentAnalysis {
score: Int
comparative: Float
tokens: [String]
words: [String]
positive: [String]
negative: [String]
}
type Query {
sentiment(phrase: String!): SentimentAnalysis
}
`;
const resolvers = {
Query: {
sentiment: (parent, args) => sentiment.analyze(args.phrase)
}
};
const server = new ApolloServer({ typeDefs, resolvers });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment