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/edit
. This 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 must contain one top-level and
or
or
element, which can then contain any number of
child search elements. 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 search elements are
combined with AND
operators:
(classification:"tag:tomorrowonline@escenic.com,2017:politics" AND contenttype:"story")
If the top level element were an or
element instead,
then the search elements would be combined with OR
operators:
(classification:"tag:tomorrowonline@escenic.com,2017:politics" OR contenttype:"story")
Even if your query only has one search element, the Cook requires you to
have an and
or or
element 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 search elements of an and
or
or
element may themselves be and
or or
elements. not
elements 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 a data source query by clicking the editor's play button ( ), 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:
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 save 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.