vesper-framework/vesper

Select only limited query params

Closed this issue · 1 comments

I'm trying to write the query

query {
  posts(limit: 0, offset: 1) {
    title
  }
}

But in the sql it is executing like

SELECT "Post"."id" AS "Post_id", "Post"."title" AS "Post_title", "Post"."text" AS "Post_text" FROM "post";

I want to select the title but it also select the other query too.
How can I get the title in the controller.

@Query()
posts() {
    // I want to select only title in this. 
    return this.entityManager.find();
}

The 3th parameter contains the select fields info which is not described in vesper document.

`import graphqlFields = require('graphql-fields');

@query()
posts(args,context,info: GraphQLResolveInfo) {
// I want to select only title in this.
const select=Object.keys( graphqlFields(info) );
return this.entityManager.find("Post",{select});
}`