Skip to content

Commit

Permalink
1.0.5 (#5)
Browse files Browse the repository at this point in the history
* Feature types changes (#4)

* Up

* Added mocha.opts file with recursive param

* Replaced chainable with resolvable

* Added SimpleResolvable class

* Fixed TS Errors on build

Build error when `yarn build`:

node_modules/@types/graphql/utilities/introspectionQuery.d.ts(96,13): error TS2456: Type alias 'IntrospectionTypeRef' circularly references itself.
node_modules/@types/mocha/index.d.ts(19,16): error TS2694: Namespace 'Mocha' has no exported member 'Interface'.
node_modules/@types/mocha/index.d.ts(25,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'reporter' must be of type 'any', but here has type 'string | ReporterConstructor'.
node_modules/@types/mocha/index.d.ts(40,15): error TS2451: Cannot redeclare block-scoped variable 'mocha'.
node_modules/@types/mocha/index.d.ts(41,15): error TS2451: Cannot redeclare block-scoped variable 'describe'.
node_modules/@types/mocha/index.d.ts(42,15): error TS2451: Cannot redeclare block-scoped variable 'xdescribe'.
node_modules/@types/mocha/index.d.ts(44,15): error TS2451: Cannot redeclare block-scoped variable 'context'.
node_modules/@types/mocha/index.d.ts(46,15): error TS2451: Cannot redeclare block-scoped variable 'suite'.
node_modules/@types/mocha/index.d.ts(47,15): error TS2451: Cannot redeclare block-scoped variable 'it'.
node_modules/@types/mocha/index.d.ts(48,15): error TS2451: Cannot redeclare block-scoped variable 'xit'.
node_modules/@types/mocha/index.d.ts(50,15): error TS2451: Cannot redeclare block-scoped variable 'test'.
node_modules/@types/mocha/index.d.ts(51,15): error TS2451: Cannot redeclare block-scoped variable 'specify'.
node_modules/@types/mocha/index.d.ts(56,6): error TS2300: Duplicate identifier 'MochaDone'.
node_modules/@types/mocha/index.d.ts(75,15): error TS2300: Duplicate identifier 'Mocha'.
node_modules/@types/mocha/index.d.ts(90,28): error TS2694: Namespace 'Mocha' has no exported member 'Interface'.
node_modules/@types/mocha/index.d.ts(128,19): error TS2300: Duplicate identifier 'Mocha'.
node_modules/@types/mocha/index.d.ts(332,5): error TS2300: Duplicate identifier 'export='.
typings/globals/mocha/index.d.ts(29,13): error TS2451: Cannot redeclare block-scoped variable 'mocha'.
typings/globals/mocha/index.d.ts(30,13): error TS2451: Cannot redeclare block-scoped variable 'describe'.
typings/globals/mocha/index.d.ts(31,13): error TS2451: Cannot redeclare block-scoped variable 'xdescribe'.
typings/globals/mocha/index.d.ts(33,13): error TS2451: Cannot redeclare block-scoped variable 'context'.
typings/globals/mocha/index.d.ts(35,13): error TS2451: Cannot redeclare block-scoped variable 'suite'.
typings/globals/mocha/index.d.ts(36,13): error TS2451: Cannot redeclare block-scoped variable 'it'.
typings/globals/mocha/index.d.ts(37,13): error TS2451: Cannot redeclare block-scoped variable 'xit'.
typings/globals/mocha/index.d.ts(39,13): error TS2451: Cannot redeclare block-scoped variable 'test'.
typings/globals/mocha/index.d.ts(40,13): error TS2451: Cannot redeclare block-scoped variable 'specify'.
typings/globals/mocha/index.d.ts(45,11): error TS2300: Duplicate identifier 'MochaDone'.
typings/globals/mocha/index.d.ts(62,15): error TS2300: Duplicate identifier 'Mocha'.
typings/globals/mocha/index.d.ts(110,19): error TS2300: Duplicate identifier 'Mocha'.
typings/globals/mocha/index.d.ts(229,5): error TS2300: Duplicate identifier 'export='.

* Updated Readme

Added tests instruction and contributing section

* 1.0.5
  • Loading branch information
theGlenn authored Jun 1, 2018
1 parent 737547b commit 1447cbb
Show file tree
Hide file tree
Showing 48 changed files with 3,645 additions and 520 deletions.
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# :shipit: graphql-resolved :shipit:
`graphql-resolved` provides a **middleware**-like capability to your GraphQL servers by enabling the combination of multiple resolvers through a simple and expressive API.
> Provides a **middleware**-like capability to your GraphQL api by enabling the combination of multiple resolvers through a simple and expressive API.
Resolvers solved :shipit:

[![NPM][npm-image]][npm-url]

[![Build Status][travis-image]][travis-url]
[![npm version](https://badge.fury.io/js/graphql-resolved.svg)](https://badge.fury.io/js/graphql-resolved)

[npm-url]: https://nodei.co/npm/graphql-resolved/
[npm-image]: https://nodei.co/npm/graphql-resolved.png?downloads=true&downloadRank=true&stars=true
Expand All @@ -15,27 +16,26 @@ Resolvers solved :shipit:

## Installing

#### npm
```
```bash
npm i graphql-resolved --save
```

#### yarn
##### or

```
```bash
yarn add graphql-resolved
```

## Usage
### Create your first resolver using the `chain`, `protect` or `apply` api

#### `chain` api

Create a new resolver chaining the ones in the supplied array. *The order matters from left to right*.
The last resolver being the one return the final expect value.
#### `chain`
Return a resolver that is the sum of the ones in the supplied array.
*The execution order follows the order from left to right*.
The last resolver being the one to return the final expect value.
```chain([1, 2, 3, 4])```

```javascript
```ts
import { chain } from 'graphql-resolved';
import { isAuthenticated, isAdmin, isTopContributer } from './auth/resolvers';
import * as UserResolvers from './user/resolvers';
Expand All @@ -51,23 +51,23 @@ const resolvers = {
}
```

#### `apply` api
Applies all the `resolvers` to all of those in the `to` object.
- `resolvers` (*The order matters from left to right*)
```javascript
#### `apply`
Applies a list of `resolvers` to each of those supplied by the `to` object.
- `resolvers` *The execution order follows the order from left to right*.
```ts
const allUserResolvers = apply({ resolvers: [isAuthenticated], to: UserResolvers })
const Query = {
...allUserResolvers
}
```

#### `protect` api
#### `protect`
The protect key work take three arguments:
- `it` (Optional) a resolver function, if supplied `protect` returns a new resolver function
- `all`(Optional) an object with resolvers, if supplied `protect` returns an object with the exact same resolvers names as keys
- `all`(Optional) a map of resolvers, if supplied `protect` returns an object with the exact same resolvers names as keys
- `using` a list of resolvers to apply(*The order matters from left to right*).

```javascript
```ts
const getMe = protect({
it: UserResolvers.getMe,
using: [isAuthenticated]
Expand All @@ -82,4 +82,24 @@ const Query = {
getMe
...adminResolvers
}
```
```

## Tests

```bash
npm test
```

##### or

```bash
yarn test
```

## Contributing

Please feel free to drop an issue or propose a feature or pull request.

## License

MIT
11 changes: 0 additions & 11 deletions dist/resolvers/Chainable.d.ts

This file was deleted.

33 changes: 0 additions & 33 deletions dist/resolvers/Chainable.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/resolvers/Chainable.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion dist/resolvers/apis/apply.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResolversMap, Resolvers } from './../resolvers.types';
import { ResolversMap, Resolvers } from './../types';
export interface ApplyArgs<R> {
resolvers: Resolvers;
to: ResolversMap;
Expand Down
4 changes: 2 additions & 2 deletions dist/resolvers/apis/apply.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/resolvers/apis/apply.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/resolvers/apis/chain.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { ResolverFunction, ChainedFunction } from './../resolvers.types';
export declare const chain: <R>(resolvers: ResolverFunction<any>[]) => ChainedFunction<any> | ChainedFunction<R>;
import { ResolverFunction, PureResolverFunction } from './../types';
export declare const chain: <R = any>(resolvers: ResolverFunction<any>[]) => PureResolverFunction<R>;
5 changes: 2 additions & 3 deletions dist/resolvers/apis/chain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/resolvers/apis/chain.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/resolvers/apis/protect.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ResolverFunction, ResolversMap, Resolvers, ChainedFunction } from './../resolvers.types';
import { ResolverFunction, ResolversMap, Resolvers, PureResolverFunction } from './../types';
export interface ProtectArgs<R> {
it?: ResolverFunction<R>;
all?: ResolversMap;
using: Resolvers;
}
export declare const protect: <R>({ it, all, using }: ProtectArgs<R>) => ResolversMap | ChainedFunction<any>;
export declare const protect: <R>({ it, all, using }: ProtectArgs<R>) => ResolversMap | PureResolverFunction<any>;
3 changes: 1 addition & 2 deletions dist/resolvers/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './apis';
export * from './resolvers.types';
export * from './types';
export * from './resolvers.check';
export * from './Chainable';
2 changes: 1 addition & 1 deletion dist/resolvers/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/resolvers/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/resolvers/resolvers.check.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export declare const isArray: (resolvers: any) => boolean;
export declare const isApplyArgs: (args: any) => boolean;
1 change: 0 additions & 1 deletion dist/resolvers/resolvers.check.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/resolvers/resolvers.check.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions dist/resolvers/resolvers.types.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/resolvers/resolvers.types.js.map

This file was deleted.

16 changes: 16 additions & 0 deletions dist/resolvers/types/Resolvables.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ResolverFunction, PureResolverFunction } from './Resolvers';
export interface Resolvable<R = any> {
evaluate(root: any, args: {}, context: {}, info: any): Promise<R>;
}
export declare function isResolvable(object: any): object is Resolvable;
export declare type ResolvableSequenceArgs = Array<Resolvable | ResolverFunction>;
export declare class ResolvableSequence<R = any> {
resolvables: Resolvable<R>[];
constructor(resolvers: ResolvableSequenceArgs);
resolved(): PureResolverFunction<R>;
}
export declare class SimpleResolvable<R = any> implements Resolvable<R> {
private resolver;
constructor(resolver: ResolverFunction<R>);
evaluate(root: any, args: {}, context: {}, info: any): Promise<R>;
}
49 changes: 49 additions & 0 deletions dist/resolvers/types/Resolvables.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/resolvers/types/Resolvables.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions dist/resolvers/types/Resolvers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GraphQLResolveInfo } from 'graphql';
export interface ResolverFunction<Result = any> {
(root: any, args: {}, context: {}, info: GraphQLResolveInfo): Promise<Result> | Result | never;
}
export interface PureResolverFunction<FinalResult = any> extends ResolverFunction<FinalResult> {
(root: any, args: {}, context: {}, info: GraphQLResolveInfo | any): Promise<FinalResult>;
}
export declare type Resolvers = Array<ResolverFunction>;
export interface ResolversMap {
[key: string]: ResolverFunction;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/resolvers/types/Resolvers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/resolvers/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Resolvables';
export * from './Resolvers';
7 changes: 7 additions & 0 deletions dist/resolvers/types/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/resolvers/types/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require ts-node/register
--recursive
src/**/*.spec.ts
Loading

0 comments on commit 1447cbb

Please sign in to comment.