Next.XP error after changing gradle configuration

Enonic version: 7.9.2

I changed my gradle-configuration to the following:

# Gradle Project settings
projectName = OSDE_2022_BE

# XP App values
appDisplayName = Outsourcing Portal Backend
#appName = com.enonic.app.nextjsdemo
appName = de.osde.app.be

vendorName = Enonic
vendorUrl = https://www.lienas.de
xpVersion = 7.8.3

version=0.8.0

I also moved the application to the default repo!
My graph-ql endpoint is now:
http://localhost:8080/site/default/draft/osde/_graphql

I adjusted the frontend-config (.env.development) to:

CONTENT_API_URL=http://localhost:8080/site/default/draft/osde/_graphql`

and in .env I added:

APP_NAME=de.osde.app.be

I tested the endpoint in graphql-playground without issues. But from the frontend I get the following error:

Error returned an empty object from `getInitialProps`. This de-optimizes and prevents automatic static optimization. https://nextjs.org/docs/messages/empty-object-getInitialProps
error - Error: {"code":"500","message":"Server responded with 1 error(s), probably from guillotine - see log."}
1 error(s) when trying to fetch data (path = "${site}/"):
{
  errorType: 'DataFetchingException',
  message: 'Exception while fetching data (/guillotine/get) : TypeError: Cannot get property "_path" of null',
  locations: [ { line: 3, column: 17 } ],
  exception: {
    name: 'com.enonic.xp.resource.ResourceProblemException',
    message: 'TypeError: Cannot get property "_path" of null'
  }
}

What did I miss?

500 error is a server error.
And "_path" of null is a null pointer exception.
While changing the config the graphql endpoint seems to have lost its refrence to the site.
There should be a server error that could give more insight into where the issue is coming from.

Thats the error on serversite -

2022-05-31 12:31:10,322 WARN  n.g.e.SimpleDataFetcherExceptionHandler - Exception while fetching data (/guillotine/get) : TypeError: Cannot get property "_path" of null
com.enonic.xp.resource.ResourceProblemException: TypeError: Cannot get property "_path" of null
        at com.enonic.xp.resource.ResourceProblemException$Builder.build(ResourceProblemEx...

seems that the graphQl (or better Guillotine) does not resolve ${site}
coming from line 661-663 of fetchContent.ts

///////////////  FIRST GUILLOTINE CALL FOR METADATA     /////////////////
            const metaResult = await fetchMetaData(CONTENT_API_URL, '${site}/' + siteRelativeContentPath);
            /////////////////////////////////////////////////////////////////////////

The exception you see comes from guillotine, so nextjs server is configured correctly and guillotine is there.
But the guillotine itself is having hard time accessing the data.

Did you try accessing data from the playground ?
What does output from the following query look like ?

query {
  guillotine {
    getSite {
      _path
    }
    get(key: "/osde") {
      _path
    }
  }
}

I found, that when I am not logged in, I get the following response:

{
  "data": {
    "guillotine": {
      "getSite": null,
      "get": null
    }
  },
  "errors": [
    {
      "errorType": "DataFetchingException",
      "message": "Exception while fetching data (/guillotine/get) : TypeError: Cannot get property \"_path\" of null",
      "locations": [
        {
          "line": 6,
          "column": 5
        }
      ],
      "exception": {
        "name": "com.enonic.xp.resource.ResourceProblemException",
        "message": "TypeError: Cannot get property \"_path\" of null"
      }
    }
  ]
}

But when I am logged in - I get the following:

{
  "data": {
    "guillotine": {
      "getSite": {
        "_path": "/osde"
      },
      "get": {
        "_path": "/osde"
      }
    }
  }
}

So it seems to be a permission-issue!
How to fix this ?
In repo ??
Ok added readPermissions to system:everyone and it worked:
But should’nt I get sth. like 401: Unauthorized instead of 500 !!

Good it works for you now !

Nextjs server gets response with errors from guillotine and just shows it because it has no means to understand what was the cause so status 500 looks like the right choice.

Guillotine should’ve returned 401 for the nextjs server to understand it, but guillotine in its turn returns you the result of the graphql query without doing any processing.

We’ll add tasks to se if we can improve both the response from the graphql query, as well as having the nextJs adapter respond with a 401 in this case!

1 Like