Syntax

Current Supports dockerSupportsJs run handlers with this argument:

async ({
	deep, // instance of DeepClient
	gql, // gql string template tag for deep.apolloClient
	require, // require in isolation provider context
	data: {
		oldLink, // available if update or delete
		// { id, from_id, to_id, type_id }

		newLink, // available if insert or update delete
		// { id, from_id, to_id, type_id }

		promiseId, // id of promise where handle works
		// number
	},
}) => {
	// your handler code
	return {};
}

Simple example

Create a type for insert instances of which we will handle.

mutation {
  insert_links(objects: {
		type_id: 1
	}) { returning { id } }
}

Снимок экрана 2022-03-04 в 10.10.41.png

{
  "data": {
    "insert_links": {
      "returning": [
        {
          "id": 328
        }
      ]
    }
  }
}

Create SyncTextFile with script to handle insert event.

We known about types Handler and Supports, and we known about dockerSupportsJs from parent article Handlers .

Снимок экрана 2022-03-04 в 10.15.01.png

Снимок экрана 2022-03-04 в 10.26.34.png

mutation {
  insert_links(objects: {
		type_id: 30
		string: { data: { value: "() => { return { hello: 'world' } }" } },
		in: { data: {
			type_id: 35,
			from_id: 85
		} },
	}) { returning { id in { id } } }
}
{
  "data": {
    "insert_links": {
      "returning": [
        {
          "id": 330,
					"in": [{ "id": 331 }]
        }
      ]
    }
  }
}

Снимок экрана 2022-03-04 в 11.02.31.png

Attach Handler to type with HandleInsert

mutation {
  insert_links(objects: {
		type_id: 49,
		to_id: 331 # <== Handler from prev result
		from_id: 328 # <== our type
	}) { returning { id } }
}
{
  "data": {
    "insert_links": {
      "returning": [
        {
          "id": 338
        }
      ]
    }
  }
}

Снимок экрана 2022-03-04 в 11.13.36.png

Check handlers works.

mutation {
  insert_links(objects: {
		type_id: 328,
	}) {
		returning { id }
	}
}
{
  "data": {
    "insert_links": {
      "returning": [
        {
          "id": 358
        }
      ]
    }
  }
}

Снимок экрана 2022-03-04 в 19.54.47.png

Result: