Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust structs and GraphQL types

The same field in each shape it takes: the GraphQL type a client or agent reads, the Rust struct that holds it after conversion, and the ECC fields it comes from. The GraphQL side is schema.graphql; the Rust side is src/merchant.rs and src/merchant_api.rs for products and the generated sap::* and acme::* structs for customers.

Origin follows the book’s rule: machine data is converted by a fixed rule and never rewritten, authored text may be written by people or declared AI, none comes from another system, and personal data never reaches Merchant Center.

Product

Two Rust structs: merchant::Product is the converted ECC record (amounts as Decimal, dates as chrono), and merchant_api::ProductInput is what the Merchant API v1 receives (amounts in micros as strings, enums upper case). merchant_api::product_input turns one into the other; tests/merchant_api.rs checks every path.

GraphQL fieldGraphQL typemerchant::Product (converted)merchant_api::ProductInput (sent)OriginECC source
offerIdID!id: Stringoffer_id: StringmachineMARA-MATNR
contentLanguageString!(feed setting)content_language: String
feedLabelString!(feed setting)feed_label: String
titleStringtitle: Option<String>title: Option<String>authoredMAKT-MAKTX, MAKT-SPRAS
availabilityAvailabilityin_stock: boolavailability: &'static str (IN_STOCK / OUT_OF_STOCK)machineMARD-LABST, MARD-INSME, MARD-SPEME
priceMoneyprice: Option<Money> (amount: Decimal, currency: String, decimals: u32)price: Option<Price> (amount_micros: String, currency_code: String)machineA004, KONP, TCURX-CURRDEC
salePriceMoneysale_price: Option<Money>sale_price: Option<Price>machineA004, KONP, TCURX-CURRDEC
salePriceEffectiveDateDateIntervalsale_window: Option<(NaiveDate, NaiveDate, FixedOffset)> (inclusive, local)sale_price_effective_date: Option<Interval> (UTC, end exclusive)machineA004-DATAB, A004-DATBI
costOfGoodsSoldMoneycost: Option<Money>cost_of_goods_sold: Option<Price>machineMBEW-VPRSV, MBEW-STPRS, MBEW-VERPR, MBEW-PEINH
unitPricingMeasureMeasureunit_pricing: Option<Measure> (value: Decimal, unit)unit_pricing_measure: Option<ValueUnit> (value: f64, unit)machineMARA-INHAL, MARA-INHME
productTypes[String!]product_type: Option<String>product_types: Vec<String>machineMARA-PRDHA, T179T-VTEXT
gtins[String!]gtin: Option<String>gtins: Vec<String>machineMARM-EAN11, MARM-NUMTP, MARA-EAN11, MARA-NUMTP
mpnStringmpn: Option<String>mpn: Option<String>machineMARA-MFRPN
identifierExistsBooleanderived: identifier_exists()identifier_exists: Option<bool> (sent only as false)machineMARA-EAN11, MARA-MFRPN
itemGroupIdStringitem_group_id: Option<String>item_group_id: Option<String>machineMARA-SATNR
materialStringmaterial: Option<String>material: Option<String>authoredMARA-WRKST
productWeightMeasureproduct_weight: Option<Measure>product_weight: Option<ValueUnit>machineMARA-NTGEW, MARA-GEWEI
shippingWeightMeasureshipping_weight: Option<Measure>shipping_weight: Option<ValueUnit>machineMARA-BRGEW, MARA-GEWEI
shippingLengthMeasureshipping_dims: Option<[Measure; 3]>, [0]shipping_length: Option<ValueUnit>machineMARM-LAENG, MARM-MEABM
shippingWidthMeasureshipping_dims, [1]shipping_width: Option<ValueUnit>machineMARM-BREIT, MARM-MEABM
shippingHeightMeasureshipping_dims, [2]shipping_height: Option<ValueUnit>machineMARM-HOEHE, MARM-MEABM
shipsFromCountryString (ISO 3166-1 alpha-2)ships_from_country: Option<String>custom_attributes: Vec<CustomAttribute> (name, value)machineT001W-LAND1
versionNumberStringversion: Option<i64> (YYYYMMDDhhmmss)version_number: Option<String>machineCDHDR-UDATE, CDHDR-UTIME
description, googleProductCategory, brand, colorStringnot heldnot sent from ECCauthoredwritten by people, or AI if declared
link, imageLink, conditionString, String, Conditionnot heldnot sent from ECCnonestorefront, DAM

User

There is no single Rust User struct. User in GraphQL is assembled from the generated table structs, so each field keeps the type its DDIC field has; the resolver joins them on KNA1-ADRNR = ADDRNUMBER.

