title: How to define and execute GraphQL query with filter
body: <p>So the thing i try to do is, retrieve filtered data from the Database (MongoDB in my situation) using GraphQL.</p>
  
  <p>Speaking in "MySQL language" how to implement the <code>where</code> clause in GraphQL?</p>
  
  <p>I followed this tutorial :
  <a href="https://learngraphql.com/basics/using-a-real-data-source/5" rel="nofollow noreferrer">https://learngraphql.com/basics/using-a-real-data-source/5</a></p>
  
  <p>Query with filter was defined like this : </p>
  
  <pre><code>const Query = new GraphQLObjectType({
    name: "Queries",
    fields: {
      authors: {
        type: new GraphQLList(Author),
        resolve: function(rootValue, args, info) {
          let fields = {};
          let fieldASTs = info.fieldASTs;
          fieldASTs[0].selectionSet.selections.map(function(selection) {
            fields[selection.name.value] = 1;
          });
          return db.authors.find({}, fields).toArray();
        }
      }
    }
  });
  </code></pre>
  
  <p>The tricky part here is the <code>info</code> parameter in the <code>resolve</code> function. Some explanations i've found here : <a href="http://pcarion.com/2015/09/26/graphql-resolve/" rel="nofollow noreferrer">http://pcarion.com/2015/09/26/graphql-resolve/</a></p>
  
  <p>So it is <a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree" rel="nofollow noreferrer">AST</a> (Abstract Syntax Tree)</p>
  
  <p>Can anyone please provide some basic real-life example code that would show how to <strong>define</strong> and <strong>execute</strong> the following query : 
  <strong>Get all authors where name == John</strong></p>
  
  <p>Thank you!</p>