Last active
January 18, 2019 20:36
-
-
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
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
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