Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

GraphQL Endpoint for Preview Service throwing QueryType Invalid Schema must define one or more fields for Persisted Query

Avatar

Level 1

I am currently trying to get the my GraphQL endpoint set up for my Preview service. I have gone to Deployment -> Distribution -> preview -> Distribute and added my endpoint and models with successful responses from the logs. I have also publish out the content to the Preview service and the GraphQL persisted Query to Preview. However, I keep getting the following error:

*ERROR*  GET /graphql/execute.json/xxxxx/persistedQuery;pathVariable=/content/dam/xxx/xx/xx/xxx HTTP/1.1] com.adobe.aem.graphql.impl.servlet.PersistedQueryServlet Error processing persisted query: status code - 500, details - "errors":"errorType":"QueryValidationError","message":"Persisted Query Validation Error","details":"invalid schema:\n\"QueryType\" must define one or more fields."

 

I have tried deleting and re-adding with no success. I have tried creating a new persisted query but that has a different structure but still nothing.

When I publish the content to production as well as the GraphQL query it works fine. Not sure what the disconnect is. It seems to be having problems with the root Object for the objects that being 'QueryType' (see below). It leads me to believe some sort of package for graphql is not enable for preview service

robertstull_0-1716555960283.png

When I click on the above QueryType it shows me all the defined models available for Querying.

A similar post that I followed for this setup was https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/graphql-endpoint-not-worki... 

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 1

I was able to solve this by following this issue https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/publishing-to-preview-envi...

In there they have a reference to a blog https://www.albinsblog.com/2018/02/approach-to-implement-content-preview-in-adobe-experience-manager...

I was able to take the script provided and create a workflow using 'preview' as the argument for the script in workflow. Luckily that worked. I then went through every model (about 10) and started a workflow for each one and published them out.

 

I am still confused as to why going through the Distribution (Deployment -> Distribution -> preview -> Distribute) didn't work though. When the workflow had finished I was able to go there and look at the logs for the preview target. The logs were the same saying it was successful just like when I ran it through the distribution. But the difference this time was it actually worked

View solution in original post

3 Replies

Avatar

Level 10

Hi @robertstull ,

The error you're encountering indicates that the GraphQL endpoint in the AEM Preview service is having issues with the schema, specifically the QueryType not defining any fields. This often points to a configuration issue or a problem with how the models are set up and distributed to the Preview service.

Here are steps to troubleshoot and resolve the issue:

1. Verify GraphQL Schema

Ensure that the GraphQL schema in your Preview environment is correctly set up and includes all necessary fields. The schema must define one or more fields for the QueryType.

2. Validate Model Distribution

Confirm that the models have been correctly distributed to the Preview environment:

  • Deployment -> Distribution -> Preview: Ensure that your models and endpoints are correctly listed and successfully distributed.
  • Check the logs for any errors or warnings during the distribution process.

3. Check Content Distribution

Ensure that the content has been published correctly to the Preview service:

  • Publish the required content to the Preview service.
  • Verify the content availability in the Preview environment.

4. Verify Persisted Queries

Make sure that the persisted queries are correctly set up and published to the Preview service:

  • Create and test the persisted queries in your author instance.
  • Publish the persisted queries to the Preview environment.
  • Validate that the structure and schema used in these queries match what is expected in the Preview service.

5. Inspect Configuration

Check your AEM GraphQL configuration for any discrepancies between your production and preview environments:

  • OSGi Configuration: Ensure that the GraphQL configurations (like com.adobe.aem.graphql.impl.servlet.GraphQLServlet) are consistent between environments.
  • Endpoint Configuration: Verify that the GraphQL endpoint for Preview is correctly configured and pointing to the right models and schemas.

6. Enable Detailed Logging

Enable detailed logging for the GraphQL services to get more insights into what might be going wrong:

  1. Go to the AEM Web Console: /system/console/configMgr.
  2. Find and configure the following loggers to DEBUG or TRACE:
    • com.adobe.aem.graphql.impl
    • com.adobe.cq.graphql.client

This will provide more detailed logs that can help identify the root cause of the issue.

Example Steps to Verify and Update Configurations

  1. Check Model Configuration:

    • Ensure the models used in the QueryType are correctly defined and distributed.
  2. Update GraphQL Endpoint Configuration:

 

curl -u admin:admin -F operation=publish -F path=/conf/global/settings/graphql/environments/preview -F recursive=true http://localhost:4502/bin/wcmcommand

 

Validate Schema:

  • Use the GraphQL introspection query to validate the schema in the Preview environment

 

{
  __schema {
    queryType {
      name
      fields {
        name
      }
    }
  }
}
​

 

  1. Compare Production and Preview Schema:

    • Ensure that the schema definitions in production and preview match.

Potential Fixes

  • Re-distribute Models: If the schema validation indicates missing fields, try re-distributing the models to the Preview environment.
  • Fix Model Definitions: Ensure that all necessary fields are defined in your model definitions.
  • Persisted Query Structure: Make sure that the structure of your persisted queries is valid and adheres to the schema.

By following these steps and validating configurations, you should be able to identify and resolve the issue causing the QueryType to lack defined fields in the Preview environment. If the problem persists, consider reaching out to Adobe Support for further assistance.

Avatar

Level 1

Thank you for the detailed response. 

I have tried most of the steps that you have mentioned. I think my next step is to set up the preview service locally since some of the steps you have outlined are not available for me to access in production environment such as the AEM Web Console: /system/console/configMgr. I know my models are correct as well as my queries since they run fine when I test them in Production. Therefore it must be some sort of configuration issue. I will open a support ticket. Thanks again!

Avatar

Correct answer by
Level 1

I was able to solve this by following this issue https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/publishing-to-preview-envi...

In there they have a reference to a blog https://www.albinsblog.com/2018/02/approach-to-implement-content-preview-in-adobe-experience-manager...

I was able to take the script provided and create a workflow using 'preview' as the argument for the script in workflow. Luckily that worked. I then went through every model (about 10) and started a workflow for each one and published them out.

 

I am still confused as to why going through the Distribution (Deployment -> Distribution -> preview -> Distribute) didn't work though. When the workflow had finished I was able to go there and look at the logs for the preview target. The logs were the same saying it was successful just like when I ran it through the distribution. But the difference this time was it actually worked