@makerx/graphql-core 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -0
- package/index.js.map +1 -1
- package/models.d.ts +5 -0
- package/models.d.ts.map +1 -0
- package/models.js +3 -0
- package/models.js.map +1 -0
- package/package.json +4 -2
- package/schema-util.d.ts +10 -0
- package/schema-util.d.ts.map +1 -0
- package/schema-util.js +29 -0
- package/schema-util.js.map +1 -0
- package/shield.d.ts +43 -0
- package/shield.d.ts.map +1 -0
- package/shield.js +52 -0
- package/shield.js.map +1 -0
package/index.d.ts
CHANGED
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
|
package/index.js
CHANGED
|
@@ -19,4 +19,7 @@ __exportStar(require("./User"), exports);
|
|
|
19
19
|
__exportStar(require("./utils"), exports);
|
|
20
20
|
__exportStar(require("./logging"), exports);
|
|
21
21
|
__exportStar(require("./subscriptions"), exports);
|
|
22
|
+
__exportStar(require("./schema-util"), exports);
|
|
23
|
+
__exportStar(require("./shield"), exports);
|
|
24
|
+
__exportStar(require("./models"), exports);
|
|
22
25
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,yCAAsB;AACtB,0CAAuB;AACvB,4CAAyB;AACzB,kDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,yCAAsB;AACtB,0CAAuB;AACvB,4CAAyB;AACzB,kDAA+B;AAC/B,gDAA6B;AAC7B,2CAAwB;AACxB,2CAAwB"}
|
package/models.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type Primitive = string | number | symbol | bigint | boolean | null | undefined | Date;
|
|
2
|
+
type ScalarPropsInternal<T, TKey extends keyof T, TAdditionalScalars = never> = TKey extends any ? T[TKey] extends Primitive | TAdditionalScalars ? TKey : never : never;
|
|
3
|
+
export type ScalarProps<T, TAdditionalScalars = never> = Pick<T, ScalarPropsInternal<T, keyof T, TAdditionalScalars>>;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=models.d.ts.map
|
package/models.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAA;AAG7F,KAAK,mBAAmB,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,CAAC,EAAE,kBAAkB,GAAG,KAAK,IAAI,IAAI,SAAS,GAAG,GAC5F,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,kBAAkB,GAC5C,IAAI,GACJ,KAAK,GACP,KAAK,CAAA;AACT,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,kBAAkB,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAA"}
|
package/models.js
ADDED
package/models.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"main": "index.js",
|
|
3
3
|
"types": "index.d.ts",
|
|
4
4
|
"name": "@makerx/graphql-core",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.1.0",
|
|
6
6
|
"private": false,
|
|
7
7
|
"description": "A set of core GraphQL utilities that MakerX uses to build GraphQL APIs",
|
|
8
8
|
"author": "MakerX",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"lodash.pick": "^4.4.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
+
"graphql-shield": "*",
|
|
27
28
|
"express": "*",
|
|
28
29
|
"graphql": "*",
|
|
29
30
|
"graphql-ws": "*",
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
}
|
|
39
40
|
},
|
|
40
41
|
"overrides": {
|
|
41
|
-
"
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
43
|
+
"@typescript-eslint/parser": "^6.0.0"
|
|
42
44
|
}
|
|
43
45
|
}
|
package/schema-util.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* It is possible to register a custom scalar with apollo server without defining an explicit resolver (a default resolver is used in
|
|
4
|
+
* this case), but it is rarely desirable. This function, when provided with your built schema, will ensure any registered scalar types
|
|
5
|
+
* provide at least a base level of validation by failing to parse a Symbol instance. The default resolver does not pass this test
|
|
6
|
+
* meaning any scalars that are falling back to the default resolver will fail.
|
|
7
|
+
* @param schema A schema object, the result of calling `makeExecutableSchema` from `@graphql-tools/schema`
|
|
8
|
+
*/
|
|
9
|
+
export declare function requireExplicitResolversForScalars(schema: GraphQLSchema): void;
|
|
10
|
+
//# sourceMappingURL=schema-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-util.d.ts","sourceRoot":"","sources":["../src/schema-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,MAAM,SAAS,CAAA;AAE1D;;;;;;GAMG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,aAAa,QAevE"}
|
package/schema-util.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireExplicitResolversForScalars = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
/**
|
|
6
|
+
* It is possible to register a custom scalar with apollo server without defining an explicit resolver (a default resolver is used in
|
|
7
|
+
* this case), but it is rarely desirable. This function, when provided with your built schema, will ensure any registered scalar types
|
|
8
|
+
* provide at least a base level of validation by failing to parse a Symbol instance. The default resolver does not pass this test
|
|
9
|
+
* meaning any scalars that are falling back to the default resolver will fail.
|
|
10
|
+
* @param schema A schema object, the result of calling `makeExecutableSchema` from `@graphql-tools/schema`
|
|
11
|
+
*/
|
|
12
|
+
function requireExplicitResolversForScalars(schema) {
|
|
13
|
+
const testSymbol = Symbol('testSymbol');
|
|
14
|
+
const scalars = Object.values(schema.getTypeMap()).filter((t) => t instanceof graphql_1.GraphQLScalarType);
|
|
15
|
+
for (const scalar of scalars) {
|
|
16
|
+
if (scalar.name === 'Void')
|
|
17
|
+
continue;
|
|
18
|
+
try {
|
|
19
|
+
scalar.parseValue(testSymbol);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// We expect that a parser should not handle parsing a symbol
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Scalar ${scalar.name} does not appear to have an explicit resolver, or is not performing sufficient validation when parsing input`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.requireExplicitResolversForScalars = requireExplicitResolversForScalars;
|
|
29
|
+
//# sourceMappingURL=schema-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-util.js","sourceRoot":"","sources":["../src/schema-util.ts"],"names":[],"mappings":";;;AAAA,qCAA0D;AAE1D;;;;;;GAMG;AACH,SAAgB,kCAAkC,CAAC,MAAqB;IACtE,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;IACvC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAA0B,EAAE,CAAC,CAAC,YAAY,2BAAiB,CAAC,CAAA;IACxH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;YAAE,SAAQ;QACpC,IAAI;YACF,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;SAC9B;QAAC,MAAM;YACN,6DAA6D;YAC7D,SAAQ;SACT;QACD,MAAM,IAAI,KAAK,CACb,UAAU,MAAM,CAAC,IAAI,8GAA8G,CACpI,CAAA;KACF;AACH,CAAC;AAfD,gFAeC"}
|
package/shield.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ShieldRule } from 'graphql-shield/typings/types';
|
|
2
|
+
import { Primitive } from './models';
|
|
3
|
+
import { and, chain, or, race } from 'graphql-shield';
|
|
4
|
+
type RuleCombinator = typeof chain | typeof race | typeof or | typeof and;
|
|
5
|
+
export declare const createRule: <TContext, TParent = unknown, TArgs = unknown>(logic: (parent: TParent, args: TArgs, ctx: TContext) => boolean | Promise<boolean> | Error, cache?: 'contextual' | 'strict') => import("graphql-shield/typings/rules").Rule;
|
|
6
|
+
/**
|
|
7
|
+
* Combines a given rule with all existing defined rules using the provided combinator
|
|
8
|
+
* @param schema The existing shield schema with rules
|
|
9
|
+
* @param rule The rule to be combined with existing rules
|
|
10
|
+
* @param combinator The combinator to use. Eg. and | or | chain | race
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
*
|
|
14
|
+
* const updatedSchema = combineRuleWithAll(shieldSchema, rules.accountNotBlocked, chain)
|
|
15
|
+
*/
|
|
16
|
+
export declare function combineRuleWithAll<T>(schema: ShieldSchema<T>, rule: ShieldRule, combinator: RuleCombinator): ShieldSchema<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates graphql shield middleware making use of generics to type the definition of the rules.
|
|
19
|
+
* @param schema A mapping of schema objects to the shield rules that define the access to that object
|
|
20
|
+
* @param fallbackRule A fallback rule to apply to any object or property which doesn't have a defined rule.
|
|
21
|
+
*
|
|
22
|
+
* Usage:
|
|
23
|
+
* import { Resolvers } from '../generated/types'
|
|
24
|
+
*
|
|
25
|
+
* const shieldSchema = createShieldSchema<Resolvers>({
|
|
26
|
+
* Query: {
|
|
27
|
+
* getThings: allow,
|
|
28
|
+
* dontGetThings: deny,
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* let schema = makeExecutableSchema({...})
|
|
33
|
+
*
|
|
34
|
+
* schema = applyMiddleware(schema, shieldSchema)
|
|
35
|
+
*/
|
|
36
|
+
export declare function createShieldSchema<TRootResolvers>(schema: ShieldSchema<TRootResolvers>, fallbackRule?: ShieldRule): import("graphql-middleware").IMiddlewareGenerator<any, any, any>;
|
|
37
|
+
export type ShieldSchema<TResolver> = TResolver extends Primitive ? ShieldRule : {
|
|
38
|
+
[key in keyof TResolver]?: ShieldSchema<TResolver[key]> | ShieldRule;
|
|
39
|
+
} & {
|
|
40
|
+
'*'?: ShieldRule;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=shield.d.ts.map
|
package/shield.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shield.d.ts","sourceRoot":"","sources":["../src/shield.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAgB,MAAM,gBAAgB,CAAA;AAE1E,KAAK,cAAc,GAAG,OAAO,KAAK,GAAG,OAAO,IAAI,GAAG,OAAO,EAAE,GAAG,OAAO,GAAG,CAAA;AAEzE,eAAO,MAAM,UAAU,yGACmC,OAAO,GAAG,QAAQ,OAAO,CAAC,GAAG,KAAK,UACnF,YAAY,GAAG,QAAQ,gDAC2C,CAAA;AAE3E;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC,CAAC,CAS5H;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,EAAE,YAAY,GAAE,UAAkB,oEAKxH;AAED,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,SAAS,SAAS,SAAS,GAC7D,UAAU,GACV;KACG,GAAG,IAAI,MAAM,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU;CACrE,GAAG;IACF,GAAG,CAAC,EAAE,UAAU,CAAA;CACjB,CAAA"}
|
package/shield.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createShieldSchema = exports.combineRuleWithAll = exports.createRule = void 0;
|
|
4
|
+
const graphql_shield_1 = require("graphql-shield");
|
|
5
|
+
const createRule = (logic, cache = 'strict') => (0, graphql_shield_1.rule)({ cache })(async (parent, args, ctx) => logic(parent, args, ctx));
|
|
6
|
+
exports.createRule = createRule;
|
|
7
|
+
/**
|
|
8
|
+
* Combines a given rule with all existing defined rules using the provided combinator
|
|
9
|
+
* @param schema The existing shield schema with rules
|
|
10
|
+
* @param rule The rule to be combined with existing rules
|
|
11
|
+
* @param combinator The combinator to use. Eg. and | or | chain | race
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* const updatedSchema = combineRuleWithAll(shieldSchema, rules.accountNotBlocked, chain)
|
|
16
|
+
*/
|
|
17
|
+
function combineRuleWithAll(schema, rule, combinator) {
|
|
18
|
+
return Object.fromEntries(Object.entries(schema).map(([key, value]) => {
|
|
19
|
+
if (value.constructor.name !== 'Object') {
|
|
20
|
+
return [key, combinator(rule, value)];
|
|
21
|
+
}
|
|
22
|
+
return [key, combineRuleWithAll(value, rule, combinator)];
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
exports.combineRuleWithAll = combineRuleWithAll;
|
|
26
|
+
/**
|
|
27
|
+
* Creates graphql shield middleware making use of generics to type the definition of the rules.
|
|
28
|
+
* @param schema A mapping of schema objects to the shield rules that define the access to that object
|
|
29
|
+
* @param fallbackRule A fallback rule to apply to any object or property which doesn't have a defined rule.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* import { Resolvers } from '../generated/types'
|
|
33
|
+
*
|
|
34
|
+
* const shieldSchema = createShieldSchema<Resolvers>({
|
|
35
|
+
* Query: {
|
|
36
|
+
* getThings: allow,
|
|
37
|
+
* dontGetThings: deny,
|
|
38
|
+
* }
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* let schema = makeExecutableSchema({...})
|
|
42
|
+
*
|
|
43
|
+
* schema = applyMiddleware(schema, shieldSchema)
|
|
44
|
+
*/
|
|
45
|
+
function createShieldSchema(schema, fallbackRule = graphql_shield_1.allow) {
|
|
46
|
+
return (0, graphql_shield_1.shield)(schema, {
|
|
47
|
+
allowExternalErrors: true,
|
|
48
|
+
fallbackRule: fallbackRule,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.createShieldSchema = createShieldSchema;
|
|
52
|
+
//# sourceMappingURL=shield.js.map
|
package/shield.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shield.js","sourceRoot":"","sources":["../src/shield.ts"],"names":[],"mappings":";;;AAEA,mDAA0E;AAInE,MAAM,UAAU,GAAG,CACxB,KAA0F,EAC1F,QAAiC,QAAQ,EACzC,EAAE,CAAC,IAAA,qBAAI,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;AAH9D,QAAA,UAAU,cAGoD;AAE3E;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAAI,MAAuB,EAAE,IAAgB,EAAE,UAA0B;IACzG,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1C,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE;YACvC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;SACtC;QACD,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAA;IAC3D,CAAC,CAAC,CACgB,CAAA;AACtB,CAAC;AATD,gDASC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,kBAAkB,CAAiB,MAAoC,EAAE,eAA2B,sBAAK;IACvH,OAAO,IAAA,uBAAM,EAAC,MAAgB,EAAE;QAC9B,mBAAmB,EAAE,IAAI;QACzB,YAAY,EAAE,YAAY;KAC3B,CAAC,CAAA;AACJ,CAAC;AALD,gDAKC"}
|