title: Limiting SQL query to defined fields/columns in Graphene-SQLAlchemy
body: <blockquote>
  <p>This question has been posted as a GH issues under <a href="https://github.com/graphql-python/graphene-sqlalchemy/issues/134" rel="nofollow noreferrer">https://github.com/graphql-python/graphene-sqlalchemy/issues/134</a> but I thought I'd post it here too to tap into the SO crowd.</p>
  <p>A full working demo can be found under <a href="https://github.com/somada141/demo-graphql-sqlalchemy-falcon" rel="nofollow noreferrer">https://github.com/somada141/demo-graphql-sqlalchemy-falcon</a>.</p>
  </blockquote>
  <p>Consider the following SQLAlchemy ORM class:</p>
  <pre><code>class Author(Base, OrmBaseMixin):
      __tablename__ = &quot;authors&quot;
  
      author_id = sqlalchemy.Column(
          sqlalchemy.types.Integer(),
          primary_key=True,
      )
  
      name_first = sqlalchemy.Column(
          sqlalchemy.types.Unicode(length=80),
          nullable=False,
      )
  
      name_last = sqlalchemy.Column(
          sqlalchemy.types.Unicode(length=80),
          nullable=False,
      )
  </code></pre>
  <p>Simply wrapped in an <code>SQLAlchemyObjectType</code> as such:</p>
  <pre><code>class TypeAuthor(SQLAlchemyObjectType):
      class Meta:
          model = Author
  </code></pre>
  <p>and exposed through:</p>
  <pre><code>author = graphene.Field(
      TypeAuthor,
      author_id=graphene.Argument(type=graphene.Int, required=False),
      name_first=graphene.Argument(type=graphene.String, required=False),
      name_last=graphene.Argument(type=graphene.String, required=False),
  )
  
  @staticmethod
  def resolve_author(
      args,
      info,
      author_id: Union[int, None] = None,
      name_first: Union[str, None] = None,
      name_last: Union[str, None] = None,
  ):
      query = TypeAuthor.get_query(info=info)
  
      if author_id:
          query = query.filter(Author.author_id == author_id)
  
      if name_first:
          query = query.filter(Author.name_first == name_first)
  
      if name_last:
          query = query.filter(Author.name_last == name_last)
  
      author = query.first()
  
      return author
  </code></pre>
  <p>A GraphQL query such as:</p>
  <pre><code>query GetAuthor{
    author(authorId: 1) {
      nameFirst
    }
  }
  </code></pre>
  <p>will cause the following raw SQL to be emitted (taken from the echo logs of the SQLA engine):</p>
  <pre><code>SELECT authors.author_id AS authors_author_id, authors.name_first AS authors_name_first, authors.name_last AS authors_name_last
  FROM authors
  WHERE authors.author_id = ?
   LIMIT ? OFFSET ?
  2018-05-24 16:23:03,669 INFO sqlalchemy.engine.base.Engine (1, 1, 0)
  </code></pre>
  <p>As one can see we may only want the <code>nameFirst</code> field, i.e., the <code>name_first</code> column but the entire row is fetched. Of course the GraphQL response only contains the requested fields, i.e.,</p>
  <pre><code>{
    &quot;data&quot;: {
      &quot;author&quot;: {
        &quot;nameFirst&quot;: &quot;Robert&quot;
      }
    }
  }
  </code></pre>
  <p>but we have still fetched the entire row, which becomes a major issue when dealing with wide tables.</p>
  <p>Is there a way to automagically communicate which columns are needed to SQLAlchemy so as preclude this form of over-fetching?</p>