OO Underpinnings for ease of GraphQL Implementation
npm install graphql-lattice     !package version
> GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
Facebook provides an excellent source of information on learning GraphQL and interfacing it with various server side language implementations that you might be using. To learn more about this, head over to their site.
class Component extends React.Component. Extensive inheritance and any over abundance of abstraction will likely lead you to a hole that will be hard to get out of, nor is the recommended way to use GraphQL Lattice.The primary goals of Lattice are
* Provide a consistent method of logically keeping your Schema for a given type next to the resolvers and implementation that make it up.
* Provide an easy way to add documentation to every level of your Schema, programmatically, while still using GraphQL SDL/IDL to define the structure of your Schema.
* Prevent any manual labor involved in merging the Query or Mutation types you've defined for all the GraphQL Object types you've put together in your application.
_Uses ASTs, not string parsing, in order to make this happen*_
Much of the newer Lattice code emphasizes the usage of ES7 Decorators and other advanced JavaScript features such as Proxies. While ES7 Decorators are not required, their usage reduces a lot of boilerplate and are the recommended way to write Lattice code.
ModuleParser. The ModuleParser, given a directory of GQLBase extended, or Lattice, classes, will automatically extract and build your Schema from this extraction. So, if you have a directory structure such as this``sh`
gql
βββ enums
βββ interfaces
βββ types
βββ Job.js
βββ Person.js
You could write code like like the following and no matter how many types, enums, interfaces or more that you ended up writing in the future, as long as that code was placed under the ./src/gql directory path passed to ModuleParser, it would automatically be loaded and ready for use going forward.
The idea of JavaScript dynamically loading this code on startup is contentious to some and this is why it is optional, but Lattice is focused on removing unnecessary boilerplate so that you can focus on getting your work done. This is one way that it can do so.
`js
import { Router } from 'express'
import { GQLExpressMiddleware, ModuleParser } from 'graphql-lattice'
const router = Router();
const parser = new ModuleParser('./src/gql')
const lattice = new GQLExpressMiddleware(parser.parseSync())
router.use('/graphql', lattice.middleware)
`
|Version| π§ |Changes|
|-------|---|-------|
|2.13.0|β
|Support "lattice" package.json entries|
||β
| β’ ModuleParser file extensions and failOnError flag|utils/getLatticePrefs
||β
| β’ Error handling; die or continue|
||β
|GQLBase|
||β
| β’Β AutoProps - automatically apply @Properties for fields missing resolvers (1:1 type/model mapping)|
||β
| fetches prefs from local package.jsonModuleParser
||β
||getProp
||β
| β’ Capture errors as they occur decide whether to die or continue based on prefs|
||β
| β’ Process only registered extensions|
||β
| β’Β Capture error for each file processed that throws for later processing|
||β
|Additional unit tests|
||β
| in GQLBase to fetch property resolver regardless of type|getResolver
||β
| in GQLBase to fetch a resolver from class or instance|target[key]
|2.13.1|β
|Fix overzealous auto-prop creation|
||β
| β’ AutoProps were being created when they shouldn't due to how existing property existence was being tested|
||β
| β’ Fixed the usage of to descriptor.value for @resolver/@mutator/@subscriptor usage|types.js
|2.13.6|β
|Refactor into its own repo ne-types`|
Until the new, under construction website is released, you can take a look at some of these quickstart boilerplate setups.
Server Only
https://github.com/nyteshade/lattice-quickstart
React Client with Lattice/Express Backend
https://github.com/nyteshade/lattice-markdown-server-client