Skip to content

Instantly share code, notes, and snippets.

@olivier5741
Created January 13, 2022 08:36
Show Gist options
  • Save olivier5741/d4c7968b2fae43209f295fc50ab42ec5 to your computer and use it in GitHub Desktop.
Save olivier5741/d4c7968b2fae43209f295fc50ab42ec5 to your computer and use it in GitHub Desktop.
Short distribution channel product schema through graphQL.

Short distribution channel product schema through graphQL

How to query a product based on its

  • contributors (or main contributors based on their role: Producer, Transformer)
  • categories (a category is part of a classification : GPC, OFN instance classification)
  • ingredients

The proposed graphQL solution :

product-contribution-category

The query :

query Products_with_sugar_from_main_producer_contributors_in_Belgium_classified_as_biscuits_by_OFN { 
  products(where: { 
    contributions_some: {
      isMain: true
      roles_contains_some: [Producer]
      actor: 
      { 
        address: { country: { code:"BE" } } 
      }
    }
    categories_some: {
      name: "Biscuits"
      classification: {
        name: "OFNBE"
      }
    }
    ingredients_some: {
      name: "sucre"
    }
  })
  {
    name
    categories{
      name
      hierarchyLevel
      classification{
        name
      }
    }
    contributions{
      isMain
      roles
      actor{
        name
      }
    }
    ingredients{
      name
    }
  }
}

gives

{
  "data": {
    "products": [
      {
        "name": "Spéculoos",
        "categories": [
          {
            "name": "Food",
            "hierarchyLevel": 1,
            "classification": {
              "name": "OFNBE"
            }
          },
          {
            "name": "Biscuits",
            "hierarchyLevel": 2,
            "classification": {
              "name": "OFNBE"
            }
          }
        ],
        "contributions": [
          {
            "isMain": true,
            "roles": [
              "Transformer"
            ],
            "actor": {
              "name": "Mon entreprise"
            }
          },
          {
            "isMain": false,
            "roles": [
              "Packer"
            ],
            "actor": {
              "name": "Ukraine enterprise"
            }
          }
        ],
        "ingredients": [
          {
            "name": "Farine de blé"
          },
          {
            "name": "sucre"
          }
        ]
      }
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment