This is not a complete solution for setting up a GraphQL server to serve ninjs content, but it is a test to show how you can use GraphQL to filter and adjust the ninjs data returned.
A more realistic setup would need to add support to connect to the database where the ninjs objects are stored.
- Clone or copy this repo to your local machine.
- Open a terminal window and move to the
tools/graphql-ninjsfolder. - Run
npm install - Type
npm run dev - and you should see this line: "Running GraphQL on localhost:4001/graphql"
- Open a browser
- Go to http://localhost:4001/graphql
- If it all worked you should see a testing interface for graphQL
-
Start by entering this simple query:
{ ninjs { uri } }and press the round RUN button with the arrow. You should see a list of URIs from ninjs news items.
-
Try to add other properties to your query. The screen has some intellisense and uses the schema to show possible choices as you type.
-
Try adding more properties to your search:
{ ninjs { uri pubStatus language headlines { value } } }Press the 'run' button, and the results will show these four properties for each ninjs item.
-
If you want to filter the result you can add that in parentheses after
ninjs. For example, the following query:{ ninjs (pubStatus: "usable", language: "sv") { uri pubStatus language headlines { value } } }will only show the usable items in Swedish.
If you want certain types of items you can filter on type like type: "text"
The samples in the data.json come from TT, NTB, DPA and AP. They have been adapted to fit the ninjs 3.0 schema.
Johan Lindgren, October 2024