Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional feature for aggregate count query support on plural entity object types #488

Merged
merged 11 commits into from
May 27, 2024

Conversation

igdianov
Copy link
Collaborator

@igdianov igdianov commented May 26, 2024

Added an optional feature to generate aggregate count query for plural entities object types. The aggregate feature can be enabled via GraphQLSchemaBuilderCustomizer:

@Bean
GraphQLJPASchemaBuilderCustomizer graphQLJPASchemaBuilderCustomizer() {
   return builder ->
      builder
         .name("Query")
         .enableAggregate(true);
});

The GraphQL Schema builder will generate aggregate selection field to be able to request counts. The count can be grouped by entity fields and nested associations, i.e.

query {
  Tasks {
    aggregate {
      countTasks: count
      countProcessVariables: count(of: processVariables)
      countTaskVariables: count(of: variables)
      countTasksGroupedByStatus: group {
        status: by(field: status)
        count
      }
      countProcessVariablesGroupedByTaskName: group {
        name: by(field: name)
        count(of: processVariables)
      }
      countTaskProcessVariablesGroupedByVariableNameAndValue: processVariables {
        name: by(field: name)
        value: by(field: value)
        count
      }
      countTaskVariablesGroupedByVariableName: variables {
        name: by(field: name)
        count
      }
    }
  }
}

Will return counts by different groups including nested associations:

{
  "data": {
    "Tasks": {
      "aggregate": {
        "countTasks": 1000,
        "countProcessVariables": 6,
        "countTaskVariables": 42,
        "countTasksGroupedByStatus": [
          {
            "status": "COMPLETED",
            "count": 335
          },
          {
            "status": "ASSIGNED",
            "count": 337
          },
          {
            "status": "CREATED",
            "count": 328
          }
        ],
        "countProcessVariablesGroupedByTaskName": [
          {
            "name": "Solarbreeze",
            "count": 6
          }
        ],
        "countTaskProcessVariablesGroupedByVariableNameAndValue": [
          {
            "name": "applicationId",
            "value": "232951752337576",
            "count": 1
          },
          {
            "name": "moduleid",
            "value": "LBU",
            "count": 1
          },
          {
            "name": "isApproved",
            "value": true,
            "count": 1
          },
          {
            "name": "approverlist",
            "value": [
              "andrelaksmana"
            ],
            "count": 1
          },
          {
            "name": "applicationDate",
            "value": "2023-10-22T00:00:00.000+0000",
            "count": 1
          },
          {
            "name": "nullable",
            "value": null,
            "count": 1
          }
        ],
        "countTaskVariablesGroupedByVariableName": [
          {
            "name": "accountNumber",
            "count": 7
          },
          {
            "name": "variable1",
            "count": 5
          },
          {
            "name": "variable2",
            "count": 6
          },
          {
            "name": "variable3",
            "count": 6
          },
          {
            "name": "variable4",
            "count": 6
          },
          {
            "name": "variable5",
            "count": 6
          },
          {
            "name": "variable7",
            "count": 6
          }
        ]
      }
    }
  }
}

@igdianov igdianov self-assigned this May 26, 2024
Copy link

codecov bot commented May 26, 2024

Codecov Report

Attention: Patch coverage is 91.10512% with 33 lines in your changes are missing coverage. Please review.

Project coverage is 77.55%. Comparing base (c5527d4) to head (3bec49e).
Report is 5 commits behind head on master.

Files Patch % Lines
.../jpa/query/schema/impl/GraphQLJpaQueryFactory.java 77.98% 12 Missing and 12 partials ⚠️
.../query/schema/impl/GraphQLJpaQueryDataFetcher.java 95.00% 4 Missing and 1 partial ⚠️
...jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java 97.27% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #488      +/-   ##
============================================
+ Coverage     76.73%   77.55%   +0.82%     
- Complexity     1231     1300      +69     
============================================
  Files            79       79              
  Lines          5372     5704     +332     
  Branches        745      759      +14     
============================================
+ Hits           4122     4424     +302     
- Misses          928      943      +15     
- Partials        322      337      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@igdianov igdianov marked this pull request as ready for review May 26, 2024 02:58
@igdianov igdianov changed the title Add aggregate count query support Add optional aggregate count query support for plural entity object types May 27, 2024
@igdianov igdianov changed the title Add optional aggregate count query support for plural entity object types Add optional feature for aggregate count query support on plural entity object types May 27, 2024
@igdianov igdianov merged commit 5ef0f9f into master May 27, 2024
3 checks passed
@igdianov igdianov deleted the feat-aggregate-count branch May 27, 2024 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant