An api that supports a web-application to enable two users to send short text messages to each other, like Facebook Messages app or Google Chat
Websocket support is simple to setup, which would be an ideal delivery method for messages
GraphQL support is the best, especially when it comes to DB and ORM tooling
It's the only GraphQL server library I have shipped to production with, and since this is the first time I am using the Prisma ORM, I didn't want to add another unknown. With more time, I would consider a service like Hasura, or graphql-yoga, a more minimal Node library
I think the relational aspect of messages (tracking senders/recipients) was reason enough. With native json/jsonb support, messages can expand their capabilities to include more in-depth functionality over time. I considered MongoDB briefly, but Prisma only supports it as a preview feature, so I stopped there
- Start the server:
docker-compose up
- Navigate to http://localhost:4000 in a browser
- In Apollo Studio, add a
userid
header with a value of an existing user from the database (the server creates a couple on startup and logs the user ids) - Send a message:
mutation SendMessage {
sendMessage(to: "messagee", body: "hello!") {
body
}
}
- Query for messages, optionally filtering by user:
query Query {
messages(from: "messager") {
to { username }
body
}
}
docker-compose run --rm api npm run test
- Handle null userId header with a useful error explanation
- Setup a GraphQL subscription to allow streaming of messages
- Configure schema introspection to the playground can infer queries and mutations