Skip to content

Commit

Permalink
Merge pull request #29 from chrisscott/update_deps_readme
Browse files Browse the repository at this point in the history
Update dependencies. Update example server and README.
  • Loading branch information
chrisscott committed May 9, 2021
2 parents 3430e27 + 2a09ca3 commit 2d54e23
Show file tree
Hide file tree
Showing 4 changed files with 15,125 additions and 5,310 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,22 @@ The following environment variables must be set:

### Running the Example Server

`npm start`
`DEBUG=* npm start`

This will run the following endpoints on the local host on the `PORT` environment variable, if defined. Defaults to port `9090`.

* `/graphql` - the GraphQL server
* `/graphiql` - the GraphiQL interface (only available when `NODE_ENV` is not `production`)
This will run the `/graphql` endpoint on localhost on the `PORT` environment variable, if defined (defaults to `9090`). In non-production environments, the GraphQL Playground interface will run here too.

In-memory caching (see below) is enabled on the example server.

Test query:
```
{
brewerySearch(q: "Inefficient Prohibitions") {
brewery_id
brewery_name
}
}
```

## User Authentication

To use an Untappd user's API limits instead of your app's limits, you can [authenticate](https://untappd.com/api/docs#authentication) the user and pass their `access_token` to the API.
Expand Down
50 changes: 27 additions & 23 deletions example-server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import express from 'express';
import bodyParser from 'body-parser';
import { ApolloServer } from 'apollo-server-express';
import NodeCache from 'node-cache';
import { schema } from './src';
Expand All @@ -13,26 +12,31 @@ if (!process.env.UNTAPPD_CLIENT_ID || !process.env.UNTAPPD_CLIENT_SECRET) {
process.exit(1);
}

// Cache in memory
const context = {
cache: new NodeCache({
stdTTL: 60 * 60 * 24 * 7, // cache for one week
}),
};

const server = new ApolloServer({
schema,
context,
formatError: (err) => {
const { status, message } = err.originalError;
return { status, message };
},
});

const app = express();
server.applyMiddleware({ app });

// Start the server
app.listen(port, () => {
async function startServer() {

// Cache in memory
const context = {
cache: new NodeCache({
stdTTL: 60 * 60 * 24 * 7, // cache for one week
}),
};

const server = new ApolloServer({
schema,
context,
formatError: (err) => {
const { status, message } = err.originalError;
return { status, message };
},
});

const app = express();
server.applyMiddleware({ app });

// Start the server
await new Promise(resolve => app.listen({ port }, resolve));
console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`);
debug(`Go to http://localhost:${port}/graphiql to run queries!`);
});
}

startServer();
Loading

0 comments on commit 2d54e23

Please sign in to comment.