Graphene-django: Limit fields fetched from database for graphene-django

Created on 22 Feb 2018  路  5Comments  路  Source: graphql-python/graphene-django

Hi,

I have a relatively wide database table and use graphene to fetch maybe one or two fields from it. At the moment with the Django ORM it will fetch the entire record by default. Is there a way to integrate the only('col1', 'col2') for each column or field requested in the query? This should make the whole process much faster especially on wide tables where one wants maybe all records from one column.

Maybe there is a way to do this already?

question wontfix

Most helpful comment

This is the first thing I looked into doing after I installed this package. Even if there were a way to get at the fields that were requested, I could do the restriction in the resolver function manually. But I don't see a way to get at that information on info

Is there away to get at the fields requested ?

All 5 comments

This feature also has some good security uses, like when you only want to expose certain fields on a model.

This is the first thing I looked into doing after I installed this package. Even if there were a way to get at the fields that were requested, I could do the restriction in the resolver function manually. But I don't see a way to get at that information on info

Is there away to get at the fields requested ?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

A query like this:

{
  allTimeobjects (first:1) {
   edges {
    node {
      id,
      beginning,
      end,
      elapsed
    }
  }
  }
}

Executes the exact same SQL as this:

{
  allTimeobjects {
   edges {
    node {
      id,
      beginning,
      end,
      elapsed
    }
  }
  }
}

They also both select all columns and not only the ones we are asking for. (only tested on sqlite but assume postgresql would be the same behavior)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickhudkins picture nickhudkins  路  3Comments

Eraldo picture Eraldo  路  3Comments

amiyatulu picture amiyatulu  路  3Comments

timothyjlaurent picture timothyjlaurent  路  3Comments

BrianChapman picture BrianChapman  路  3Comments