Aggregations in guillotine in Apollo Angular

Enonic version: 7.9.2.
OS: Windows 10

Hi,

I’m having a problem with aggregations in a guillotine query when using Apollo Angular.
Here’s the query method:

public static GetAvailableCategories(): QueryOptions {
    const query = `{
      guillotine {
        queryConnection(
          query: "type='com.gksoftware.es.esintranet:e-shop-item'",
          aggregations: {
            name: "categories",
            terms: {
              field: "data.category"
              size: 500
            }
          }
        ) {
          aggregationsAsJson
        }
      }
    }`
    return {
      query: gql(query)
    }
  }

In the Enonic XP content studio playground, the query result returns as expected:

{
  "data": {
    "guillotine": {
      "queryConnection": {
        "aggregationsAsJson": {
          "categories": {
            "buckets": [
              {
                "key": "a6aec745-b66a-4397-b350-6ba7495a59d0",
                "docCount": 1
              },
              {
                "key": "46dc49d5-90d1-4830-bfcf-0867c0ca964a",
                "docCount": 2
              },
              {
                "key": "4ca44465-b3e1-4e4e-925c-16adec7564ed",
                "docCount": 3
              },
              {
                "key": "f0bd3664-b6e2-4537-8702-13508a06ed16",
                "docCount": 4
              },
              {
                "key": "a1f33434-6ab0-4457-8a8b-b290cb1181b1",
                "docCount": 5
              }
            ]
          }
        }
      }
    }
  }
}

However, when I try to fetch the data through Apollo Angular using this method:

public executeQuery(options: QueryOptions): Promise<QueryResponse> {
    let apolloBase: ApolloBase<any>;
    switch (this.language) {
      case 'en':
        apolloBase = this.apollo.use(this.language);
        break;
      default:
        apolloBase = this.apollo;
    }
    return new Promise((resolve, reject) => {
      apolloBase.query<any>(options)
        .subscribe(
          ({data}) => {
            resolve(data);
          },
          err => {
            this.router.navigateByUrl('/error/500');
            console.log(err);
            reject(err);
          }
        );
    });
  }

It throws this error:

Error: Uncaught (in promise): Error: GraphQL error: Validation error of type UnknownArgument: Unknown field argument aggregations @ 'guillotine/queryConnection'
GraphQL error: Validation error of type FieldUndefined: Field 'aggregationsAsJson' in type 'ContentConnection' is undefined @ 'guillotine/queryConnection/aggregationsAsJson'
Error
    at new ApolloError (bundle.esm.js:63:1)
    at bundle.esm.js:1247:1
    at bundle.esm.js:1559:1
    at Set.forEach (<anonymous>)
    at bundle.esm.js:1557:1
    at Map.forEach (<anonymous>)
    at push.dMq0.QueryManager.broadcastQueries (bundle.esm.js:1555:1)
    at bundle.esm.js:1646:1
    at Object.next (Observable.js:322:1)
    at notifySubscription (Observable.js:135:1)
    at resolvePromise (zone-evergreen.js:798:1)
    at resolvePromise (zone-evergreen.js:750:1)
    at zone-evergreen.js:860:1
    at ZoneDelegate.invokeTask (zone-evergreen.js:399:1)
    at Object.onInvokeTask (core.js:28567:1)
    at ZoneDelegate.invokeTask (zone-evergreen.js:398:1)
    at Zone.runTask (zone-evergreen.js:167:1)
    at drainMicroTaskQueue (zone-evergreen.js:569:1)
    at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:484:1)
    at invokeTask (zone-evergreen.js:1621:1)

It basically doesn’t recognize aggregation and aggregationsAsJson as valid fields, since without them, the query works fine, and having it in a guillotine is necessary. What should I do to make the aggregation fields work?

Hi @pcermak,

Something is wrong here. The queryConnection field returns the QueryContentConnection type. However, in the provided error, I can see the ContentConnection type. The ContentConnection type is used for getChildrenConnection of the HeadlessCms type. This field also does not have the aggregations argument.

Could you please double-check it on your end? Maybe do you have aliases for this field, where you can use getChildrenConntection.

If the problem still appears, please provide the version of Guillotine as well.

Additionally, please note that the query and queryConnection fields are deprecated starting from version 6.1.0 API - Enonic Developer Portal. You should use queryDsl and queryDslConnection instead.

Hi @asi,

I tried looking but unfortunately, I didn’t manage to find any aliases for the field. Additionally, enonic doesn’t seem to register queryDsl and queryDslConnection as valid guillotine fields, though I may be doing something wrong. For reference, the guillotine version is 6.0.6.

Anyways, thanks for your help!

Yes, QueryDSL is supported starting from version 6.1.0. I think it makes sense to update the version of Guillotine.

Hi, were you able to resolve your issue?

If not, could you please check if you are using the correct endpoint for the Guillotine API? The Guillotine API should be accessible at:

  • POST /site/<project-name>/master - for publishing content
  • POST /site/<project-name>/draft - for draft content

Where <project-name> is the name of your repository without com.enonic.cms., for example, myproject for com.enonic.cms.myproject.

Hi asi,

we decided to upgrade the whole stack:

  • XP to the version 7.14.2
  • Content Studio to 5.2.
  • Guilotine 7.1.1

We updated the packages in our project too accordingly. We are fixing the queries now, because of the new fields of the data types (HTML area, …).
We found out that the queries returns 401 status now. How can we authenticate the requests?

After fixing this we will try to use the aggregation again.
Thank you

Hi @pcermak,

That is very cool that you started to use latest versions of apps and XP.

Could you please to clarify which queries return 401?

Hi asi,

basically all the queries which worked on the older version need authentication now. The error message below appears for all the data queries now.

ERROR Error: Uncaught (in promise): Error: Network error: Http failure response for https://intranet-staging.es.gk-software.com/xp/cz/draft/intranet/api: 401 OK
t@https://intranet-staging.es.gk-software.com/cz/esint-1821-update-queries-draft/main-es2015.f13de18c1e5ecccf1d41.js:1:1795745
...

If we open and login to the XP within the same web browser, the client application loads data without any problem. The question is how to set the authentication in the client application to order to authenticate and access the data without login to XP?

The permissions of the content is set to available to read for everyone:

Thank you
Pavel

It is related to these changes Release Notes - Enonic Developer Portal. It should be done via draftBranchAllowedFor configuration.

Hi asi,

the configuration helped, thank you
Pavel

1 Like