Creating metaobjects in my app

Hello there,

I’m working on my first shopify app. It’s an embedded app, and I’m using the older node/express template. I’m trying to create a metaobject, that will use data entered by the user in my react front end, to populate an app block in liquid. I’ve written my frontend code, and I’ve written code in my server file (index.js) to create a metaobject definition. Here’s the relevant bit from my front end, it’s a handler function after a button press:

function saveHandler(){
    console.log('saving...');

    (async() => {
      try {
        //await fetch('/api/create-metaobject-definition')
        await authenticatedFetch("/api/create-metaobject-definition", {
          method: "POST",
          body: JSON.stringify({
            discount: {
              ...discount,
              title: form.discountCode,
              code: form.discountCode,
            },
          }),
        });
        console.log('success')
      }
      catch(err){
        console.log(err)
      }
    })();
  }

The "discount: { … } " part is not relevant, it’s from the tutorial app I was looking at which was creating a discount app. I need to put something there however, as removing the “body” in the fetch gives me an oauth error in my development store. The tutorial I was following wasn’t trying to create a metaobject. Here is the relevant backend code:

const CREATE_CODE_MUTATION = `mutation {
  metaobjectDefinitionCreate(definition: {
      type: "$app:cart_app_block",
      access: {
          admin: MERCHANT_READ_WRITE,
          storefront: PUBLIC_READ
      },

....

}`

app.post('/api/create-metaobject-definition', async(req, res)=>{
  await createMetaobjectDefinitions(req, res, CREATE_CODE_MUTATION);
});

const createMetaobjectDefinitions = async(req, res, mutation) => {
  const session = res.locals.shopify.session
  const client = new shopify.api.clients.Graphql(session);
  const data = await client.query({
    data: {
      query: mutation
    }
  });
  res.send(data.body)
}

So I’d like to know if my approach is correct, and if so what could I add to the body of my fetch. I would have thought that nothing needs to be added since we’re creating the metaobject definition, and the relevant data from the front end wouldn’t be needed till the metaobject itself is created later on.

ps. I found this post https://community.shopify.com/topic/2543593 and it seems that they placed the mutation into the body of the fetch request. Not sure if this is the correct way. Anyways any help and guidance would be greatly appreciated. Cheers - Dak