Parinaz.N
Parinaz.N

Reputation: 27

How Can I relate 2 content items in GraphQl in orchard?

I want to write a GraphQl query in the Orchard with these conditions:

I have a content type for Office and another one for City Now I want to receive all the offices in Newyork city. But the problem is that in the where condition of the GraphQl I don't see any condition for filtering a specific city.

What can I do?

Upvotes: 0

Views: 347

Answers (1)

awashima
awashima

Reputation: 114

You could create a taxonomy for cities and then add a taxonomy field with Cities taxonomy to your Office content type.

Enable Queries Feature, which is a module that enables you to write Lucene or SQL queries and expose them to GraphQL.

Add a SQL query.

  1. Add name getOfficesByCity
  2. Add schema
{
"type": "ContentItem/Office"
} 
  1. Check the Return Documents checkbox.
  2. Write SQL that will query TaxonomyIndex for Offices with specific TermContentItemId. Something along the lines
SELECT
    ti.DocumentId
FROM
    TaxonomyIndex ti
WHERE
    ti.TermContentItemId = @cityItemId
    AND ti.ContentType = 'Office'

  1. Go to GraphQL
query MyQuery {
  getOfficesByCity(parameters: "{\"cityItemId\":\"4rx2d0cqr8h7fyzdq95hb45scj\"}") {
    displayText
  }
}

Upvotes: 1

Related Questions