Skip to content

Commit

Permalink
Adding additional logging.
Browse files Browse the repository at this point in the history
Updated README to include steps to test
  • Loading branch information
Dave Johnston committed Aug 27, 2017
1 parent 2a76df2 commit 1344d3c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# graphql-go-tutorial
A go implementation of the graphql server, that is compatible with the Apollo demo: https://github.com/apollographql/graphql-tutorial

## Running the GraphQL server
The server runs on port 400. To run execute

$ go run

## Testing with Curl
The server can be tested using curl. The query and mutations are described in the sub-sections below. In each case you can use the following curl command to POST the requests. You can optionally pass the response through jq to make it easier to read.

curl -XPOST http://locahost:4000 -H 'Content-Type: application/json' -d \
curl -XPOST http://localhost:4000/graphql -H 'Content-Type: application/json' -d \
'
<pay load goes here>
' | jq
Expand All @@ -13,7 +18,31 @@ The server can be tested using curl. The query and mutations are described in
### Queries

This will get all channels
...

{"query":"query ChannelsListQuery{channels{id name}}","operationName":"ChannelsListQuery"}

This will return channel details for the specified channel id

{"query":"query ChannelDetailsQuery($channelId: ID!) {channel(id: $channelId) {id name messages{id text}}}","variables":{"channelId":"1"},"operationName":"ChannelDetailsQuery"}

### Mutations
This will add a new message
{"query":"mutation addMessage($message: MessageInput!) {\n addMessage(message: $message) {\n id\n text\n __typename\n }\n}\n","variables":{"message":{"channelId":"1","text":"Yo"}},"operationName":"addMessage"}

{"query":"mutation addMessage($message: MessageInput!) {addMessage(message: $message) {id text}}","variables":{"message":{"channelId":"1","text":"Yo"}},"operationName":"addMessage"}

## Testing with Apollo GraphQL Tutorial
Checkout the apollo Tutorial.

git clone https://github.com/apollographql/graphql-tutorial

Switch to the t7-end branch

cd graphql-tutorial
git checkout t7-end

With the golang server running, start the apollo Client.

cd client
npm install && npm start

The browser should open on localhost:3000. You can now use the UI to test drive the server.
2 changes: 2 additions & 0 deletions handlers/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func GraphQLHandler() http.HandlerFunc {
OperationName: opts.OperationName,
RootObject: rootValue,
}
glog.Infof("Request Options Request:[%s], Variables:[%s], OperationName:[%s]",
opts.Query, opts.Variables, opts.OperationName)

// If there was an error, it should be
// included in the result, so we send it back to the client
Expand Down

0 comments on commit 1344d3c

Please sign in to comment.