How to query for only the joint nodes in between

Sorry if this is an overly simple question. I don’t know what I don’t know, so I’m having a hard time Googling for the right terms that I actually need to search for.

I’m not sure of how to best describe the issue other than provide the scenario. I’d say that I’m likely trying to remove the extraneous nodes in the response other than what filters down to the “deepest” value.

Here is the query I have now.

{
  company(func: type(Company)) 
  @filter(eq(ticker, "RDS") OR eq(ticker, "EQNR")) {
    name, ~project.company {
      name
    }
  }
}

This query pulls back what I want plus more. I want to find the nodes for Equinor and Shell and I want to find the “projects” that they mutually work on. It’s currently giving me both companies and ALL of the projects that they both work on. Essentially, “the Canyon Lime formation” and “the Timor Sea” are the only two that should be showing up below.

{
  "data": {
    "company": [
      {
        "name": "Equinor ASA",
        "~project.company": [
          {
            "name": "the Timor Sea"
          },
          {
            "name": "the Canyon Lime formation"
          },
          {
            "name": "Tyrihans"
          },
          {
            "name": "Oseberg C"
          },
          {
            "name": "Oseberg C"
          },
          {
            "name": "Oseberg C"
          },
          {
            "name": "Ormen Lange"
          },
          {
            "name": "Ivar Aasen"
          },
          {
            "name": "the Barents Sea"
          },
          {
            "name": "Johan Sverdrup"
          },
          {
            "name": "Johan Castberg"
          },
          {
            "name": "28 June"
          },
          {
            "name": "Johan Castberg"
          },
          {
            "name": "Martin Linge  "
          },
          {
            "name": "Martin Linge  "
          },
          {
            "name": "the Skarv field"
          },
          {
            "name": "the Skarv field"
          },
          {
            "name": "the Skarv field"
          },
          {
            "name": "Askeladd"
          },
          {
            "name": "Haltenbanken"
          },
          {
            "name": "March"
          },
          {
            "name": "November"
          },
          {
            "name": "the UK sector"
          },
          {
            "name": "the North Sea"
          },
          {
            "name": "Jack"
          },
          {
            "name": "Louisiana"
          },
          {
            "name": "north east US"
          },
          {
            "name": "north east US"
          },
          {
            "name": "the Appalachian region"
          },
          {
            "name": "Campos"
          },
          {
            "name": "the Central Niger Delta region"
          },
          {
            "name": "the Central Niger Delta region"
          },
          {
            "name": "the Consolidated financial statements"
          },
          {
            "name": "Equinor"
          },
          {
            "name": "Southern"
          },
          {
            "name": "Northern"
          },
          {
            "name": "the Campos basin"
          },
          {
            "name": "Uirapuru"
          },
          {
            "name": "Canada"
          },
          {
            "name": "Mariner"
          }
        ]
      },
      {
        "name": "Royal Dutch Shell",
        "~project.company": [
          {
            "name": "Tobago"
          },
          {
            "name": "the Hazira LNG and Port venture"
          },
          {
            "name": "the Changbei II Phase 1 project"
          },
          {
            "name": "Sichuan"
          },
          {
            "name": "the Mid Tapti and South Tapti fields"
          },
          {
            "name": "the Mid Tapti and South Tapti fields"
          },
          {
            "name": "an onshore LNG project"
          },
          {
            "name": "Khanty Mansiysk Autonomous District"
          },
          {
            "name": "Concerto"
          },
          {
            "name": "Woodside"
          },
          {
            "name": "the Timor Sea"
          },
          {
            "name": "Bonaparte"
          },
          {
            "name": "the Rovuma Basin"
          },
          {
            "name": "the Block 1 and 4 appraisal programme"
          },
          {
            "name": "the Block 1 and 4 appraisal programme"
          },
          {
            "name": "the Block 1 and 4 appraisal programme"
          },
          {
            "name": "the La Vertiente gas processing plant"
          },
          {
            "name": "Caipipendi"
          },
          {
            "name": "NCMA blocks"
          },
          {
            "name": "Atlantic Area"
          },
          {
            "name": "the Canyon Lime formation"
          }
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 14650,
      "processing_ns": 3460629,
      "encoding_ns": 115420,
      "assign_timestamp_ns": 611824
    },
    "txn": {
      "start_ts": 608762
    }
  }
}

Also, if it helps, this is the schema between those two types

Type: Company
company.doc - [Document]
company.group - [Group]
company.industry - [Industry]
company.location - [Location]
name - string
nativeName - string
otherNames - [string]
ticker - string

Type: Project
name - string
project.company - [Company]
project.field - [Field]
project.location - [Location]
status - string

Thanks ahead of time for the help. Please let me know if I missed something to add here.

Not sure if I understood perfectly. But for

“I want to find the “projects” that they mutually work on.”

You can do something like:

Take into account that I had to improvise by simplifying the sample.

{
  company1(func: type(Company)) 
  @filter(eq(name, "Equinor ASA") ) {
    uid
    name
    PC1 as ~project.company
    count(~project.company)
  }
  company2(func: type(Company)) 
  @filter(eq(name, "Royal Dutch Shell") ) {
    uid
    PC2 as ~project.company
    count(~project.company)
  }
  
  worked(func: uid(PC1)) @filter(uid(PC2)) {
    name
    ~project.company {
      name
    }
     count(uid)
  }
    
}

Result

{
  "data": {
    "company1": [
      {
        "uid": "0xea6f",
        "name": "Equinor ASA",
        "count(~project.company)": 6
      }
    ],
    "company2": [
      {
        "uid": "0xea70",
        "name": "Royal Dutch Shell",
        "count(~project.company)": 6
      }
    ],
    "worked": [
      {
        "count": 4
      },
      {
        "name": "Worked with Shell 1"
      },
      {
        "name": "Worked with Shell 3"
      },
      {
        "name": "Worked with Shell 2"
      },
      {
        "name": "Worked with Shell 4"
      }
    ]
  }
}

Mutation

{
	"set": [{
			"uid": "_:EquinorASA",
			"name": "Equinor ASA",
			"dgraph.type": "Company"
		},
		{
			"uid": "_:Shell",
			"name": "Royal Dutch Shell",
			"dgraph.type": "Company"
		}, {
			"name": "the Timor Sea",
			"project.company": {
				"uid": "_:EquinorASA"
			}
		},
		{
			"name": "the Canyon Lime formation",
			"project.company": {
				"uid": "_:EquinorASA"
			}
		}, {
			"uid": "_:Shell1",
			"name": "Worked with Shell 1",
			"project.company": [{
				"uid": "_:EquinorASA"
			}, {
				"uid": "_:Shell"
			}]
		}, {
			"uid": "_:Shell2",
			"name": "Worked with Shell 2",
			"project.company": [{
				"uid": "_:EquinorASA"
			}, {
				"uid": "_:Shell"
			}]
		}, {
			"uid": "_:Shell3",
			"name": "Worked with Shell 3",
			"project.company": [{
				"uid": "_:EquinorASA"
			}, {
				"uid": "_:Shell"
			}]
		}, {
			"uid": "_:Shell4",
			"name": "Worked with Shell 4",
			"project.company": [{
				"uid": "_:EquinorASA"
			}, {
				"uid": "_:Shell"
			}]
		}, {
			"name": "Tobago",
			"project.company": {
				"uid": "_:Shell"
			}
		}, {
			"name": "the Hazira LNG and Port venture",
			"project.company": {
				"uid": "_:Shell"
			}
		}
	]
}

How do you determine whether to use eq(dgraph.type, "Company") or type(Company)?

It is not recommended to use “dgraph.type”. The type system is designed to use with Type() Func.

https://docs.dgraph.io/query-language/#type-system

I see, your example was to suggest that both options are available 'tho users should use Type().

ohh, I see too. I did that without thinking I guess. In fact, that option exists. But users shouldn’t use it. I’ll fix that in my example. I don’t know what I was thinking, But I believe it was because I wasn’t totally used to Type System yet.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.