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

GraphQL: Product and User

Two GraphQL shapes generated from the same map as the Rust structs and the Google Merchant Center chapter. Product attributes follow Google’s product data specification.

  • Product has one field per Merchant attribute, named and typed like the Merchant API v1 product input (price: Money in micros, availability: Availability, gtins: [String!]). 18 of its fields are machine data.
  • User is the customer: KNA1 with its address and default e-mail, and the consent ledger. 5 of its fields are personal data, so User is a separate type: nothing personal is reachable from Product, and nothing in User is sent to Merchant Center.

Every field carries @source(ecc: [...], origin: ...), so a resolver, a reviewer or an agent can see where a value comes from and whether it may be rewritten. marketingOptIn is @deprecated: it is a flag a nightly batch can overwrite, so clients read consent (newest row per purpose wins) instead.

Fields

TypeFieldGraphQL typeOriginECC source
ProductofferIdID!machineMARA-MATNR
ProducttitleStringauthoredMAKT-MAKTX
MAKT-SPRAS
ProductdescriptionStringauthored
ProductlinkStringnone
ProductimageLinkStringnone
ProductavailabilityAvailabilitymachineMARD-LABST
MARD-INSME
MARD-SPEME
ProductpriceMoneymachineA004-KSCHL
A004-DATAB
A004-DATBI
KONP-KBETR
KONP-KPEIN
KONP-KONWA
KONP-LOEVM_KO
TCURX-CURRDEC
ProductsalePriceMoneymachineA004-KSCHL
A004-DATAB
A004-DATBI
KONP-KBETR
KONP-KPEIN
KONP-KONWA
TCURX-CURRDEC
ProductsalePriceEffectiveDateDateIntervalmachineA004-DATAB
A004-DATBI
ProductcostOfGoodsSoldMoneymachineMBEW-VPRSV
MBEW-STPRS
MBEW-VERPR
MBEW-PEINH
ProductunitPricingMeasureMeasuremachineMARA-INHAL
MARA-INHME
ProductgoogleProductCategoryStringauthoredMARA-MATKL
ProductproductTypes[String!]machineMARA-PRDHA
T179T-PRODH
T179T-VTEXT
ProductbrandStringauthoredMARA-MFRNR
Productgtins[String!]machineMARM-EAN11
MARM-NUMTP
MARA-EAN11
MARA-NUMTP
ProductmpnStringmachineMARA-MFRPN
ProductidentifierExistsBooleanmachineMARA-EAN11
MARA-MFRPN
ProductitemGroupIdStringmachineMARA-SATNR
ProductmaterialStringauthoredMARA-WRKST
ProductcolorStringauthored
ProductconditionConditionnone
ProductproductWeightMeasuremachineMARA-NTGEW
MARA-GEWEI
ProductshippingWeightMeasuremachineMARA-BRGEW
MARA-GEWEI
ProductshippingLengthMeasuremachineMARM-LAENG
MARM-MEABM
ProductshippingWidthMeasuremachineMARM-BREIT
MARM-MEABM
ProductshippingHeightMeasuremachineMARM-HOEHE
MARM-MEABM
ProductshipsFromCountryStringmachineT001W-LAND1
UseridID!machineKNA1-KUNNR
UsernameStringpersonalKNA1-NAME1
UseremailStringpersonalADR6-SMTP_ADDR
ADR6-FLGDEFAULT
ADR6-FLG_NOUSE
UserphoneStringpersonalADRC-TEL_NUMBER
UsercityStringpersonalKNA1-ORT01
UserpostalCodeStringpersonalKNA1-PSTLZ
UserregionStringmachineKNA1-REGIO
UsercountryString!machineKNA1-LAND1
UserlanguageStringmachineKNA1-SPRAS
UsercreatedOnDatemachineKNA1-ERDAT
UserdeletedBoolean!machineKNA1-LOEVM
UsergpcSeenBooleanmachineKNA1-/ACME/GPC
UsermarketingOptInBooleanmachineKNA1-ZZ_MKT_OPTIN
Userconsent[Consent!]!machine/ACME/CONSENT

