Skip to content

Commit 82f9a84

Browse files
committed
feat: initial commit
0 parents  commit 82f9a84

15 files changed

+3908
-0
lines changed

.codebeatsettings

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"TYPESCRIPT": {
3+
"TOTAL_LOC": [500, 1000, 1500, 2000],
4+
"TOO_MANY_FUNCTIONS": [40, 50, 60, 70],
5+
"TOTAL_COMPLEXITY": [100, 180, 280, 400]
6+
}
7+
}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.ssh/
2+
dist/
3+
tmp/
4+
out-tsc/
5+
build/
6+
.nyc_output/
7+
node_modules/
8+
.idea/
9+
.project
10+
.classpath
11+
.c9/
12+
*.launch
13+
.settings/
14+
*.sublime-workspace
15+
.vscode/*
16+
.sass-cache/
17+
connect.lock/
18+
coverage/
19+
typings/
20+
docs/
21+
debug*
22+
*.txt
23+
*.js
24+
*.d.ts
25+
*.js.map
26+
*.pid
27+
*.log
28+
*.swp
29+
*.tgz
30+
.env
31+
.eslintrc
32+
.editorconfig
33+
.gitlab-ci.yml
34+
.DS_Store
35+
Thumbs.db

.npmignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.gitignore
2+
.travis.yml
3+
.dockerignore
4+
.codebeatignore
5+
.codebeatsettings
6+
7+
.ssh/
8+
dist/
9+
tmp/
10+
out-tsc/
11+
build/
12+
.nyc_output/
13+
14+
node_modules/
15+
16+
.idea/
17+
.project
18+
.classpath
19+
.c9/
20+
*.launch
21+
.settings/
22+
*.sublime-workspace
23+
.vscode/*
24+
.env
25+
26+
.sass-cache/
27+
connect.lock/
28+
coverage/
29+
typings/
30+
docs/
31+
32+
debug*
33+
*.pid
34+
*.log
35+
.DS_Store
36+
Thumbs.db
37+
38+
test/
39+
40+
*.js.map
41+
*.ts
42+
!*.d.ts
43+
tsconfig.json
44+
45+
*.tgz

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist: xenial
2+
language: node_js
3+
node_js:
4+
- lts/*

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2019, imqueue.com <support@imqueue.com>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose
4+
with or without fee is hereby granted, provided that the above copyright notice
5+
and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13+
PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# @imqueue/type-graphql-dependency
2+
3+
[![Build Status](https://travis-ci.com/type-graphql-dependency/type-graphql-dependency.svg?branch=master)](https://travis-ci.com/imqueue/type-graphql-dependency)
4+
[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://rawgit.com/imqueue/type-graphql-dependency/master/LICENSE)
5+
6+
Adoption of @imqueue/graphql-dependency for use with type-graphql.
7+
8+
# Install
9+
10+
~~~bash
11+
npm i --save @imqueue/type-graphql-dependency
12+
~~~
13+
14+
# Usage
15+
16+
This module allows describing cross-service dependencies and fetch user
17+
requested data in an optimal manner in a schemas defined using type-graphql
18+
library.
19+
20+
Example:
21+
22+
~~~typescript
23+
import {
24+
Dependency,
25+
DependencyFor,
26+
schemaHooks,
27+
} from '@imqueue/type-graphql-dependency';
28+
import { Ctx, Info } from 'type-graphql';
29+
import { fieldsMap } from 'graphql-fields-list';
30+
31+
@DependencyFor<Partial<Consumer>>({
32+
// this defines dependency relations for Consumer object.
33+
// refers to: @imqueue/graphql-dependency:Dependency.require()
34+
require: [
35+
[() => ApiKey, [
36+
{ as: 'apiKeys', filter: { 'consumerId': 'id' } }],
37+
],
38+
],
39+
// this defines initializer for Consumer, all dependencies will wait
40+
// for initializer to finish before load
41+
// refers to: @imqueue/graphql-dependency:Dependency.defineInitializer()
42+
async init(
43+
context: Context,
44+
result: Partial<Consumer>,
45+
fields?: FieldsInput,
46+
): Promise<DataInitializerResult> {
47+
// ... do initializer stuff here ...
48+
return result;
49+
},
50+
// this defines loader for Consumer entity, which should be used by
51+
// other entities, which depend on Consumer
52+
// refers to: @imqueue/graphql-dependency:Dependency.defineLoader()
53+
async load(
54+
context: Context,
55+
filter: ConsumerListInput,
56+
fields?: FieldsInput,
57+
): Promise<Partial<Consumer>[]> {
58+
const { data } = await context.consumer.listConsumer(filter, fields);
59+
return toConsumers(data);
60+
},
61+
})
62+
@ObjectType()
63+
export class Consumer {
64+
// ... Consumer fields definitions goes here ...
65+
}
66+
67+
// now within a resolver:
68+
async function consumerResolver(
69+
@Ctx() context: Context,
70+
@Info() info: GraphQLResolveInfo,
71+
) {
72+
// load consumer data from some service or database
73+
const data = await loadConsumers(/* ... */);
74+
// fill dependent data into loaded data
75+
await Dependency(Consumer).load(data, context, fieldsMap(info));
76+
return data;
77+
}
78+
79+
// Now where schema is created using type-graphql:
80+
const schema = await buildSchema({
81+
// your schema options due to type-graphql docs
82+
});
83+
// and
84+
(schemaHooks || []).forEach(handle => handle && handle(schema));
85+
// so now all deps initialized within schema
86+
~~~
87+
88+
# License
89+
90+
[ISC](https://github.com/imqueue/type-graphql-dependency/blob/master/LICENSE)

index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*!
2+
* @imqueue/type-graphql-dependency - Declarative GraphQL dependency loading
3+
*
4+
* Copyright (c) 2019, imqueue.com <support@imqueue.com>
5+
*
6+
* Permission to use, copy, modify, and/or distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16+
* PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
export * from './src';

0 commit comments

Comments
 (0)