Skip to content

Instantly share code, notes, and snippets.

@MichelDiz
Last active December 11, 2018 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichelDiz/2e434fcd4a4536da20a63b127a04a600 to your computer and use it in GitHub Desktop.
Save MichelDiz/2e434fcd4a4536da20a63b127a04a600 to your computer and use it in GitHub Desktop.
{
GetIssues_Customer_By_metaTags(func: eq(title, "Hyper Tech")) # @cascade @normalize
{
uid
issues @filter(eq(metaTags, ["Urgent","Bug"]))# AND NOT eq(metaCategories, "Problem"))
{
title
metaTags
metaCategories
participants {
uid
name
}
}
}
}
{
"set": [
{
"datetime_structure": [
{
"uid": "_:2019",
"year": "2019",
"description": "This structure is as it is so that you can use Recurse Query and be able view in graphs the annual data",
"Warning": "This structure is generally unnecessary.",
"month_attached": [
{
"description": "Here are months that have obtained records in DB"
},
{
"1": [
{
"description": "January - unnecessary description"
},
{
"days": [
{
"uid": "_:2019-01-01",
"datetime": "2019-01-01",
"date_records": [
{
"uid": "_:michaelsecond"
}
]
}
]
}
]
}
]
},
{
"uid": "_:2018",
"year": "2018",
"month_attached": [
{
"description": "Here are months that have obtained records in DB"
},
{
"1": [
{
"description": "January - unnecessary description"
},
{
"days": [
{
"uid": "_:2018-01-01",
"datetime": "2018-01-01",
"date_records": [
{
"uid": "_:amitfirst"
}
]
}
]
}
]
},
{
"2": [
{
"description": "Feb - unnecessary description"
},
{
"days": [
{
"uid": "_:2018-02-01",
"datetime": "2018-02-01",
"date_records": [
{
"uid": "_:amitsecond"
},
{
"uid": "_:joefirst"
},
{
"uid": "_:joesecond"
},
{
"uid": "_:maryfirst"
}
]
}
]
}
],
"3": [
{
"description": "March - unnecessary description"
},
{
"days": [
{
"uid": "_:2018-03-01",
"datetime": "2018-03-01",
"date_records": [
{
"uid": "_:marysecond"
}
]
}
]
}
]
}
]
},
{
"uid": "_:2017",
"year": "2017",
"month_attached": [
{
"description": "Here are months that have obtained records in DB"
},
{
"1": [
{
"description": "January - unnecessary description"
},
{
"days": [
{
"uid": "_:2017-01-01",
"datetime": "2017-01-01",
"date_records": [
{
"uid": "_:michaelfirst"
}
]
}
]
}
]
},
{
"2": [
{
"description": "Feb - unnecessary description"
},
{
"days": [
{
"uid": "_:2017-02-01",
"datetime": "2017-02-01"
}
]
}
]
}
]
}
],
"departments": [
{
"uid": "_:Accountdepartment",
"department_type": true,
"title": "Account",
"incharge": {
"uid": "_:michael"
},
"supervisor": {
"uid": "_:sarah"
},
"also_works_here": [
{
"uid": "_:Saul"
},
{
"uid": "_:sang"
},
{
"uid": "_:catalina"
},
{
"uid": "_:artyom"
}
],
"issues_dp": [
{
"uid": "_:michaelfirst"
},
{
"uid": "_:michaelsecond"
}
]
},
{
"uid": "_:Salesdepartment",
"department_type": true,
"title": "Sales",
"incharge": {
"uid": "_:Angelina"
},
"supervisor": {
"uid": "_:Lucas"
},
"also_works_here": [
{
"uid": "_:amit"
},
{
"uid": "_:Julios"
},
{
"uid": "_:Fernando"
},
{
"uid": "_:Helena"
},
{
"uid": "_:mary"
},
{
"uid": "_:joe"
}
],
"issues_dp": [
{
"uid": "_:amitfirst"
},
{
"uid": "_:amitsecond"
},
{
"uid": "_:joefirst"
},
{
"uid": "_:joesecond"
},
{
"uid": "_:maryfirst"
},
{
"uid": "_:marysecond"
}
]
}
],
"Customers": [
{
"uid": "_:CustomerA",
"Customer_type": true,
"title": "Hyper Tech",
"department": {
"uid": "_:Accountdepartment"
},
"issues": [
{
"uid": "_:michaelfirst"
},
{
"uid": "_:michaelsecond"
}
]
},
{
"uid": "_:CustomerX",
"Customer_type": true,
"title": "Rio Sales",
"department": {
"uid": "_:Salesdepartment"
},
"issues": [
{
"uid": "_:amitfirst"
},
{
"uid": "_:amitsecond"
},
{
"uid": "_:joefirst"
},
{
"uid": "_:joesecond"
},
{
"uid": "_:maryfirst"
},
{
"uid": "_:marysecond"
}
]
}
],
"categories": [
{
"uid": "_:Problemcategorie",
"categ_type": true,
"title_cat": "Problem"
},
{
"uid": "_:alertcategorie",
"categ_type": true,
"title_cat": "alert"
},
{
"uid": "_:Ccategorie",
"categ_type": true,
"title_cat": "C"
},
{
"uid": "_:Dcategorie",
"categ_type": true,
"title_cat": "D"
}
],
"all_tags": [
{
"uid": "_:tagUrgent",
"tag_type": true,
"title_tag": "Urgent"
},
{
"uid": "_:tagBug",
"tag_type": true,
"title_tag": "Bug"
}
],
"all_users": [
{
"uid": "_:michael",
"name": "Michael",
"email": "Michael@somewhere.com",
"user_type": true,
"age": 39,
"author": [
{
"uid": "_:michaelfirst",
"issue_type": true,
"title": "Michael first issue",
"datetime": "2017-01-01",
"category": [
{
"uid": "_:Problemcategorie"
}
],
"metaCategories": [
"Problem"
],
"metaTags": [
"Urgent",
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
},
{
"uid": "_:tagUrgent"
}
],
"participants": [
{
"uid": "_:Saul"
},
{
"uid": "_:sang"
},
{
"uid": "_:catalina"
},
{
"uid": "_:artyom"
}
]
},
{
"uid": "_:michaelsecond",
"issue_type": true,
"title": "Michael second issue",
"datetime": "2019-02-01",
"category": [
{
"uid": "_:alertcategorie"
}
],
"metaCategories": [
"Alert"
],
"metaTags": [
"Urgent",
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
},
{
"uid": "_:tagUrgent"
}
],
"participants": [
{
"uid": "_:Saul"
},
{
"uid": "_:sang"
},
{
"uid": "_:catalina"
},
{
"uid": "_:artyom"
}
]
}
]
},
{
"uid": "_:amit",
"name@hi": "अमित",
"name@bn": "অমিত",
"name@en": "Amit",
"email": "Amit@somewhere.com",
"user_type": true,
"age": 35,
"author": [
{
"uid": "_:amitfirst",
"issue_type": true,
"title": "Amit first issue",
"datetime": "2018-01-01",
"category": [
{
"uid": "_:Problemcategorie"
}
],
"metaCategories": [
"Problem"
],
"metaTags": [
"Urgent",
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
},
{
"uid": "_:tagUrgent"
}
],
"participants": [
{
"uid": "_:Fernando"
},
{
"uid": "_:Helena"
},
{
"uid": "_:mary"
},
{
"uid": "_:joe"
}
]
},
{
"uid": "_:amitsecond",
"issue_type": true,
"title": "Amit second issue",
"datetime": "2018-02-01",
"category": [
{
"uid": "_:Problemcategorie"
}
],
"metaCategories": [
"Problem"
],
"metaTags": [
"Urgent",
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
},
{
"uid": "_:tagUrgent"
}
],
"participants": [
{
"uid": "_:Fernando"
},
{
"uid": "_:Helena"
},
{
"uid": "_:mary"
},
{
"uid": "_:joe"
}
]
}
]
},
{
"uid": "_:sarah",
"name": "Sarah",
"email": "Sarah@somewhere.com",
"user_type": true,
"age": 55
},
{
"uid": "_:joe",
"name": "joe",
"email": "joe@somewhere.com",
"user_type": true,
"age": 28,
"author": [
{
"uid": "_:joefirst",
"issue_type": true,
"title": "joe first issue",
"datetime": "2018-02-01",
"category": [
{
"uid": "_:alertcategorie"
}
],
"metaCategories": [
"alert"
],
"metaTags": [
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
}
],
"participants": [
{
"uid": "_:Fernando"
},
{
"uid": "_:Helena"
},
{
"uid": "_:mary"
}
]
},
{
"uid": "_:joesecond",
"issue_type": true,
"title": "joe second issue",
"datetime": "2018-02-01",
"category": [
{
"uid": "_:alertcategorie"
}
],
"metaCategories": [
"alert"
],
"metaTags": [
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
}
],
"participants": [
{
"uid": "_:Fernando"
},
{
"uid": "_:Helena"
},
{
"uid": "_:mary"
}
]
}
]
},
{
"uid": "_:mary",
"name": "mary",
"email": "mary@somewhere.com",
"user_type": true,
"age": 31,
"author": [
{
"uid": "_:maryfirst",
"issue_type": true,
"title": "mary first issue",
"datetime": "2018-02-01",
"category": [
{
"uid": "_:alertcategorie"
}
],
"metaCategories": [
"alert"
],
"metaTags": [
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
}
],
"participants": [
{
"uid": "_:Fernando"
},
{
"uid": "_:Helena"
},
{
"uid": "_:joe"
}
]
},
{
"uid": "_:marysecond",
"issue_type": true,
"title": "mary second issue",
"datetime": "2018-03-01",
"category": [
{
"uid": "_:alertcategorie"
}
],
"metaCategories": [
"alert"
],
"metaTags": [
"Bug"
],
"tags": [
{
"uid": "_:tagBug"
}
],
"participants": [
{
"uid": "_:Fernando"
},
{
"uid": "_:Helena"
},
{
"uid": "_:joe"
}
]
}
]
}
]
}
]
}
{
ORGetIssuesByDepartmentANDCustomer_using_metaTags(func: eq(title, "Rio Sales")) # @cascade @normalize
{
uid
title
department @filter(eq(title, "Sales")){
title
incharge {name}
issues_dp
#@filter(NOT eq(metaCategories, ["Test", "D"]))
#@filter(eq(metaTags, ["Urgent","Bug"]))
@filter(eq(metaTags, ["Urgent","Bug"]) AND NOT eq(metaCategories, "Problem"))
{
title
author : ~author {name}
metaTags
metaCategories
participants {
uid
name
}
category {
title_cat
}
}
}
}
}
{
# In this example there are two companies. Rio Sales and Hyper Tech. I stated how each one relate to a single department (for testing).
# Therefore, all modifiable fields need to be changed according to this premise - Take a look in the JSON before.
# For example, Rio Sales is configured as a Sales department. So if you modify to Hyper Tech and do not modify the "department" fields.
# The results will be null because Hyper Tech has no issues in Sales.
# GetCategorie(func: has(categ_type))
# {
# uid
# title_cat
# }
### ORGetIssuesByDepartmentANDCustomer
var(func: eq(title, "Rio Sales")) # @cascade @normalize
{
department @filter(eq(title, "Sales")){
issues_dp
# Through GetCategorie we store the UID of the desired category and use it above.
@filter(uid_in(category, "0xe1") OR uid_in(category, "0xec") AND (ge(datetime, "2011-01-01") AND le(datetime, "2019-07-23")))
@groupby(~date_records)
{
a as count(uid)
}
}
}
GroupingByDay(func: uid(a)){
uid
datetime
# You have to put a filter down here just like the one in the var block above.
# For the first block was just to find the correct dates among the Department AND Customer. Also pre-filter the category.
# Through GetCategorie we store the UID of the desired category and use it above.
date_records @filter(uid_in(category, "0xe1") OR uid_in(category, "0xec") AND (ge(datetime, "2017-05-01") AND le(datetime, "2019-07-23"))) {
title
author : ~author {name}
metaTags
metaCategories
participants {
uid
name
}
category {
title_cat
}
~date_records {
datetime
}
}
}
}
name: string @index(term) @lang .
release_date: datetime @index(year) .
category: uid @reverse .
metaCategories: [string] @index(exact) .
metaTags: [string] @index(exact) .
author: uid @reverse .
tags: uid @reverse .
issues_dp: uid @reverse .
issues: uid @reverse .
title: string @index(exact) .
title_cat: string @index(exact) .
year: datetime @index(year) .
datetime: datetime @index(day) .
date_records: uid @reverse .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment