All Projects → contentacms → contentajs-graphql

contentacms / contentajs-graphql

Licence: MIT license
GraphQL.js helpers for Contenta JS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to contentajs-graphql

ts-init
Minimalist TypeScript package initializer - like `npm init`, but for TS.
Stars: ✭ 27 (+107.69%)
Mutual labels:  javascript-library
fancy-textfill
Fast implementation for resizing text to fill its container.
Stars: ✭ 17 (+30.77%)
Mutual labels:  javascript-library
SimpleSlider
Simple responsive slider created in pure javascript.
Stars: ✭ 21 (+61.54%)
Mutual labels:  javascript-library
DevHelpBox
we are creating this community so that other developers can get benefits of it.
Stars: ✭ 35 (+169.23%)
Mutual labels:  javascript-library
jvm.js
A Java VM bytecode library written in ES6 for Node.js
Stars: ✭ 33 (+153.85%)
Mutual labels:  javascript-library
indexeddb-orm
Indexed DB ORM
Stars: ✭ 53 (+307.69%)
Mutual labels:  javascript-library
ctxmenu
Tiny and customizable context menu generator
Stars: ✭ 20 (+53.85%)
Mutual labels:  javascript-library
Awesome-Javascript
A Curated list of Awesome JavaScript Resources
Stars: ✭ 116 (+792.31%)
Mutual labels:  javascript-library
solid-client-js
Library for accessing data and managing permissions on data stored in a Solid Pod
Stars: ✭ 201 (+1446.15%)
Mutual labels:  javascript-library
DummyJSON
DummyJSON provides different types of REST Endpoints filled with JSON data which you can use in developing the frontend with your favorite framework and library without worrying about writing a backend.
Stars: ✭ 213 (+1538.46%)
Mutual labels:  javascript-library
tung
A javascript library for rendering html
Stars: ✭ 29 (+123.08%)
Mutual labels:  javascript-library
ionic4-sidemenu-auth
Building a Basic Ionic 4 Login Flow with Angular Router & Side Menu UI
Stars: ✭ 34 (+161.54%)
Mutual labels:  javascript-library
thenewboston-js
JavaScript library for thenewboston.
Stars: ✭ 39 (+200%)
Mutual labels:  javascript-library
picoCSS
picoCSS - really small JavaScript Framework
Stars: ✭ 62 (+376.92%)
Mutual labels:  javascript-library
lazysimon
Minimal effort 350 byte JavaScript library to lazy load all <img> on your website
Stars: ✭ 18 (+38.46%)
Mutual labels:  javascript-library
Mei.js
a minimal, simple and helpful library for you
Stars: ✭ 15 (+15.38%)
Mutual labels:  javascript-library
awesome-app-js
This document list all the javascript libs used at Soixante circuits. They are compatible with Webpack and run in the browser and / or node only.
Stars: ✭ 16 (+23.08%)
Mutual labels:  javascript-library
pinyin4js
A opensource javascript library for converting chinese to pinyin。welcome Star : P
Stars: ✭ 153 (+1076.92%)
Mutual labels:  javascript-library
kolorwheel.js
🌈 Color palette generator JavaScript library
Stars: ✭ 37 (+184.62%)
Mutual labels:  javascript-library
stackml-js
Machine Learning platform in-browser for creators
Stars: ✭ 34 (+161.54%)
Mutual labels:  javascript-library

ContentaJS GraphQL Contenta logo

ContentaJS GraphQL is a repository that contains a set of helpers to build your GraphQL project on top of Contenta JS.

GraphQL

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 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 branch. If you prefer, you can see the diff. That will show the necessary code to add GraphQL to your Contenta project.

Travis Coverage David Dependency Management Last Commit Node Documented with emdaer

Benefits of GraphQL in node.js

The most obvious benefit of having GraphQL in node.js is that you can aggregate different APIs under a single GraphQL back-end in a non-blocking I/O runtime. This will improve performance dramatically.

Another obvious benefit is that by using the Apollo Server you get many features for free (like mocking, persited queries, cache hint directives, and many additional packages). And even more if your consumers use the Apollo Client.

Another outstanding benefit is that by using GraphQL.js you are depending on the reference implementation of GraphQL. That means that it is supported by the official GraphQL team. It also means that it has extensive support and a wide community.

Installation

You can see an example of this in this demo code.

  1. Inside of your Contenta JS project add the necessary dependencies

npm install --save @contentacms/contentajs-graphql graphql graphql-tools
  1. Create a server instance with the Contena CMS URL and add it to express.
  2. Write your GraphQL types.

  3. If they follow the structure of your JSON API resources they’ll get automatically resolved. See this example of an Article type.

  4. If there are any additional fields, you can resolve them the GraphQL way. This example creates an extra field called random. In order to resolve the value of random you will need a resolver like this one.

  5. THAT’S IT.

The @fromJsonApi(…) directive

The @fromJsonApi(…) is the biggest motivator of this repository. Since JSON API allows you to get the information you need and only the information you need, in a single request, it is the perfect data fetcher for your GraphQL.js project.

This directive will intelligently turn the response from JSON API into the hierarchical format that GraphQL expects. This includes all the nested relationships at all levels. This leaves everything ready for the user to start selecting fields for the response.

Examples

Imagine you have these top level fields in your GraphQL query.

type Query {
  lastRecipe: Recipe
    @fromJsonApi(query: "/recipes?page[limit]=1&sort=createdAt&include=author")
  recipesByAuthor(authorName: String!): [Recipe]
    @fromJsonApi(
      query: "/recipes?filter[author.name]={authorName}&include=author"
    )
  articlesByAuthor(authorName: String!): [Article]
    @fromJsonApi(
      query: "/articles?filter[owner.name]={authorName}&include=owner"
    )
}

Note how you can specify a templated URL with variables. The replacement value for these variables will be specified in the query. For instance see how the {authorName} value is provided when the front-end is querying the GraphQL server like:


curl -X GET \
  'http://localhost:3000/graphql?query={recipesByAuthor(authorName:"Umami"){title,id,random,author{name}}}'

Videos

Take a look at the video series for the ContentaJS GraphQL introduction.

ContentaJS GraphQL videoContentaJS GraphQL videoContentaJS GraphQL videoContentaJS GraphQL video
ContentaJS GraphQL videoContentaJS GraphQL videoContentaJS GraphQL videoContentaJS GraphQL video

Contributors

Contributors
Mateu Aguiló Bosch

License

@contentacms/contentajs-graphql is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].