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

feat(admin,shop): enable tags on assets for shop api #1754

Conversation

julien-monchany
Copy link
Contributor

Enable to retrieve tags on asset for the shop API

  • remove the admin-api specificity
  • add tags on common asset type

@michaelbromley
Copy link
Member

Hi Julien!

Thanks for the contribution. Can you give a bit of detail about your use-case on why you want to use tags in the shop api? I'd like to get a good understanding so I can judge this feature better.

My only concern is if users are using tagging currently to store non-public data.

@julien-monchany
Copy link
Contributor Author

Hello @michaelbromley 👋

We have products with several assets, and we wish to display only some of them on the product page, and use others in a different checkout step.

As we need to retrieve all of them, we thought using the tags to differentiate them.

@julien-monchany
Copy link
Contributor Author

Hi @michaelbromley, have you seen my previous message? 🙏

@michaelbromley
Copy link
Member

Hi @julien-monchany, yes thanks. I've been unusually busy these part weeks so didn't get a chance to triage all the open issues.

So I'm going to leave this under consideration for the time being until I have a bit more time to dedicate to working through issues. I trust that your own use-case is not blocked, since you can implement this feature with a plugin which extends the type.

@julien-monchany
Copy link
Contributor Author

Hello @michaelbromley 👋
did you have time to look at this pull request? 🙏

@michaelbromley michaelbromley merged commit d9316df into vendure-ecommerce:minor Dec 15, 2022
@michaelbromley
Copy link
Member

Thanks, and apologies for the long silence. I'm not sure when this change will be released - most likely only on v2.0 (or its pre-releases).

@jakubnavratil
Copy link

I'm getting Cannot return null for non-nullable field Asset.tags.

Version 2.0.2 after migration from v1. Interesting is, that all assets on product have tags (shows in admin).

@michaelbromley
Copy link
Member

Hi @jakubnavratil, can you share the query which results in that error message?

@jakubnavratil
Copy link

jakubnavratil commented Jun 28, 2023

Ho @michaelbromley , from what I can tell, there is no query for tags. Maybe thats the problem.

SELECT
    `product`.`id` AS `id`,
    CASE
        `translation`.`languageCode`
        WHEN 'cs' THEN 2
        WHEN 'cs' THEN 1
        ELSE 0
    END AS `sort_order`
FROM
    `product` `product`
    LEFT JOIN `product_translation` `translation` ON `translation`.`baseId` = `product`.`id`
WHERE
    `product`.`deletedAt` IS NULL
    AND `product`.`id` IN (
        SELECT
            `_product_translation`.`baseId`
        FROM
            `product_translation` `_product_translation`
        WHERE
            `_product_translation`.`slug` = ?
    )
ORDER BY
    sort_order DESC -- PARAMETERS: ["abc"]

SELECT
    `entity`.`createdAt` AS `entity_createdAt`,
    `entity`.`updatedAt` AS `entity_updatedAt`,
    `entity`.`deletedAt` AS `entity_deletedAt`,
    `entity`.`enabled` AS `entity_enabled`,
    `entity`.`id` AS `entity_id`,
    `entity`.`featuredAssetId` AS `entity_featuredAssetId`,
    `entity`.`customFieldsShortdescription` AS `entity_customFieldsShortdescription`,
    `entity`.`customFieldsNameen` AS `entity_customFieldsNameen`,
    `entity`.`customFieldsNamede` AS `entity_customFieldsNamede`,
    `entity`.`customFieldsVydatnost` AS `entity_customFieldsVydatnost`,
    `entity`.`customFieldsVaha` AS `entity_customFieldsVaha`,
    `entity`.`customFieldsKapacita` AS `entity_customFieldsKapacita`,
    `entity_translations`.`createdAt` AS `entity_translations_createdAt`,
    `entity_translations`.`updatedAt` AS `entity_translations_updatedAt`,
    `entity_translations`.`languageCode` AS `entity_translations_languageCode`,
    `entity_translations`.`name` AS `entity_translations_name`,
    `entity_translations`.`slug` AS `entity_translations_slug`,
    `entity_translations`.`description` AS `entity_translations_description`,
    `entity_translations`.`id` AS `entity_translations_id`,
    `entity_translations`.`baseId` AS `entity_translations_baseId`
FROM
    `product` `entity`
    LEFT JOIN `product_translation` `entity_translations` ON `entity_translations`.`baseId` = `entity`.`id`
    LEFT JOIN `product_channels_channel` `entity___channel` ON `entity___channel`.`productId` = `entity`.`id`
    LEFT JOIN `channel` `__channel` ON `__channel`.`id` = `entity___channel`.`channelId`
WHERE
    (`entity`.`deletedAt` IS NULL)
    AND `entity`.`id` = ?
    AND `__channel`.`id` = ? -- PARAMETERS: [1,1]

SELECT
    `entity`.`createdAt` AS `entity_createdAt`,
    `entity`.`updatedAt` AS `entity_updatedAt`,
    `entity`.`deletedAt` AS `entity_deletedAt`,
    `entity`.`enabled` AS `entity_enabled`,
    `entity`.`id` AS `entity_id`,
    `entity`.`featuredAssetId` AS `entity_featuredAssetId`,
    `entity`.`customFieldsShortdescription` AS `entity_customFieldsShortdescription`,
    `entity`.`customFieldsNameen` AS `entity_customFieldsNameen`,
    `entity`.`customFieldsNamede` AS `entity_customFieldsNamede`,
    `entity`.`customFieldsVydatnost` AS `entity_customFieldsVydatnost`,
    `entity`.`customFieldsVaha` AS `entity_customFieldsVaha`,
    `entity`.`customFieldsKapacita` AS `entity_customFieldsKapacita`,
    `orderable_asset`.`createdAt` AS `orderable_asset_createdAt`,
    `orderable_asset`.`updatedAt` AS `orderable_asset_updatedAt`,
    `orderable_asset`.`assetId` AS `orderable_asset_assetId`,
    `orderable_asset`.`position` AS `orderable_asset_position`,
    `orderable_asset`.`productId` AS `orderable_asset_productId`,
    `orderable_asset`.`id` AS `orderable_asset_id`,
    `asset`.`createdAt` AS `asset_createdAt`,
    `asset`.`updatedAt` AS `asset_updatedAt`,
    `asset`.`name` AS `asset_name`,
    `asset`.`type` AS `asset_type`,
    `asset`.`mimeType` AS `asset_mimeType`,
    `asset`.`width` AS `asset_width`,
    `asset`.`height` AS `asset_height`,
    `asset`.`fileSize` AS `asset_fileSize`,
    `asset`.`source` AS `asset_source`,
    `asset`.`preview` AS `asset_preview`,
    `asset`.`focalPoint` AS `asset_focalPoint`,
    `asset`.`id` AS `asset_id`,
    `asset_channel`.`createdAt` AS `asset_channel_createdAt`,
    `asset_channel`.`updatedAt` AS `asset_channel_updatedAt`,
    `asset_channel`.`code` AS `asset_channel_code`,
    `asset_channel`.`token` AS `asset_channel_token`,
    `asset_channel`.`description` AS `asset_channel_description`,
    `asset_channel`.`defaultLanguageCode` AS `asset_channel_defaultLanguageCode`,
    `asset_channel`.`availableLanguageCodes` AS `asset_channel_availableLanguageCodes`,
    `asset_channel`.`defaultCurrencyCode` AS `asset_channel_defaultCurrencyCode`,
    `asset_channel`.`availableCurrencyCodes` AS `asset_channel_availableCurrencyCodes`,
    `asset_channel`.`trackInventory` AS `asset_channel_trackInventory`,
    `asset_channel`.`outOfStockThreshold` AS `asset_channel_outOfStockThreshold`,
    `asset_channel`.`pricesIncludeTax` AS `asset_channel_pricesIncludeTax`,
    `asset_channel`.`id` AS `asset_channel_id`,
    `asset_channel`.`sellerId` AS `asset_channel_sellerId`,
    `asset_channel`.`defaultTaxZoneId` AS `asset_channel_defaultTaxZoneId`,
    `asset_channel`.`defaultShippingZoneId` AS `asset_channel_defaultShippingZoneId`
FROM
    `product` `entity`
    LEFT JOIN `product_asset` `orderable_asset` ON `orderable_asset`.`productId` = `entity`.`id`
    LEFT JOIN `asset` `asset` ON `asset`.`id` = `orderable_asset`.`assetId`
    LEFT JOIN `asset_channels_channel` `asset_asset_channel` ON `asset_asset_channel`.`assetId` = `asset`.`id`
    LEFT JOIN `channel` `asset_channel` ON `asset_channel`.`id` = `asset_asset_channel`.`channelId`
WHERE
    `entity`.`id` = ?
    AND `asset_channel`.`id` = ? -- PARAMETERS: [1,1]

Used graphql query:

query {
  product(slug:"abc") {
    id
    name
    assets {
    	id
        name
        tags {
          id
          value
        }
    }
  }
}

@michaelbromley
Copy link
Member

@jakubnavratil ah ok thanks. Now I see the issue - the AssetEntityResolver is only registered with the Admin API and not the Shop API. I'll fix that.

michaelbromley added a commit that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🚀 Shipped
Development

Successfully merging this pull request may close these issues.

3 participants