You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using an entity with composite primary keys. Those primary keys are not used in the generated schema for the read-one, update-one, and delete-one queries/mutations.
import{NestjsQueryGraphQLModule}from'@ptc-org/nestjs-query-graphql';import{NestjsQueryTypeOrmModule}from'@ptc-org/nestjs-query-typeorm';import{Module}from'@nestjs/common';import{TodoItemEntity}from'./todo-item.entity';
@Module({imports: [NestjsQueryGraphQLModule.forFeature({// import the NestjsQueryTypeOrmModule to register the entity with typeorm// and provide a QueryServiceimports: [NestjsQueryTypeOrmModule.forFeature([TodoItemEntity])],resolvers: [{EntityClass: TodoItemEntity,DTOClass: TodoItemEntity,},],}),],})exportclassTodoItemModule{}
Expected behavior
The schema generated is using id: ID! for the read-one, update-one, and delete-one queries/mutations.
Generated schema
typeTodoItem {
firstId: ID!secondId: ID!title: String!
}
typeDeleteManyResponse {
# The number of records deleted.deletedCount: Int!
}
typeTodoItemDeleteResponse {
firstId: IDsecondId: IDtitle: String
}
typeUpdateManyResponse {
# The number of records updated.updatedCount: Int!
}
typeTodoItemEdge {
# The node containing the TodoItemnode: TodoItem! # Cursor for this node.cursor: ConnectionCursor!
}
# Cursor for paging through collectionsscalarConnectionCursortypePageInfo {
# true if paging forward and there are more records.hasNextPage: Boolean # true if paging backwards and there are more records.hasPreviousPage: Boolean # The cursor of the first returned record.startCursor: ConnectionCursor # The cursor of the last returned record.endCursor: ConnectionCursor
}
typeTodoItemConnection {
# Paging informationpageInfo: PageInfo! # Array of edges.edges: [TodoItemEdge!]!
}
typeQuery {
todoItem(
# The id of the record to find.id: ID!
): TodoItem!todoItems(
# Limit or page results.paging: CursorPaging! = { first: 10 }
# Specify to filter the records returned.filter: TodoItemFilter! = {}
# Specify to sort results.sorting: [TodoItemSort!]! = []
): TodoItemConnection!
}
inputCursorPaging {
# Paginate before opaque cursorbefore: ConnectionCursor # Paginate after opaque cursorafter: ConnectionCursor # Paginate firstfirst: Int # Paginate lastlast: Int
}
inputTodoItemFilter {
and: [TodoItemFilter!]
or: [TodoItemFilter!]
firstId: IDFilterComparisonsecondId: IDFilterComparisontitle: StringFieldComparison
}
inputIDFilterComparison {
is: BooleanisNot: Booleaneq: IDneq: IDgt: IDgte: IDlt: IDlte: IDlike: IDnotLike: IDiLike: IDnotILike: IDin: [ID!]
notIn: [ID!]
}
inputStringFieldComparison {
is: BooleanisNot: Booleaneq: Stringneq: Stringgt: Stringgte: Stringlt: Stringlte: Stringlike: StringnotLike: StringiLike: StringnotILike: Stringin: [String!]
notIn: [String!]
}
inputTodoItemSort {
field: TodoItemSortFields!direction: SortDirection!nulls: SortNulls
}
enumTodoItemSortFields {
firstId secondId title
}
# Sort DirectionsenumSortDirection {
ASC DESC
}
# Sort Nulls OptionsenumSortNulls {
NULLS_FIRST NULLS_LAST
}
typeMutation {
createOneTodoItem(input: CreateOneTodoItemInput!): TodoItem!createManyTodoItems(input: CreateManyTodoItemsInput!): [TodoItem!]!updateOneTodoItem(input: UpdateOneTodoItemInput!): TodoItem!updateManyTodoItems(input: UpdateManyTodoItemsInput!): UpdateManyResponse!deleteOneTodoItem(input: DeleteOneTodoItemInput!): TodoItemDeleteResponse!deleteManyTodoItems(input: DeleteManyTodoItemsInput!): DeleteManyResponse!
}
inputCreateOneTodoItemInput {
# The record to createtodoItem: CreateTodoItem!
}
inputCreateTodoItem {
firstId: ID!secondId: ID!title: String!
}
inputCreateManyTodoItemsInput {
# Array of records to createtodoItems: [CreateTodoItem!]!
}
inputUpdateOneTodoItemInput {
# The id of the record to updateid: ID! # The update to apply.update: UpdateTodoItem!
}
inputUpdateTodoItem {
firstId: IDsecondId: IDtitle: String
}
inputUpdateManyTodoItemsInput {
# Filter used to find fields to updatefilter: TodoItemUpdateFilter! # The update to apply to all records found using the filterupdate: UpdateTodoItem!
}
inputTodoItemUpdateFilter {
and: [TodoItemUpdateFilter!]
or: [TodoItemUpdateFilter!]
firstId: IDFilterComparisonsecondId: IDFilterComparisontitle: StringFieldComparison
}
inputDeleteOneTodoItemInput {
# The id of the record to delete.id: ID!
}
inputDeleteManyTodoItemsInput {
# Filter to find records to deletefilter: TodoItemDeleteFilter!
}
inputTodoItemDeleteFilter {
and: [TodoItemDeleteFilter!]
or: [TodoItemDeleteFilter!]
firstId: IDFilterComparisonsecondId: IDFilterComparisontitle: StringFieldComparison
}
I would expect something like:
type Query {
todoItem(
- # The id of the record to find.- id: ID!+ firstId: ID!+ secondId: ID!
): TodoItem!
}
input UpdateOneTodoItemInput {
- # The id of the record to update- id: ID!+ firstId: ID!+ secondId: ID!
# The update to apply.
update: UpdateTodoItem!
}
input DeleteOneTodoItemInput {
- # The id of the record to delete.- id: ID!+ firstId: ID!+ secondId: ID!
}
Desktop (please complete the following information):
Node Version: v22.2.0
@ptc-org/nestjs-query-core: ^6.1.0,
@ptc-org/nestjs-query-graphql: ^6.1.0,
@ptc-org/nestjs-query-typeorm: ^6.1.0,
The text was updated successfully, but these errors were encountered:
Interesting case, if I look at the code everywhere where we use IDField it only expects one field, to change this will be a challenge as we would then go from one known field (id) to 1 or more unknown fields.
Less then ideal solution: mark the second primary field as a required filter field?
ValentinVignal
changed the title
Composite primary keys generating a correct schema
Composite primary keys generating an incorrect schema
Jun 4, 2024
Describe the bug
I'm using an entity with composite primary keys. Those primary keys are not used in the generated schema for the read-one, update-one, and delete-one queries/mutations.
Have you read the Contributing Guidelines?
Yes.
To Reproduce
Follow the installation for the example: https://tripss.github.io/nestjs-query/docs/introduction/example
Use this entity:
And this module:
Expected behavior
The schema generated is using
id: ID!
for the read-one, update-one, and delete-one queries/mutations.Generated schema
I would expect something like:
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: