This directory contains a basic example of Thunder. The code is organized as follows:
- All server code can be found in the
main.go
file. - The
db/
directory contains MySQL schema and configuration files. - The
client/
directory contains a JavaScript client.
This example requires Docker, Go, and Node.
To start the database, run docker-compose -f db/docker-compose.yml up
to
start a MySQL server on port 3307, properly configured for use with Thunder.
Then, install github.com/mattes/migrate
using go get github.com/mattes/migrate
and run migrate -url mysql://root:@tcp(127.0.0.1:3307)/chat -path ./db/migrations up
to set-up the
database's schema.
Now you can access the database with mysql -h 127.0.0.1 --port=3307 -uroot chat
. Try inserting a new message by running
INSERT INTO messages (text) VALUES ("Hello, world!");
To run the server, first install the server's dependencies using
go get .
.
Then, run go run main.go
to start the server.
To run the client, first install the client's dependencies using npm install
.
Then, run npm run start
to start the client. You can access the basic client
by going to http://localhost:3000
. To run your own queries, access the
GraphiQL client at http://localhost:3000/graphiql
. One example GraphQL query
to fetch all messages is as follows:
{
messages {
id
text
}
}