Creating a Data Source

To create a data source, start up your browser and navigate to the "Cook view" of any page in your publication. For example: http://cue-front-host:8101/tomorrow-online/. You should see the JSON data for the page you have chosen. Now add the /edit suffix to the URL to display the GraphiQL editor. Make sure that the editor is displayed and that it has a Save button. If it doesn't, then you need to enable saving (see Saving Your GraphQL changes).

If saving is enabled, then replace the /edit suffix with /_datasource/politicalContent. This URL means "show me the data source query called politicalContent, in the context of http://cue-front-host:8101/tomorrow-online/. Assuming you haven't already created a data source query called politicalContent, what you will see is the following message:

{
  message: "No query found with name 'politicalContent'"
}

Adding /edit to the end of this URL (so the whole URL is http://cue-front-host:8101/tomorrow-online/_datasource/politicalContent/edit) should give you a new, empty GraphiQL editor with the title politicalContent.graphql. To start your query, enter:

query {
  
}

and with the cursor inside the braces, press Ctrl-Space. You will see that the editor works in the same way as when editing a content retrieval query, but that the options available to you are different. If you explore the help in the Docs section on the right side of the editor, you will see that it too now contains completely different information, aimed at helping you build a data source query rather than a content retrieval query.

A data source query is made by combining special functions called filters. The root query field may contain only one top-level filter: an and, an or or a related(). All the other filter types can only be used as children of an and or or filter. For example:

query {
  and {
    tag(tag: "tag:tomorrowonline@escenic.com,2017:politics")
    type(name: "story")
  }
}

This will generate a Solr query in which the child filters are combined with AND operators:

(classification:"tag:tomorrowonline@escenic.com,2017:politics" AND contenttype:"story")

If the top level filter was an or instead, then the filters would be combined with OR operators:

(classification:"tag:tomorrowonline@escenic.com,2017:politics" OR contenttype:"story")

Even if your query only has one such filter, the Cook requires you to have an and or or at the top level (although in this case, of course, it doesn't matter which you choose). This data source query:

query {
  and {
    type(name: "story")
  }
}

will generate this Solr query:

(contenttype:"story")

The child filters in an and or or filter may themselves be and or or filters. not filters are also allowed. This allows you to construct more sophisticated queries. This data source query, for example:

query {
  and {
    tag (tag: "tag:tomorrowonline@escenic.com,2017:politics")
    not {
      tag (tag: "tag:tomorrowonline@escenic.com,2017:elections")
    } 
    or {
     type (name: "story")
     type (name: "picture")
    }
  }
}

will generate this Solr query:

(classification:"tag:tomorrowonline@escenic.com,2017:politics"
AND -(classification:"tag:tomorrowonline@escenic.com,2017:elections") 
AND (contenttype:"story" OR contenttype:"picture"))
(contenttype:"story")

When you execute this kind of data source query by clicking the editor's play button ( graphics/execute.png ), the Cook:

  • Generates a Solr query

  • Submits the query to Solr

  • Displays a response in the editor containing both the query submitted to Solr and the response. The Solr response is a JSON structure containing information about the matching content items found.

For example:

graphics/datasource-results.png

You can use this output to verify that your query is working correctly and returning the content you are interested in. Once you are satisfied, you can save the query by clicking the Save button. The query is saved in your CUE Front's recipe/datasources folder. You can modify it at any time either by opening recipe/datasources/politicalContent.graphql in an editor of your choice or by returning to http://cue-front-host:8101/tomorrow-online/_datasource/politicalContent/edit in the browser.

The top level filter related() is different from all the other data source filters in that it is not implemented using Solr, but works by directly accessing the Content Engine web service. For further information, see Related.