Return aggregated data from federated query - aggregate

I am working with SPARQL federated queries. I do not wish to return anything other than aggregated data from each service query. Is this possible? Currently, the query returns data from each service query, and then runs a count and group by. I tried to use subqueries, but they do not work. I am using a fuseki server.
<Edited - added sample query>
SELECT (COUNT(?var) as ?varCount) ?var2
WHERE{
{
?var a abc:Class;
}
UNION
{
SERVICE <https://sample1.org>
{
?var a abc:Class;
?var abc:var2 ?var2.
}
}
UNION
{
SERVICE <https://sample2.org>
{
?var a abc:Class;
?var abc:var2 ?var2.
}
}
} group by ?var2

Related

Mapping dashboard id between GraphQL and PostgreSQL in Tableau Server

In order to develop my application, I am trying to get dashboard data using GraphQL from Tableau Server.
My sample GraphQL is like below,
{
dashboard {
id
luid
name
}
}
From GraphQL, I get a result like below.
{
“data”: {
“dashboards”: [
{
“id”: “0001a27e-6429-c8b7-0d29-644b2ca00e76”,
“luid”: “8291u72j-9281-c9d8-0r83-098i2jx82i00”,
“name”: “TestDashboard”
}
]
}
}
Can I get dashboard id “0001a27e-6429-c8b7-0d29-644b2ca00e76” (not luid) from PostgreSQL in Tableau Server?
If possible, what table in PostgreSQL do I check?
Thank you for your help.

How to query GitHub deployments using GraphQL and use createdAt as a property?

I would like to query my organization deployments using GraphQL and use createdAt as a property (I am doing the same thing with a pull request query : createdAt:"2022-01-01..2022-01-31").
For now, the only way I've found would be to iterate over my repositories, sort deployments by creation date, and stop the query if I reached my limit but I don't think that's efficient.
{
repository(owner: "my_organization", name: "my_repo") {
deployments(orderBy: {field: CREATED_AT, direction: ASC}) {
edges {
node {
state
createdAt
}
}
}
}
}

Getting all repositories query Github v4 API

I am trying to get all my repositories using the Github v4 API, but I can't find any query named repositories. I found a similar way to do so like this:
export const query = gql`
query repositories() {
search(query: "user:userName", type: REPOSITORY, first: 50) {
repositoryCount
edges {
node {
... on Repository {
name
}
}
}
}
}
But this is not what I want because I would have to provide the username which I should get through another query (and I do not want to type it by myself)
Is there a way to get all my repositories by only using one query? I think it should be easy enough, but I can't find the way.
I found the query:
export const query = gql`
query repositories {
viewer {
login
repositories(first: 30) {
edges {
node {
name
}
}
}
}
}
There are different ways to achieve this. You can define parameter in the query and then pass them. In the example below set usersName to your username and first to 50 or whatsoever required, keep in mind there is a limitation for first on GitHub API (value must be between 1 to 100 inclusive) which you can find here.
In this example if userName does not match any entry then an error is returned.
export const query = gql`
query repositories ($userName: String!, $first: Int){
user(login: $userName) {
repositories(first: $first) {
nodes {
name
}
}
}
}
`;
You can use search as in your example and pass variables to the query. However, this way the query will return repositories from users those their names or usernames match or include substring of provided searchText. This query will not return an error if there in no match with searchText.
export const query = gql`
query ($searchText: String!) {
search(query: $searchText, type: USER, first: 1) {
nodes {
... on User {
repositories(first: 50) {
nodes {
name
}
}
}
}
}
}
`;
If you are only interested in your own repository then your own answer can be used as well.

Avoiding Hasura sequential scan for query on large array relation

How do I get Hasura to generate SQL that uses the index on review.user_id?
Here is the seemingly obvious way of getting a user's reviews. I've included a simplified version of the SQL that Hasura generates, which is a sub query approach rather than a JOIN of the review table on user:
# SELECT * FROM review
# WHERE user_id = (
# SELECT id FROM "user" WHERE username = 'admin'
# )
# LIMIT 50
# This uses a sequential scan on `review` because Postgres
# can't know exactly what the subquery returns.
query ReviewsForUserSlow {
user(where: { username: { _eq: "admin" } }) {
reviews(limit: 50) {
text
}
}
}
Here is a hack to get Hasura to generate SQL that does indeed use the review.user_id index. However, the caveat is that we need to make a round trip to Hasura to get the user ID in order to build this query:
# Simplification of the SQL Hasura generates:
# SELECT * FROM review
# WHERE user_id = '8f3547e4-c8a9-480f-991f-0798c02f2ba2'
# LIMIT 50
query ReviewsForUserFast {
review(
limit: 50,
where: {
user_id: {
_eq: "8f3547e4-c8a9-480f-991f-0798c02f2ba2"
}
}
) {
text
}
}

Github V4 GraphQL API - audit log query

i'm trying to interact with github api v4, i want to query audit log events based on schemas available in the api. I can found a documentary about the github api here and I can see the schemas available here but there are no working examples of how to query the different schemas.
If there is someone here experience with this API, specially with the audit log schemas, I need a working example to start interacting with the audit log schemas...
for example i want to query all organization add member to team events, suppose to be in the schema TeamAddMemberAuditEntry, or remove member from org OrgRemoveMemberAuditEntry
So far I've tried to query it with node.js:
require('isomorphic-fetch');
fetch('https://api.github.com/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json',
'Authorization': 'bearer <token>',
'Accept': 'application/vnd.github.audit-log- preview+json'},
body: JSON.stringify({ query: '{ TeamAddMemberAuditEntry }' }),
})
.then(res => res.json())
.then(res => console.log(res.data));
If someone here will look for solution, after viewing the public schema this is how the query looks for getting audit-log objects, this is without the headers and the query prefix of course.
The auditLog is a union type, you can get multiple audit events by adding another "...on" block. for example here i'm getting all the orginvitemembers events
{
organization(login:"<your-org>") {
auditLog(first:2) {
edges {
node {
__typename
... on OrgInviteMemberAuditEntry {
action
actorIp
actorLogin
createdAt
userLogin
actorLocation{
country
city
}
}
}
}
}
}
}
I was after the same thing. I think your query statement is like the issue.
I came across this documentation in the GitHub blog.
https://github.blog/2019-06-21-the-github-enterprise-audit-log-api-for-graphql-beginners/
I was able to adapt the example query and come up with the following...
{
organization(login: "xyz-corp") {
auditLog(last: 10
, query: "action:org.remove_member") {
edges {
node {
... on AuditEntry {
action
actorLogin
userLogin
createdAt
user{
name
email
}
}
}
}
}
}
}
I was able to substitute the query with the following just as I would via the UI to get adds and updates.
action:org.add_member
action:org.update_member
Other audit log query items are described here
https://docs.github.com/en/organizations/keeping-your-organization-secure/reviewing-the-audit-log-for-your-organization