From dea8eb3e4309c6b6a0aeb241e4c729e37efb0b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Wed, 31 Oct 2018 00:45:34 +0100 Subject: [PATCH] docs: add better documentation --- .emdaer/README.emdaer.md | 12 ++++++++++++ .emdaer/docs/benefits.md | 12 ++++++++++++ .emdaer/docs/directive.md | 35 +++++++++++++++++++++++++++++++++++ .emdaer/docs/header.md | 13 ++++++++++--- .emdaer/docs/install.md | 12 +++++++++++- 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 .emdaer/docs/benefits.md create mode 100644 .emdaer/docs/directive.md diff --git a/.emdaer/README.emdaer.md b/.emdaer/README.emdaer.md index 94e5e4e..5768f9b 100644 --- a/.emdaer/README.emdaer.md +++ b/.emdaer/README.emdaer.md @@ -42,12 +42,24 @@ style: 'flat-square' --> + + + + ## Contributors -**IMPORTANT:** I need to finish this… +This project provides a simple Apollo server instance that you can use in your Contenta JS application. It ships wit a +very convenient [GraphQL directive](https://www.apollographql.com/docs/graphql-tools/schema-directives.html) that will +fetch data from your Contenta CMS back-end using JSON API. The result of that data fetch will be parsed and prepared so +it can be resolved by GraphQL without additional work. + +You can see this is action in the [`graphql-example-code`](https://github.com/contentacms/contentajs/tree/graphql-example-code) +branch. If you prefer, you can see [the diff](https://github.com/contentacms/contentajs/compare/9b95bba53e47220129fcf2e84eed9ceedff119d9...graphql-example-code?expand=1). +That will show the necessary code to add GraphQL to your Contenta project. diff --git a/.emdaer/docs/install.md b/.emdaer/docs/install.md index 7c35053..9350940 100644 --- a/.emdaer/docs/install.md +++ b/.emdaer/docs/install.md @@ -1,2 +1,12 @@ ## Installation -TODO +You can see an example of this in this [demo code](https://github.com/contentacms/contentajs/compare/9b95bba53e47220129fcf2e84eed9ceedff119d9...graphql-example-code?expand=1). +1. Inside of your Contenta JS project add the necessary dependencies +``` +npm install --save @contentacms/contentajs-graphql graphql graphql-tools +``` +2. [Create a server instance with the Contena CMS URL and add it to express](https://github.com/contentacms/contentajs/compare/9b95bba53e47220129fcf2e84eed9ceedff119d9...graphql-example-code?expand=1#diff-f4fed62a72fc59b66a2183017cc4b9cb). +3. Write your GraphQL types. + - If they follow the structure of your JSON API resources they'll get automatically resolved. See [this example of an Article type](https://github.com/contentacms/contentajs/compare/9b95bba53e47220129fcf2e84eed9ceedff119d9...graphql-example-code?expand=1#diff-da57a422b90e697b0a5bbe0a11699b7a). + - If there are any additional fields, you can resolve them _the GraphQL way_. This example [creates an extra field called random](https://github.com/contentacms/contentajs/compare/9b95bba53e47220129fcf2e84eed9ceedff119d9...graphql-example-code?expand=1#diff-2be3149c012f9a61fb6bbd290edde707R9). + In order to resolve the value of `random` you will need a resolver like [this one](https://github.com/contentacms/contentajs/compare/9b95bba53e47220129fcf2e84eed9ceedff119d9...graphql-example-code?expand=1#diff-895614263fb87c38476aeb8dad289b12). +4. THAT'S IT.