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

Shop-API Error: Cannot Load Relation Type Custom Fields #2775

Closed
ban-am opened this issue Apr 9, 2024 · 1 comment
Closed

Shop-API Error: Cannot Load Relation Type Custom Fields #2775

ban-am opened this issue Apr 9, 2024 · 1 comment
Assignees
Labels
type: bug 🐛 Something isn't working @vendure/core

Comments

@ban-am
Copy link

ban-am commented Apr 9, 2024

Describe the bug
When querying the activeOrder with custom relation fields on the OrderLine entity, the shop-api throws an error: Cannot read properties of undefined (reading 'filter'.
This issue occure only when eager: true.
This issue does not occur with the admin-api order(id: $id) query.
No stack trace in the server logs.

To Reproduce

  1. Define custom ProductVariant fields for `OrderLine.
customFields: {
    OrderLine: [
      {
        name: 'material',
        type: 'relation',
        entity: ProductVariant,
        eager: true,
        nullable: true,
        public: true
      },
    ],
  }
  1. Create order
# shop-api

mutation addItemToOrder($productVariantId: ID!, $quantity: Int!, $customFields: OrderLineCustomFieldsInput!) {
  addItemToOrder(productVariantId: $productVariantId, quantity: $quantity, customFields: $customFields) {
    __typename
  }
}
# Query Variables
{
  "productVariantId": "1", 
  "quantity": 1, 
  "customFields": {
    "materialId": "2"
  }
}
  1. Query activeOrder using the shop-api with the custom fields.
query activeOrder {
  activeOrder {
    __typename
    lines {
      customFields {
        material {
          __typename
        }
      }
    }
  }

Expected behavior
The shop-api should load the relation type custom fields without any errors, similar to the admin-api.

Environment (please complete the following information):

  • @vendure/core version: 2.1.9, 2.2.0-next.8 also tested
  • Nodejs version: v18.20.1
  • Database: postgres

Additional context
Repository https://github.com/ban-am/order-line-custom-relation-field-error

@ban-am
Copy link
Author

ban-am commented Apr 10, 2024

While debugging the core package, I discovered that the method this.orderService.findOne(ctx, sessionOrder.id), invoked by activeOrder, successfully retrieves the custom field value. This same method is also called within the context of order(id: xxx) in the admin API. However, when the shop API makes a request, it results in an error, but the admin does not. Additionally, none of the middleware reported any errors. I’m uncertain about the next steps to take in troubleshooting this issue.

@michaelbromley michaelbromley moved this from 📋 Backlog to 🔖 Ready in Vendure OS Roadmap Apr 25, 2024
@michaelbromley michaelbromley moved this from 🔖 Ready to ✅ Done in Vendure OS Roadmap Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working @vendure/core
Projects
Status: 🚀 Shipped
Development

No branches or pull requests

2 participants