How do i get metafields from a "discountAutomaticAppCreate" function

Hello, I have created a Shopify CLI Discount shipping - Function

The function works perfectly fine, it applies the discounts and I can read the metadata in the run.ts from the graphql.ts

However, I need the metafield(s) in the admin interface as well but they don’t show up when I query with graphql?

This is the query:

query {
  discountNodes(query: "type:app AND method:automatic", first: 10) {
    nodes {
      id
      metafields(
        namespace: "$app:discount-shipping",
        first: 10
      ){
        nodes{
          jsonValue
        }
      }
      metafield(namespace: "$app:discount-shipping", key: "function-configuration") {
        jsonValue
      }
      discount {
        ... on DiscountAutomaticApp {
          __typename
          title
          startsAt
          endsAt
          endsAt
          status
          asyncUsageCount
          appliesOnSubscription
          discountId
          status
          appDiscountType {
          	title
            functionId
            description
        	}
          combinesWith {
            orderDiscounts
            productDiscounts
            shippingDiscounts
          }
        }
      }
    }
  }
}

I create the resource/node like so:

const automaticDiscount = await discountAutomaticAppCreate(
    admin,
    shippingDiscountFunctionId,
    "$app:discount-shipping",
    "function-configuration",
    discountTitle,
    discountStart,
    discountEnd,
    discountCombinesProducts === 'true',
    discountCombinesOrders === 'true',
    JSON.stringify({
        targetSetting: targetSetting,
        discountValue: Number(discountValue),
        discountType: discountType,
    })
);

And the helper method looks like this:

export async function discountAutomaticAppCreate(
    admin: AdminApiContext

As mentioned above, the creation works, and the discount works, I can confirm the metafields are being used in the **Shopify Partners->Ingsights->functions->myfunction**

Here I can see the script has the metafield in the success input:

{ “cart”: { “deliveryGroups”: [ {
“id”: “gid://shopify/CartDeliveryGroup/0”, “deliveryOptions”: [ {
“cost”: { “amount”: “49.0”, “currencyCode”: “DKK”
}
},
{
“cost”: { “amount”: “666.0”, “currencyCode”: “DKK”
}
}
]
}
],
“cost”: { “subtotalAmount”: { “amount”: “7500.0”, “currencyCode”: “DKK”
}
}
},
“discountNode”: { “metafield”: { “jsonValue”: { “targetSetting”: “5555”, “discountValue”: 0, “discountType”: “free”
}
}
}
}


How do I get the metadata added to my query response in my admin panel with the helper function specified above?

Heads up, if i change the namespace at creation from “$app:discount-shipping” to a random string like: test_meta_field_test and use that in my query, then I get the metafields!

But that’s not very generic/dynamic? that means I have to hardcode this none app specific namespace to my run.graphql too… Is there really no way to get the app specific metafield ?

hey did you found something ?