title: How a guard can be implemented to a graphql resolver
body: <p>I'm new in graphql and I am trying to integrate an authentication/authorization system in my project. I found an example on Medium, but I do not understand how a guard communicates with a resolver. If someone knows, I will be very grateful. </p>
  
  <pre><code>import { ApolloServer } from 'apollo-server';
  import gql from 'graphql-tag';
  import { tradeTokenForUser } from './auth-helpers';
  
  const HEADER_NAME = 'authorization';
  
  const typeDefs = gql`
    type Query {
       me: User
       serverTime: String
    }
    type User {
       id: ID!
       username: String!
    }
  `;
  
  const resolvers = {
     Query: {
        me: authenticated((root, args, context) =&gt; context.currentUser), 
        serverTime: () =&gt; new Date(),
     },
     User: {
        id: user =&gt; user._id,
        username: user =&gt; user.username,
     },
  };
  
  const server = new ApolloServer({
     typeDefs,
     resolvers,
     context: async ({ req }) =&gt; {
        let authToken = null;
        let currentUser = null;
  
         try {
            authToken = req.headers[HEADER_NAME];
  
            if (authToken) {
                 currentUser = await tradeTokenForUser(authToken);
            }
         } catch (e) {
            console.warn(`Unable to authenticate using auth token: ${authToken}`);
         }
  
        return {
            authToken,
            currentUser,
        };
     },
  });
  
  server.listen().then(({ url }) =&gt; {
    console.log(`  Server ready at ${url}`);
  });
  </code></pre>
  
  <pre><code>export const authenticated = next =&gt; (root, args, context, info) =&gt; {
    if (!context.currentUser) {
        throw new Error(`Unauthenticated!`);
    }
  
    return next(root, args, context, info);
  };
  </code></pre>
  
  <p>I do not understand what "next" parameter does and why as an argument when this guard is called I have to return a value?</p>