Mando75 / typeorm-graphql-loader

A query builder to easily resolve nested fields and relations for TypeORM-based GraphQL servers
https://gql-loader.bmuller.net
MIT License
57 stars 12 forks source link

column "createdat" does not exist #15

Closed famuyiwadayo closed 4 years ago

famuyiwadayo commented 4 years ago

Got an error when trying to sort the users data in 'DESC' order.

const user = await loader
      .loadEntity(User, 'user')
      .info(info)
      .order({ createdAt: 'DESC' })
      .loadMany();

User Entity definition


@ObjectType()
@Entity()
export class User extends BaseEntity {
  @Field(type => ID)
  @PrimaryGeneratedColumn('uuid')
  id: string;

................
................

  @Field(type => Date)
  @CreateDateColumn()
  createdAt: Date;

  @Field(type => Date)
  @UpdateDateColumn()
  updatedAt: Date;
}

GraphQL Error log on playground


"errors": [
    {
      "message": "column \"createdat\" does not exist",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "me"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "column \"createdat\" does not exist",
          "name": "QueryFailedError",
          "length": 111,
          "severity": "ERROR",
          "code": "42703",
          "position": "6222",
          "file": "parse_relation.c",
          "line": "3359",
          "routine": "errorMissingColumn",
Mando75 commented 4 years ago

I responded to your email, but I would suggest trying to prepend the alias to the order call like this:

order({'user.createdAt': 'DESC'})

Also a the output of SQL DESCRIBE query for you users table and a copy of the SQL Query log TypeORM generates would be helpful if adding the alias doesn't work.

famuyiwadayo commented 4 years ago

Hi Bryan,Thanks for your swift response.I will try that and see if it works. Thank youRegards,Famuyiwa Dayo Sent from my Samsung Galaxy smartphone. -------- Original message --------From: Bryan Müller notifications@github.com Date: 02/06/2020 8:32 pm (GMT+01:00) To: Mando75/typeorm-graphql-loader typeorm-graphql-loader@noreply.github.com Cc: famuyiwadayo famuyiwadayodaniel@gmail.com, Author author@noreply.github.com Subject: Re: [Mando75/typeorm-graphql-loader] column "createdat" does not exist (#15) I responded to your email, but I would suggest trying to prepend the alias to the order call like this: order({'user.createdAt': 'DESC'})

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe. [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/Mando75/typeorm-graphql-loader/issues/15#issuecomment-637761060", "url": "https://github.com/Mando75/typeorm-graphql-loader/issues/15#issuecomment-637761060", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

famuyiwadayo commented 4 years ago

Hi Bryan,Thanks for the feedback.The order function is now working fine after using the alias as you said.The typeorm-graphql-loader, is really a life saver, and sweet, thanks man.If I have any other challenge with it I will quickly inform you about it.Please can I have your Twitter handle so I can follow you on Twitter?Regards, Famuyiwa DayoSent from my Samsung Galaxy smartphone. -------- Original message --------From: Bryan Müller notifications@github.com Date: 02/06/2020 8:32 pm (GMT+01:00) To: Mando75/typeorm-graphql-loader typeorm-graphql-loader@noreply.github.com Cc: famuyiwadayo famuyiwadayodaniel@gmail.com, Author author@noreply.github.com Subject: Re: [Mando75/typeorm-graphql-loader] column "createdat" does not exist (#15) I responded to your email, but I would suggest trying to prepend the alias to the order call like this: order({'user.createdAt': 'DESC'})

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe. [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/Mando75/typeorm-graphql-loader/issues/15#issuecomment-637761060", "url": "https://github.com/Mando75/typeorm-graphql-loader/issues/15#issuecomment-637761060", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

Mando75 commented 4 years ago

Glad to hear that worked for you.

I don't actually use Twitter that much. The best way to reach me is to just post an issue on GitHub. My dayjob uses GitHub so I frequently check my GitHub notifications during the day. If you open an issue I tend to see it pretty quickly.

famuyiwadayo commented 4 years ago

Oh okay,

thanks though.

On Fri, 5 Jun 2020 at 17:55, Bryan Müller notifications@github.com wrote:

Glad to hear that worked for you.

I don't actually use Twitter that much. The best way to reach me is to just post an issue on GitHub. My dayjob uses GitHub so I frequently check my GitHub notifications during the day. If you open an issue I tend to see it pretty quickly.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Mando75/typeorm-graphql-loader/issues/15#issuecomment-639629187, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANRL6UUPDN5UK2DZZ3LLABTRVEPRXANCNFSM4NQ5T2WQ .