Mapping URLs To GraphQL Queries

The GraphQL query used to retrieve content for any given URL is determined by a set of configurable mapping rules. A default mapping configuration is included in the CUE Front start pack that allows you to control what GraphQL queries are used to retrieve content in different contexts by observing the following naming conventions:

  • The query called index-page.graphql is the default query used for all section pages.

  • If you want to use different queries for some sections, create queries with names of the form index-page-section-name.graphql, where section-name is the unique name of a section. A query named like this will be used for the specified section (but not for its subsections). A query called index-page-sports.graphql, for example, will be used for the Sports section but not for any of its subsections (Football, for example).

  • There is no default query for content items. You must create a separate query for each content-type in your publication, with a name of the form content-type.graphql.

  • If you want to use different queries for certain content item types when they belong to particular sections, then you can do so by creating queries with names of the form content-type-section-name.graphql. A query called story-sports.graphql, for example, will be used for story content items that belong to the Sports section.

  • Any URL that starts with .esi/ will be directed to queries in the recipe/queries/esi folder. The query called recipe/queries/esi/header.graphql, for example, will be used to respond to requests for .esi/header. This convention is intended to support the use of Edge Side Includes. For further information, see ESI Support.

Currently, the Cook's GraphiQL editor provides no means of renaming queries or saving them under new names. If you want to make specialized queries for particular sections, then you must do it as follows:

  1. Log in on the machine where CUE Front is installed.

  2. cd to your CUE Front installation.

  3. Copy an existing query to a new name. For example:

    cp recipe/queries/index-page.graphql recipe/queries/index-page-sports.graphql
  4. Restart the Cook:

    docker-compose restart cook
  5. If you now open the GraphiQL editor in the context of the Sports section by pointing your browser to http://localhost:8101/tomorrow-online/sports/edit, you will see that the editor loads the index-page-sports.graphql query rather than index-page.graphql.

You can now modify index-page-sports.graphql so that the Cook delivers a different JSON structure for the Sports section than it does for other section pages.

Changing the default URL-query mapping

All the naming conventions described above are just the default mapping rules included in the start pack. If they do not meet your needs, you can easily extend them, or completely replace them with mappings of your own. For information on how to do this, seeConfiguring URL-GraphQL query mappings.