GraphQL fieldGraphQL typeRust struct and fieldRust typeOriginECC source
idID!sap::Kna1.kunnrStringmachineKNA1-KUNNR
nameStringsap::Kna1.name1StringpersonalKNA1-NAME1
emailStringsap::Adr6.smtp_addr, where flgdefault and not flg_nouseString, bool, boolpersonalADR6-SMTP_ADDR, ADR6-FLGDEFAULT, ADR6-FLG_NOUSE
phoneStringsap::Adrc.tel_numberStringpersonalADRC-TEL_NUMBER
cityStringsap::Kna1.ort01StringpersonalKNA1-ORT01
postalCodeStringsap::Kna1.pstlzStringpersonalKNA1-PSTLZ
regionStringsap::Kna1.regioStringmachineKNA1-REGIO
countryString!sap::Kna1.land1StringmachineKNA1-LAND1
languageStringsap::Kna1.spras (E → en, 3 → ko)StringmachineKNA1-SPRAS
createdOnDatesap::Kna1.erdatOption<chrono::NaiveDate>machineKNA1-ERDAT
deletedBoolean!sap::Kna1.loevmboolmachineKNA1-LOEVM
gpcSeenBooleansap::Kna1.acme_gpcboolmachineKNA1-/ACME/GPC
marketingOptIn (deprecated)Booleansap::Kna1.zz_mkt_optinboolmachineKNA1-ZZ_MKT_OPTIN
consent[Consent!]!Vec<acme::Consent> for the customersee belowmachine/ACME/CONSENT
GraphQL fieldGraphQL typeRust struct and fieldRust typeECC source
purposeString!acme::Consent.purposeString/ACME/CONSENT-PURPOSE
recordedAtDateTime!acme::Consent.recorded_atOption<chrono::NaiveDateTime>/ACME/CONSENT-RECORDED_AT
grantedBoolean!acme::Consent.grantedbool/ACME/CONSENT-GRANTED
sourceStringacme::Consent.sourceString/ACME/CONSENT-SOURCE
seqnoIntacme::Consent.seqnoi32/ACME/CONSENT-SEQNO

Google Merchant endpoints: product, loyalty, comparison shopping, reviews

Where each record goes in Google, and what of it this book builds. All four use the https://www.googleapis.com/auth/content OAuth scope, and every write names a data source (accounts/{account}/dataSources/{dataSource}).

EndpointMethod and pathVersionRust structGraphQLWhat it carriesHere
ProductPOST https://merchantapi.googleapis.com/products/v1/{parent=accounts/*}/productInputs:insert?dataSource=...; the processed product is read back with GET .../products/v1/accounts/{account}/products/{contentLanguage~feedLabel~offerId}v1merchant_api::ProductInputProductThe converted ECC product: identifiers, prices, stock, units, dimensions, versionNumberBuilt: src/merchant_api.rs, tests/merchant_api.rs. Nothing sends yet.
LoyaltyNo endpoint of its own: productAttributes.loyaltyPrograms[] on the same productInputs:insert. Loyalty shipping is set on accounts/{account}/shippingSettings. The program must first be linked in Merchant Center.v1not built: would be ProductAttributes.loyalty_programs: Vec<LoyaltyProgram>not built: would be Product.loyaltyProgramsPer tier: programLabel, tierLabel, member price (no higher than the regular price), cashbackForFutureUse, loyaltyPoints, memberPriceEffectiveDate, shippingLabelNot built. A member price would come from its own SAP condition type, converted like price. Program data, not personal data: who is a member stays on User.
Comparison shoppingPOST https://css.googleapis.com/v1/{parent=accounts/*}/cssProductInputs:insert: the separate CSS API, for comparison shopping services listing other merchants’ productsv1not builtnot builtA product input keyed by contentLanguage, feedLabel (the target country, e.g. DE) and identity; feedId is deprecatedNot built. Applies only when acting as, or supplying, a comparison shopping service. One-time API registration required.
ReviewsPOST https://merchantapi.googleapis.com/reviews/v1beta/{parent=accounts/*}/productReviews:insert?dataSource=... and .../merchantReviews:insert?dataSource=..., with get, list and deletev1betanot builtnot builtRating, title, content, review time, language and country, isVerifiedPurchase, isIncentivizedReview, and the reviewer (reviewerId, reviewerUsername, isAnonymous)Not built. Reviews come from the storefront or a review platform, not ECC. The reviewer is personal data: it belongs with User, under consent, never in Product. Requires a review data source and enrolment in the product ratings programme.

Two rules follow from the table:

  • Loyalty and reviews ride on the product, not the person. A member price is a fact about the product and the tier; a review is attached to the product’s identifiers. The person behind either (the member, the reviewer) stays on User, and leaves only through the release gate.
  • Beta means it can change. Reviews are v1beta; Google says beta versions are subject to change or removal. Product and loyalty are on v1.

Sources: Products: add and manage, ProductAttributes (v1), including loyaltyPrograms, loyalty_program in the product data specification, CSS API: cssProductInputs.insert, Reviews: product reviews, Reviews: merchant reviews, Merchant API design and versioning.

Where the types differ, and why

  • Amounts: Decimal in Rust keeps SAP’s scale exactly (258.00); GraphQL and the Merchant API carry micros as a string, because int64 doesn’t fit a JSON number safely.
  • Dates: Rust holds what ECC means (a local sale window, inclusive); the API gets UTC with an exclusive end.
  • Lists: ECC holds one GTIN and one product type per row; Google takes lists, so the converter wraps them.
  • Optional vs required: ABAP has no null. A Rust Option is None only where ECC’s initial value means “not set” (00000000 dates); GraphQL’s non-null ! marks the fields a resolver must always return.
  • Personal data: only User holds it. Nothing in Product, merchant::Product or ProductInput can carry a name, e-mail or phone, so a product feed can’t leak one.