Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@OrderBy bug #77

Open
SergeShkurko opened this issue Feb 24, 2018 · 0 comments
Open

@OrderBy bug #77

SergeShkurko opened this issue Feb 24, 2018 · 0 comments
Labels

Comments

@SergeShkurko
Copy link

When i add

@OrderBy() orderBy: OrderByItem[],

in my method

import {
  ObjectType,
  Field,
  Ctx,
  Arg,
  OrderBy,
  OrderByItem,
  PaginationResponse,
  Root,
} from 'graphql-schema-decorator/lib'
import NewsSchema from 'news/schema'

@ObjectType({
  description: 'News',
})
export default class NewsQuery {
  @Field({
    type: NewsSchema,
    pagination: true,
  })
  public all?(
    @Ctx() context: any,
    @Root() root: any,
    @Arg({ name: 'offset' }) offset: number,
    @Arg({ name: 'limit' }) limit: number,
    @OrderBy() orderBy: OrderByItem[],
  ): NewsSchema[] {
    console.log(context, offset, limit, orderBy[0])

    const result = [
      {
        image: 'image 1',
        title: 'title 1',
        description: 'description 1',
        content: 'content 1',
        timestamp: new Date().toISOString(),
      },
      {
        image: 'image 2',
        title: 'title 2',
        description: 'description 2',
        content: 'content 2',
        timestamp: new Date().toISOString(),
      },
      {
        image: 'image 3',
        title: 'title 3',
        description: 'description 3',
        content: 'content 3',
        timestamp: new Date().toISOString(),
      },
    ]

    return new PaginationResponse<NewsSchema>(3, result, null)
  }
}

Without @OrderBy() orderBy: OrderByItem[], work normally

node give me error:

/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/order-by.type-factory.js:56
                    if (fieldReturnType.prototype == null) {
                                        ^

TypeError: Cannot read property 'prototype' of undefined
    at fieldMetadataList.forEach.def (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/order-by.type-factory.js:56:41)
    at Array.forEach ()
    at Function.orderByFactory (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/order-by.type-factory.js:54:35)
    at Object.fieldTypeFactory (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/field.type-factory.js:191:55)
    at fieldMetadataList.reduce (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/object.type-factory.js:37:40)
    at Array.reduce ()
    at metadata_builder_1.getMetadataBuilder.buildObjectTypeMetadata.map.metadata (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/object.type-factory.js:36:42)
    at Array.map ()
    at Object.objectTypeFactory (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/object.type-factory.js:17:10)
    at convertType (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/field.type-factory.js:44:48)
    at Object.fieldTypeFactory (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/field.type-factory.js:190:23)
    at fieldMetadatas.reduce (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/schema.type-factory.js:40:63)
    at Array.reduce ()
    at metadatas.map.metadata (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/schema.type-factory.js:39:31)
    at Array.map ()
    at getEntryObject (/home/node/app/node_modules/graphql-schema-decorator/lib/type-factory/schema.type-factory.js:36:30)

Lib version: 1.0.0-alpha9
Node: 9.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants