version: 2
title: Data Enrichment with Webhooks
contributor: https://github.com/mastapegs
summary: Stream numbers into graph and notify HTTP endpoint to enrich graph
description: |-
  This recipe will stream numbers into the graph and stream them out to an HTTP endpoint, which will
  then calculate the factors of those numbers, and create relationships between the numbers and their
  factors.

ingestStreams:
  - name: number-iterator
    source:
      type: NumberIterator
      startOffset: 1
      limit: 13
    query: |-
      WITH toInteger($that) AS number
      MATCH (n) WHERE id(n) = idFrom("Number", number)
      SET n:Number, n.number = number

standingQueries:
  - name: number-processor
    pattern:
      type: Cypher
      mode: DistinctId
      query: |-
        MATCH (n:Number)
        WHERE n.number IS NOT NULL
        RETURN DISTINCT id(n) AS id
    outputs:
      - name: log-to-console
        preEnrichmentTransformation:
          type: InlineData
        resultEnrichment:
          query: |-
            MATCH (n:Number)
            WHERE id(n) = $that.id
            RETURN n.number AS number, $that.id AS id
          parameter: that
        destinations:
          - type: StandardOut
      - name: post-to-webhook
        preEnrichmentTransformation:
          type: InlineData
        resultEnrichment:
          query: |-
            MATCH (n:Number)
            WHERE id(n) = $that.id
            RETURN n.number AS number, $that.id AS id
          parameter: that
        destinations:
          - type: HttpEndpoint
            url: http://127.0.0.1:3000/webhook

nodeAppearances:
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: Number
    label:
      type: Property
      key: number
      prefix: "Number: "

quickQueries: []
sampleQueries:
  - name: Return all Number nodes
    query: MATCH (n:Number) RETURN n