Schema

schema.graphql in the repository; tests/graphql.rs parses it.

# @generated from site/ddic.json by src/codegen.rs. Do not edit.

"""Where a field's value comes from, and who may change it."""
directive @source(
  """Attribute name in the product data specification."""
  attribute: String
  """ECC tables and fields it is converted from."""
  ecc: [String!]!
  origin: Origin!
) on FIELD_DEFINITION

enum Origin {
  """A code, identifier, amount, unit, date or quantity ECC holds: converted by rule, never rewritten."""
  MACHINE
  """Text a person writes. AI-written text must be declared (digital_source_type)."""
  AUTHORED
  """Owned by another system."""
  NONE
  """Personal data: served only to the customer or a permitted purpose, never sent to Merchant Center."""
  PERSONAL
}

scalar Date
scalar DateTime

"""A product, shaped like a Merchant API v1 product input. Attributes: https://support.google.com/merchants/answer/7052112"""
type Product {
  """ISO 639-1, e.g. en."""
  contentLanguage: String!
  """A-Z, 0-9, - and _; up to 20."""
  feedLabel: String!
  offerId: ID! @source(attribute: "id", ecc: ["MARA-MATNR"], origin: MACHINE)
  title: String @source(attribute: "title", ecc: ["MAKT-MAKTX", "MAKT-SPRAS"], origin: AUTHORED)
  description: String @source(attribute: "description", ecc: [], origin: AUTHORED)
  link: String @source(attribute: "link", ecc: [], origin: NONE)
  imageLink: String @source(attribute: "image_link", ecc: [], origin: NONE)
  availability: Availability @source(attribute: "availability", ecc: ["MARD-LABST", "MARD-INSME", "MARD-SPEME"], origin: MACHINE)
  price: Money @source(attribute: "price", ecc: ["A004-KSCHL", "A004-DATAB", "A004-DATBI", "KONP-KBETR", "KONP-KPEIN", "KONP-KONWA", "KONP-LOEVM_KO", "TCURX-CURRDEC"], origin: MACHINE)
  salePrice: Money @source(attribute: "sale_price", ecc: ["A004-KSCHL", "A004-DATAB", "A004-DATBI", "KONP-KBETR", "KONP-KPEIN", "KONP-KONWA", "TCURX-CURRDEC"], origin: MACHINE)
  salePriceEffectiveDate: DateInterval @source(attribute: "sale_price_effective_date", ecc: ["A004-DATAB", "A004-DATBI"], origin: MACHINE)
  costOfGoodsSold: Money @source(attribute: "cost_of_goods_sold", ecc: ["MBEW-VPRSV", "MBEW-STPRS", "MBEW-VERPR", "MBEW-PEINH"], origin: MACHINE)
  unitPricingMeasure: Measure @source(attribute: "unit_pricing_measure", ecc: ["MARA-INHAL", "MARA-INHME"], origin: MACHINE)
  googleProductCategory: String @source(attribute: "google_product_category", ecc: ["MARA-MATKL"], origin: AUTHORED)
  productTypes: [String!] @source(attribute: "product_type", ecc: ["MARA-PRDHA", "T179T-PRODH", "T179T-VTEXT"], origin: MACHINE)
  brand: String @source(attribute: "brand", ecc: ["MARA-MFRNR"], origin: AUTHORED)
  gtins: [String!] @source(attribute: "gtin", ecc: ["MARM-EAN11", "MARM-NUMTP", "MARA-EAN11", "MARA-NUMTP"], origin: MACHINE)
  mpn: String @source(attribute: "mpn", ecc: ["MARA-MFRPN"], origin: MACHINE)
  identifierExists: Boolean @source(attribute: "identifier_exists", ecc: ["MARA-EAN11", "MARA-MFRPN"], origin: MACHINE)
  itemGroupId: String @source(attribute: "item_group_id", ecc: ["MARA-SATNR"], origin: MACHINE)
  material: String @source(attribute: "material", ecc: ["MARA-WRKST"], origin: AUTHORED)
  color: String @source(attribute: "color", ecc: [], origin: AUTHORED)
  condition: Condition @source(attribute: "condition", ecc: [], origin: NONE)
  productWeight: Measure @source(attribute: "product_weight", ecc: ["MARA-NTGEW", "MARA-GEWEI"], origin: MACHINE)
  shippingWeight: Measure @source(attribute: "shipping_weight", ecc: ["MARA-BRGEW", "MARA-GEWEI"], origin: MACHINE)
  shippingLength: Measure @source(attribute: "shipping_length", ecc: ["MARM-LAENG", "MARM-MEABM"], origin: MACHINE)
  shippingWidth: Measure @source(attribute: "shipping_width", ecc: ["MARM-BREIT", "MARM-MEABM"], origin: MACHINE)
  shippingHeight: Measure @source(attribute: "shipping_height", ecc: ["MARM-HOEHE", "MARM-MEABM"], origin: MACHINE)
  shipsFromCountry: String @source(attribute: "ships_from_country", ecc: ["T001W-LAND1"], origin: MACHINE)
  """Newest change document for the material (CDHDR), YYYYMMDDhhmmss: an older write can't replace a newer one."""
  versionNumber: String @source(ecc: ["CDHDR-UDATE", "CDHDR-UTIME"], origin: MACHINE)
}

"""Micros: 1 000 000 = one unit of the currency. KRW and JPY are already shifted from SAP's 2 stored decimals."""
type Money {
  amountMicros: String!
  """ISO 4217."""
  currencyCode: String!
}

"""UTC; endTime is exclusive."""
type DateInterval {
  startTime: DateTime!
  endTime: DateTime!
}

type Measure {
  value: Float!
  """Google's unit: g, kg, oz, lb, cm, in, ml, l, ..."""
  unit: String!
}

enum Availability {
  IN_STOCK
  OUT_OF_STOCK
  PREORDER
  BACKORDER
  LIMITED_AVAILABILITY
}

enum Condition {
  NEW
  USED
  REFURBISHED
}

"""A customer (KNA1 with its address and e-mail) and their consent. Personal data stays here: it is not part of Product."""
type User {
  """Customer number as SAP displays it (leading zeros dropped for all-digit numbers)."""
  id: ID! @source(ecc: ["KNA1-KUNNR"], origin: MACHINE)
  """Name 1 of the customer master."""
  name: String @source(ecc: ["KNA1-NAME1"], origin: PERSONAL)
  """The default e-mail address (FLGDEFAULT) that is not marked do-not-use (FLG_NOUSE); ADR6 is reached through KNA1-ADRNR."""
  email: String @source(ecc: ["ADR6-SMTP_ADDR", "ADR6-FLGDEFAULT", "ADR6-FLG_NOUSE"], origin: PERSONAL)
  """Telephone from the business address."""
  phone: String @source(ecc: ["ADRC-TEL_NUMBER"], origin: PERSONAL)
  """City."""
  city: String @source(ecc: ["KNA1-ORT01"], origin: PERSONAL)
  """Postal code."""
  postalCode: String @source(ecc: ["KNA1-PSTLZ"], origin: PERSONAL)
  """Region code (ISO 3166-2 subdivision once prefixed with the country)."""
  region: String @source(ecc: ["KNA1-REGIO"], origin: MACHINE)
  """ISO 3166-1 alpha-2."""
  country: String! @source(ecc: ["KNA1-LAND1"], origin: MACHINE)
  """BCP 47 from the one-character SAP language key (E → en / 3 → ko)."""
  language: String @source(ecc: ["KNA1-SPRAS"], origin: MACHINE)
  """Created on."""
  createdOn: Date @source(ecc: ["KNA1-ERDAT"], origin: MACHINE)
  """Central deletion flag: a deleted customer is not served."""
  deleted: Boolean! @source(ecc: ["KNA1-LOEVM"], origin: MACHINE)
  """Global Privacy Control was received."""
  gpcSeen: Boolean @source(ecc: ["KNA1-/ACME/GPC"], origin: MACHINE)
  marketingOptIn: Boolean @source(ecc: ["KNA1-ZZ_MKT_OPTIN"], origin: MACHINE) @deprecated(reason: "a flag a batch job can overwrite. Read consent instead.")
  """The append-only consent ledger for this customer; the newest row per purpose wins."""
  consent: [Consent!]! @source(ecc: ["/ACME/CONSENT"], origin: MACHINE)
}

"""One row of /ACME/CONSENT: append-only, the newest row per purpose wins."""
type Consent {
  purpose: String! @source(ecc: ["/ACME/CONSENT-PURPOSE"], origin: MACHINE)
  recordedAt: DateTime! @source(ecc: ["/ACME/CONSENT-RECORDED_AT"], origin: MACHINE)
  granted: Boolean! @source(ecc: ["/ACME/CONSENT-GRANTED"], origin: MACHINE)
  source: String @source(ecc: ["/ACME/CONSENT-SOURCE"], origin: MACHINE)
  seqno: Int @source(ecc: ["/ACME/CONSENT-SEQNO"], origin: MACHINE)
}

type Query {
  product(offerId: ID!, contentLanguage: String!, feedLabel: String!): Product
  """Served only to the customer themself or for a permitted purpose."""
  user(id: ID!): User
}

Example

The same sample material as the Merchant chapter, and the sample customer from fixtures/records/kna1.json, adr6.json and acme_consent.json. tests/graphql.rs checks that every key in these responses is a field of the schema.

query {
  product(offerId: "HM-QUEEN-01", contentLanguage: "en", feedLabel: "US") {
    offerId title availability
    price { amountMicros currencyCode }
    salePrice { amountMicros currencyCode }
    salePriceEffectiveDate { startTime endTime }
    gtins mpn identifierExists productTypes
    shippingWeight { value unit }
    shipsFromCountry versionNumber
  }
}
{
  "data": {
    "product": {
      "availability": "IN_STOCK",
      "gtins": [
        "012345678905"
      ],
      "identifierExists": true,
      "mpn": "HM-Q-2026",
      "offerId": "HM-QUEEN-01",
      "price": {
        "amountMicros": "129000000",
        "currencyCode": "USD"
      },
      "productTypes": [
        "Home > Heating > Heated mats"
      ],
      "salePrice": {
        "amountMicros": "109000000",
        "currencyCode": "USD"
      },
      "salePriceEffectiveDate": {
        "endTime": "2026-12-01T08:00:00Z",
        "startTime": "2026-11-01T08:00:00Z"
      },
      "shippingWeight": {
        "unit": "kg",
        "value": 9.8
      },
      "shipsFromCountry": "US",
      "title": "Heated mat, queen",
      "versionNumber": "20261103021500"
    }
  }
}
query {
  user(id: "12345") {
    id name email country region language createdOn deleted gpcSeen marketingOptIn
    consent { purpose recordedAt granted source seqno }
  }
}
{
  "data": {
    "user": {
      "consent": [
        {
          "granted": false,
          "purpose": "ads",
          "recordedAt": "2026-11-04T10:05:00Z",
          "seqno": 0,
          "source": "dsr"
        },
        {
          "granted": true,
          "purpose": "ads",
          "recordedAt": "2026-11-04T10:02:00Z",
          "seqno": 0,
          "source": "banner"
        }
      ],
      "country": "US",
      "createdOn": "2024-01-15",
      "deleted": false,
      "email": "orders@example.com",
      "gpcSeen": false,
      "id": "12345",
      "language": "en",
      "marketingOptIn": true,
      "name": "Example Retail Inc.",
      "region": "CA"
    }
  }
}

consent returns the ledger; the 10:05 withdrawal (dsr) is newer than the 10:02 grant, so ads consent is withdrawn. marketingOptIn still says true: that is the stale batch-written flag the schema deprecates.