Skip to content

Circular Reference causes schema not to compile #65

@ryuuji3

Description

@ryuuji3

Possibly related to Issue #64

I have two types that refer to each other;

@ObjectType({ description: 'Store' })
class StoreType {
  @Field({ type: EmployeeType, isList: true })
  employees: EmployeeType[]
}

@ObjectType({ description: 'Employee' })
class EmployeeType {
  @Field({ type: StoreType })
  store: StoreType
}

As a result, I got this when trying to start the server;

{ Error: @ObjectType()'s store is annotated by @Field() but no type could be inferred
    at SchemaFactoryError (/Users/ryuuji3/Projects/shift-scheduler/node_modules/graphql-schema-decorator/src/type-factory/schema.type-factory.ts:27:5)
    at fieldMetadataList.reduce (/Users/ryuuji3/Projects/shift-scheduler/node_modules/graphql-schema-decorator/src/type-factory/object.type-factory.ts:52:21)
    at Array.reduce (native)
    at metadata_builder_1.getMetadataBuilder.buildObjectTypeMetadata.map.metadata (/Users/ryuuji3/Projects/shift-scheduler/node_modules/graphql-schema-decorator/src/type-factory/object.type-factory.ts:49:44)
    at Array.map (native)
    at Object.objectTypeFactory (/Users/ryuuji3/Projects/shift-scheduler/node_modules/graphql-schema-decorator/src/type-factory/object.type-factory.ts:22:8)
    at convertType (/Users/ryuuji3/Projects/shift-scheduler/node_modules/graphql-schema-decorator/src/type-factory/field.type-factory.ts:53:20)
    at Object.fieldTypeFactory (/Users/ryuuji3/Projects/shift-scheduler/node_modules/graphql-schema-decorator/src/type-factory/field.type-factory.ts:217:21)
    at fieldMetadataList.reduce (/Users/ryuuji3/Projects/shift-scheduler/node_modules/graphql-schema-decorator/src/type-factory/object.type-factory.ts:50:25)
    at Array.reduce (native) type: 2 }

When commenting out Store.employees, it compiles successfully. Then I uncommented Store.employees and commented out Employee.store and it compiled successfully.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions