# Buggy code
def resolve_category(root: models.Product, info):
    return CategoryByIdLoader(info.context).load(root.category_id)


# Traceback (TypeError)
{
"errors": [
{
"message": "The loader.load() function must be called with a value,but got: None.",
"locations": [
{
"line": 82,
"column": 3
}
],
"path": [
"productCreate",
"product",
"category"
],
"extensions": {
"exception": {
"code": "TypeError",
"stacktrace": [
"Traceback (most recent call last):",
"  File \"/Users/anders/.pyenv/versions/saleor/lib/python3.8/site-packages/promise/promise.py\", line 489, in _resolve_from_executor",
"    executor(resolve, reject)",
"  File \"/Users/anders/.pyenv/versions/saleor/lib/python3.8/site-packages/promise/promise.py\", line 756, in executor",
"    return resolve(f(*args, **kwargs))",
"  File \"/Users/anders/.pyenv/versions/saleor/lib/python3.8/site-packages/graphql/execution/middleware.py\", line 75, in make_it_promise",
"    return next(*args, **kwargs)",
"  File \"/Users/anders/projects/saleor/saleor/graphql/product/types/products.py\", line 462, in resolve_category",
"    return CategoryByIdLoader(info.context).load(root.category_id)",
"  File \"/Users/anders/.pyenv/versions/saleor/lib/python3.8/site-packages/promise/dataloader.py\", line 86, in load",
"    raise TypeError(",
"TypeError: The loader.load() function must be called with a value,but got: None."
]
}
}
}
],
"data": {
"productCreate": {
"errors": [],
"product": {
"id": "UHJvZHVjdDoxMTk=",
"attributes": [
{
"attribute": {
"id": "QXR0cmlidXRlOjIx",
"slug": "abv",
"name": "ABV",
"inputType": "DROPDOWN",
"valueRequired": false,
"values": [
{
"id": "QXR0cmlidXRlVmFsdWU6Njg=",
"name": "5.1%",
"slug": "51",
"__typename": "AttributeValue"
},
{
"id": "QXR0cmlidXRlVmFsdWU6Njk=",
"name": "6.7%",
"slug": "67",
"__typename": "AttributeValue"
},
{
"id": "QXR0cmlidXRlVmFsdWU6ODI=",
"name": "1%",
"slug": "1",
"__typename": "AttributeValue"
}
],
"__typename": "Attribute"
},
"values": [
{
"id": "QXR0cmlidXRlVmFsdWU6ODI=",
"name": "1%",
"slug": "1",
"__typename": "AttributeValue"
}
],
"__typename": "SelectedAttribute"
}
],
"productType": {
"id": "UHJvZHVjdFR5cGU6MTE=",
"variantAttributes": [],
"__typename": "ProductType",
"name": "Beer",
"hasVariants": false
},
"__typename": "Product",
"name": "piwko",
"descriptionJson": "{}",
"seoTitle": "",
"seoDescription": "",
"category": null,
"collections": [],
"basePrice": {
"amount": 0,
"currency": "USD",
"__typename": "Money"
},
"margin": {
"start": 0,
"stop": 0,
"__typename": "Margin"
},
"purchaseCost": {
"start": {
"amount": 0,
"currency": "USD",
"__typename": "Money"
},
"stop": {
"amount": 0,
"currency": "USD",
"__typename": "Money"
},
"__typename": "MoneyRange"
},
"isAvailable": false,
"isPublished": false,
"chargeTaxes": false,
"publicationDate": null,
"pricing": {
"priceRange": {
"start": {
"net": {
"amount": 0,
"currency": "USD",
"__typename": "Money"
},
"__typename": "TaxedMoney"
},
"stop": {
"net": {
"amount": 0,
"currency": "USD",
"__typename": "Money"
},
"__typename": "TaxedMoney"
},
"__typename": "TaxedMoneyRange"
},
"__typename": "ProductPricingInfo"
},
"images": [],
"variants": [
{
"id": "UHJvZHVjdFZhcmlhbnQ6MzE2",
"sku": "3123",
"name": "",
"priceOverride": null,
"margin": null,
"stocks": [
{
"id": "U3RvY2s6NjI3",
"quantity": 9,
"quantityAllocated": 0,
"warehouse": {
"id": "V2FyZWhvdXNlOmUyZjAyNDlmLTc1MzEtNDU2Ny1hODExLTM4NmY4ZGJkNzlkNQ==",
"name": "Americas",
"__typename": "Warehouse"
},
"__typename": "Stock"
}
],
"trackInventory": false,
"__typename": "ProductVariant"
}
]
},
"__typename": "ProductCreate"
}
}
}

# Fixed code
def resolve_category(root: models.Product, info):
    category_id = root.category_id
    if category_id is None:
        return None

    return CategoryByIdLoader(info.context).load(category_id)