@orion-js/graphql 3.9.0 → 3.10.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/lib/buildSchema/getResolvers/index.js +4 -4
- package/lib/buildSchema/getResolvers/index.test.js +3 -3
- package/lib/buildSchema/getType/enum.test.js +3 -3
- package/lib/buildSchema/getType/getTypeAsResolver.d.ts +1 -1
- package/lib/buildSchema/getType/getTypeAsResolver.js +3 -3
- package/lib/service/global.js +9 -9
- package/lib/service/index.test.js +1 -1
- package/lib/service/model.d.ts +2 -2
- package/lib/service/model.js +7 -7
- package/lib/service/otherParams.js +1 -1
- package/lib/service/subscription.js +5 -5
- package/lib/startGraphQL.test.js +119 -74
- package/package.json +10 -10
|
@@ -13,7 +13,7 @@ async function default_1(options, mutation) {
|
|
|
13
13
|
.map(key => {
|
|
14
14
|
return {
|
|
15
15
|
name: key,
|
|
16
|
-
resolver: resolvers[key]
|
|
16
|
+
resolver: resolvers[key],
|
|
17
17
|
};
|
|
18
18
|
})
|
|
19
19
|
.filter(({ resolver }) => !!resolver.mutation === !!mutation)
|
|
@@ -26,16 +26,16 @@ async function default_1(options, mutation) {
|
|
|
26
26
|
fields[name] = {
|
|
27
27
|
type,
|
|
28
28
|
args,
|
|
29
|
-
async resolve(root, params, context) {
|
|
29
|
+
async resolve(root, params, context, info) {
|
|
30
30
|
try {
|
|
31
|
-
const result = await resolver.resolve(params, context);
|
|
31
|
+
const result = await resolver.resolve(params, context, info);
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
35
|
(0, errorHandler_1.default)(error, { context, resolver, options, name });
|
|
36
36
|
throw error;
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
},
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
return fields;
|
|
@@ -46,9 +46,9 @@ describe('Test get resolvers schema', () => {
|
|
|
46
46
|
return {
|
|
47
47
|
userId: params.userId,
|
|
48
48
|
name: 'test',
|
|
49
|
-
age: 10
|
|
49
|
+
age: 10,
|
|
50
50
|
};
|
|
51
|
-
}
|
|
51
|
+
},
|
|
52
52
|
});
|
|
53
53
|
const resolvers = { globalResolver };
|
|
54
54
|
const mutation = false;
|
|
@@ -59,7 +59,7 @@ describe('Test get resolvers schema', () => {
|
|
|
59
59
|
expect(await schema.globalResolver.resolve(null, { userId: '1' })).toEqual({
|
|
60
60
|
userId: '1',
|
|
61
61
|
name: 'test',
|
|
62
|
-
age: 10
|
|
62
|
+
age: 10,
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
});
|
|
@@ -34,7 +34,7 @@ describe('Enum test', () => {
|
|
|
34
34
|
returns: colorsEnum,
|
|
35
35
|
async resolve(params) {
|
|
36
36
|
return params.color;
|
|
37
|
-
}
|
|
37
|
+
},
|
|
38
38
|
});
|
|
39
39
|
const resolvers = { globalResolver };
|
|
40
40
|
const mutation = false;
|
|
@@ -62,7 +62,7 @@ describe('Enum test', () => {
|
|
|
62
62
|
returns: Clone1,
|
|
63
63
|
async resolve(params) {
|
|
64
64
|
return params;
|
|
65
|
-
}
|
|
65
|
+
},
|
|
66
66
|
});
|
|
67
67
|
const Clone2 = (0, typed_model_1.cloneSchemaClass)(TestParams, { name: 'TestParams3', pickFields: ['color'] });
|
|
68
68
|
const Clone3 = (0, typed_model_1.cloneSchemaClass)(TestParams, { name: 'TestParams4', pickFields: ['color'] });
|
|
@@ -71,7 +71,7 @@ describe('Enum test', () => {
|
|
|
71
71
|
returns: Clone3,
|
|
72
72
|
async resolve(params) {
|
|
73
73
|
return params;
|
|
74
|
-
}
|
|
74
|
+
},
|
|
75
75
|
});
|
|
76
76
|
const resolvers = { globalResolver, globalResolver2 };
|
|
77
77
|
const options = { resolvers };
|
|
@@ -11,16 +11,16 @@ function default_1({ resolver, getGraphQLType, options, model }) {
|
|
|
11
11
|
return {
|
|
12
12
|
type,
|
|
13
13
|
args,
|
|
14
|
-
async resolve(item, params, context) {
|
|
14
|
+
async resolve(item, params, context, info) {
|
|
15
15
|
try {
|
|
16
|
-
const result = await resolver.resolve(item, params, context);
|
|
16
|
+
const result = await resolver.resolve(item, params, context, info);
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
20
|
(0, errorHandler_1.default)(error, { context, resolver, options, model });
|
|
21
21
|
throw error;
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
},
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
exports.default = default_1;
|
package/lib/service/global.js
CHANGED
|
@@ -6,14 +6,14 @@ const resolvers_1 = require("@orion-js/resolvers");
|
|
|
6
6
|
const helpers_1 = require("@orion-js/helpers");
|
|
7
7
|
const otherParams_1 = require("./otherParams");
|
|
8
8
|
function Resolvers() {
|
|
9
|
-
return
|
|
9
|
+
return (target) => {
|
|
10
10
|
(0, services_1.Service)()(target);
|
|
11
11
|
target.prototype.service = target;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
exports.Resolvers = Resolvers;
|
|
15
15
|
function Query(options) {
|
|
16
|
-
return
|
|
16
|
+
return (target, propertyKey, descriptor) => {
|
|
17
17
|
if (!descriptor.value)
|
|
18
18
|
throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
19
19
|
target.resolvers = target.resolvers || {};
|
|
@@ -23,16 +23,16 @@ function Query(options) {
|
|
|
23
23
|
returns: (0, otherParams_1.getTargetMetadata)(target, propertyKey, 'returns'),
|
|
24
24
|
middlewares: (0, otherParams_1.getTargetMetadata)(target, propertyKey, 'middlewares'),
|
|
25
25
|
...options,
|
|
26
|
-
resolve: async (params, viewer) => {
|
|
26
|
+
resolve: async (params, viewer, info) => {
|
|
27
27
|
const instance = (0, services_1.getInstance)(target.service);
|
|
28
|
-
return await instance[propertyKey](params, viewer);
|
|
29
|
-
}
|
|
28
|
+
return await instance[propertyKey](params, viewer, info);
|
|
29
|
+
},
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
exports.Query = Query;
|
|
34
34
|
function Mutation(options) {
|
|
35
|
-
return
|
|
35
|
+
return (target, propertyKey, descriptor) => {
|
|
36
36
|
if (!descriptor.value)
|
|
37
37
|
throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
38
38
|
target.resolvers = target.resolvers || {};
|
|
@@ -43,10 +43,10 @@ function Mutation(options) {
|
|
|
43
43
|
middlewares: (0, otherParams_1.getTargetMetadata)(target, propertyKey, 'middlewares'),
|
|
44
44
|
...options,
|
|
45
45
|
mutation: true,
|
|
46
|
-
resolve: async (params, viewer) => {
|
|
46
|
+
resolve: async (params, viewer, info) => {
|
|
47
47
|
const instance = (0, services_1.getInstance)(target.service);
|
|
48
|
-
return await instance[propertyKey](params, viewer);
|
|
49
|
-
}
|
|
48
|
+
return await instance[propertyKey](params, viewer, info);
|
|
49
|
+
},
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
}
|
|
@@ -40,7 +40,7 @@ describe('Resolvers with service injection', () => {
|
|
|
40
40
|
__decorate([
|
|
41
41
|
(0, index_1.Query)({
|
|
42
42
|
params: { name: { type: 'string' } },
|
|
43
|
-
returns: String
|
|
43
|
+
returns: String,
|
|
44
44
|
}),
|
|
45
45
|
__metadata("design:type", Function),
|
|
46
46
|
__metadata("design:paramtypes", [Object]),
|
package/lib/service/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GlobalResolverResolve, ResolverOptions, ModelResolverResolve, ModelResolver } from '@orion-js/resolvers';
|
|
1
|
+
import { GlobalResolverResolve, ResolverOptions, ModelResolverResolve, ModelResolver as ModelResolverType } from '@orion-js/resolvers';
|
|
2
2
|
export interface ModelResolverPropertyDescriptor extends Omit<PropertyDecorator, 'value'> {
|
|
3
3
|
value?: ModelResolverResolve;
|
|
4
4
|
}
|
|
@@ -9,6 +9,6 @@ export interface ModelResolversOptions {
|
|
|
9
9
|
export declare function ModelResolvers(typedSchema: any, options?: ModelResolversOptions): ClassDecorator;
|
|
10
10
|
export declare function getServiceModelResolvers(target: any): {
|
|
11
11
|
[key: string]: {
|
|
12
|
-
[key: string]:
|
|
12
|
+
[key: string]: ModelResolverType<GlobalResolverResolve>;
|
|
13
13
|
};
|
|
14
14
|
};
|
package/lib/service/model.js
CHANGED
|
@@ -6,7 +6,7 @@ const resolvers_1 = require("@orion-js/resolvers");
|
|
|
6
6
|
const helpers_1 = require("@orion-js/helpers");
|
|
7
7
|
const otherParams_1 = require("./otherParams");
|
|
8
8
|
function ModelResolver(options) {
|
|
9
|
-
return
|
|
9
|
+
return (target, propertyKey, descriptor) => {
|
|
10
10
|
if (!descriptor.value)
|
|
11
11
|
throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
12
12
|
target.resolvers = target.resolvers || {};
|
|
@@ -15,20 +15,20 @@ function ModelResolver(options) {
|
|
|
15
15
|
returns: (0, otherParams_1.getTargetMetadata)(target, propertyKey, 'returns'),
|
|
16
16
|
middlewares: (0, otherParams_1.getTargetMetadata)(target, propertyKey, 'middlewares'),
|
|
17
17
|
...options,
|
|
18
|
-
resolve: async (item, params, viewer) => {
|
|
18
|
+
resolve: async (item, params, viewer, info) => {
|
|
19
19
|
const instance = (0, services_1.getInstance)(target.service);
|
|
20
|
-
return await instance[propertyKey](item, params, viewer);
|
|
21
|
-
}
|
|
20
|
+
return await instance[propertyKey](item, params, viewer, info);
|
|
21
|
+
},
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
exports.ModelResolver = ModelResolver;
|
|
26
26
|
function ModelResolvers(typedSchema, options = {}) {
|
|
27
|
-
return
|
|
27
|
+
return (target) => {
|
|
28
28
|
(0, services_1.Service)()(target);
|
|
29
29
|
target.prototype.modelName = options.modelName || typedSchema.name;
|
|
30
30
|
if (!target.prototype.modelName) {
|
|
31
|
-
throw new Error(
|
|
31
|
+
throw new Error('The specified model has no name or is not a model');
|
|
32
32
|
}
|
|
33
33
|
target.prototype.typedSchema = typedSchema;
|
|
34
34
|
target.prototype.service = target;
|
|
@@ -42,7 +42,7 @@ function getServiceModelResolvers(target) {
|
|
|
42
42
|
throw new helpers_1.UserError('You must pass a class to getResolvers');
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
|
-
[target.prototype.modelName]: target.prototype.resolvers || {}
|
|
45
|
+
[target.prototype.modelName]: target.prototype.resolvers || {},
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
exports.getServiceModelResolvers = getServiceModelResolvers;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ResolverReturns = exports.ResolverParams = exports.UseMiddleware = exports.getTargetMetadata = void 0;
|
|
4
4
|
function createRegisterResolverMetadata(metadataKey, isArray = false) {
|
|
5
5
|
return (metadata) => {
|
|
6
|
-
return
|
|
6
|
+
return (target, propertyKey, descriptor) => {
|
|
7
7
|
if (!descriptor.value)
|
|
8
8
|
throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
9
9
|
target[metadataKey] = target[metadataKey] || {};
|
|
@@ -5,7 +5,7 @@ const services_1 = require("@orion-js/services");
|
|
|
5
5
|
const helpers_1 = require("@orion-js/helpers");
|
|
6
6
|
const __1 = require("..");
|
|
7
7
|
function Subscriptions() {
|
|
8
|
-
return
|
|
8
|
+
return (target) => {
|
|
9
9
|
(0, services_1.Service)()(target);
|
|
10
10
|
target.prototype.service = target;
|
|
11
11
|
target.prototype.serviceType = 'subscriptions';
|
|
@@ -13,10 +13,10 @@ function Subscriptions() {
|
|
|
13
13
|
}
|
|
14
14
|
exports.Subscriptions = Subscriptions;
|
|
15
15
|
function Subscription(options) {
|
|
16
|
-
return
|
|
16
|
+
return (object, propertyName, index) => {
|
|
17
17
|
const sub = (0, __1.subscription)({
|
|
18
18
|
name: propertyName,
|
|
19
|
-
...options
|
|
19
|
+
...options,
|
|
20
20
|
});
|
|
21
21
|
object.subscriptions = object.subscriptions || {};
|
|
22
22
|
object.subscriptions[propertyName] = sub;
|
|
@@ -24,12 +24,12 @@ function Subscription(options) {
|
|
|
24
24
|
object,
|
|
25
25
|
propertyName,
|
|
26
26
|
index,
|
|
27
|
-
value:
|
|
27
|
+
value: _containerInstance => {
|
|
28
28
|
if (!object.serviceType || object.serviceType !== 'subscriptions') {
|
|
29
29
|
throw new Error('You must pass a class decorated with @Subscriptions if you want to use @Subscription');
|
|
30
30
|
}
|
|
31
31
|
return sub;
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
}
|
package/lib/startGraphQL.test.js
CHANGED
|
@@ -29,19 +29,19 @@ describe('Test GraphQL Server', () => {
|
|
|
29
29
|
helloWorld: (0, resolvers_1.resolver)({
|
|
30
30
|
params: {
|
|
31
31
|
name: {
|
|
32
|
-
type: 'string'
|
|
33
|
-
}
|
|
32
|
+
type: 'string',
|
|
33
|
+
},
|
|
34
34
|
},
|
|
35
35
|
returns: 'string',
|
|
36
36
|
async resolve({ name }) {
|
|
37
37
|
return `Hello ${name}`;
|
|
38
|
-
}
|
|
39
|
-
})
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
40
|
};
|
|
41
41
|
const app = (0, http_1.express)();
|
|
42
42
|
await (0, _1.startGraphQL)({
|
|
43
43
|
resolvers,
|
|
44
|
-
app
|
|
44
|
+
app,
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
it('should startGraphQL and make a request', async () => {
|
|
@@ -49,30 +49,30 @@ describe('Test GraphQL Server', () => {
|
|
|
49
49
|
helloWorld: (0, resolvers_1.resolver)({
|
|
50
50
|
params: {
|
|
51
51
|
name: {
|
|
52
|
-
type: 'string'
|
|
53
|
-
}
|
|
52
|
+
type: 'string',
|
|
53
|
+
},
|
|
54
54
|
},
|
|
55
55
|
returns: 'string',
|
|
56
56
|
async resolve({ name }) {
|
|
57
57
|
return `Hello ${name}`;
|
|
58
|
-
}
|
|
59
|
-
})
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
60
|
};
|
|
61
61
|
const app = (0, http_1.express)();
|
|
62
62
|
await (0, _1.startGraphQL)({
|
|
63
63
|
resolvers,
|
|
64
|
-
app
|
|
64
|
+
app,
|
|
65
65
|
});
|
|
66
66
|
const response = await (0, supertest_1.default)(app)
|
|
67
67
|
.post('/graphql')
|
|
68
68
|
.send({
|
|
69
69
|
operationName: 'testOperation',
|
|
70
70
|
variables: {
|
|
71
|
-
name: 'Nico'
|
|
71
|
+
name: 'Nico',
|
|
72
72
|
},
|
|
73
73
|
query: `query testOperation($name: String) {
|
|
74
74
|
helloWorld(name: $name)
|
|
75
|
-
}
|
|
75
|
+
}`,
|
|
76
76
|
});
|
|
77
77
|
expect(response.body.data).toEqual({ helloWorld: 'Hello Nico' });
|
|
78
78
|
});
|
|
@@ -81,30 +81,30 @@ describe('Test GraphQL Server', () => {
|
|
|
81
81
|
helloWorld: (0, resolvers_1.resolver)({
|
|
82
82
|
params: {
|
|
83
83
|
name: {
|
|
84
|
-
type: 'string'
|
|
85
|
-
}
|
|
84
|
+
type: 'string',
|
|
85
|
+
},
|
|
86
86
|
},
|
|
87
87
|
returns: 'string',
|
|
88
88
|
async resolve({ name }) {
|
|
89
89
|
return `Hello ${name}`;
|
|
90
|
-
}
|
|
91
|
-
})
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
92
|
};
|
|
93
93
|
const app = (0, http_1.express)();
|
|
94
94
|
await (0, _1.startGraphQL)({
|
|
95
95
|
resolvers,
|
|
96
|
-
app
|
|
96
|
+
app,
|
|
97
97
|
});
|
|
98
98
|
const response = await (0, supertest_1.default)(app)
|
|
99
99
|
.post('/graphql')
|
|
100
100
|
.send({
|
|
101
101
|
operationName: 'testOperation',
|
|
102
102
|
variables: {
|
|
103
|
-
name: 'Nico'
|
|
103
|
+
name: 'Nico',
|
|
104
104
|
},
|
|
105
105
|
query: `query testOperation($name: String) {
|
|
106
106
|
helloWorld_doesntExists(name: $name)
|
|
107
|
-
}
|
|
107
|
+
}`,
|
|
108
108
|
});
|
|
109
109
|
expect(response.statusCode).toBe(400);
|
|
110
110
|
expect(response.body.errors[0].message).toEqual('Cannot query field "helloWorld_doesntExists" on type "Query".');
|
|
@@ -117,30 +117,30 @@ describe('Test GraphQL Server', () => {
|
|
|
117
117
|
type: 'string',
|
|
118
118
|
validate: () => {
|
|
119
119
|
return 'notUnique';
|
|
120
|
-
}
|
|
121
|
-
}
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
122
|
},
|
|
123
123
|
returns: 'string',
|
|
124
124
|
async resolve({ name }) {
|
|
125
125
|
return `Hello ${name}`;
|
|
126
|
-
}
|
|
127
|
-
})
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
128
|
};
|
|
129
129
|
const app = (0, http_1.express)();
|
|
130
130
|
await (0, _1.startGraphQL)({
|
|
131
131
|
resolvers,
|
|
132
|
-
app
|
|
132
|
+
app,
|
|
133
133
|
});
|
|
134
134
|
const response = await (0, supertest_1.default)(app)
|
|
135
135
|
.post('/graphql')
|
|
136
136
|
.send({
|
|
137
137
|
operationName: 'testOperation',
|
|
138
138
|
variables: {
|
|
139
|
-
name: 'Nico'
|
|
139
|
+
name: 'Nico',
|
|
140
140
|
},
|
|
141
141
|
query: `query testOperation($name: String) {
|
|
142
142
|
helloWorld(name: $name)
|
|
143
|
-
}
|
|
143
|
+
}`,
|
|
144
144
|
});
|
|
145
145
|
expect(response.statusCode).toBe(200);
|
|
146
146
|
expect(response.body).toEqual({
|
|
@@ -150,8 +150,8 @@ describe('Test GraphQL Server', () => {
|
|
|
150
150
|
locations: [
|
|
151
151
|
{
|
|
152
152
|
line: 2,
|
|
153
|
-
column: 11
|
|
154
|
-
}
|
|
153
|
+
column: 11,
|
|
154
|
+
},
|
|
155
155
|
],
|
|
156
156
|
path: ['helloWorld'],
|
|
157
157
|
extensions: {
|
|
@@ -163,15 +163,15 @@ describe('Test GraphQL Server', () => {
|
|
|
163
163
|
error: 'validationError',
|
|
164
164
|
message: 'Validation Error',
|
|
165
165
|
validationErrors: {
|
|
166
|
-
name: 'notUnique'
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
166
|
+
name: 'notUnique',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
171
|
],
|
|
172
172
|
data: {
|
|
173
|
-
helloWorld: null
|
|
174
|
-
}
|
|
173
|
+
helloWorld: null,
|
|
174
|
+
},
|
|
175
175
|
});
|
|
176
176
|
});
|
|
177
177
|
it('should return user errors correctly', async () => {
|
|
@@ -179,31 +179,31 @@ describe('Test GraphQL Server', () => {
|
|
|
179
179
|
helloWorld: (0, resolvers_1.resolver)({
|
|
180
180
|
params: {
|
|
181
181
|
name: {
|
|
182
|
-
type: 'string'
|
|
183
|
-
}
|
|
182
|
+
type: 'string',
|
|
183
|
+
},
|
|
184
184
|
},
|
|
185
185
|
returns: 'string',
|
|
186
186
|
async resolve({ name }) {
|
|
187
187
|
throw new helpers_1.UserError('code', 'message');
|
|
188
188
|
return `Hello ${name}`;
|
|
189
|
-
}
|
|
190
|
-
})
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
191
|
};
|
|
192
192
|
const app = (0, http_1.express)();
|
|
193
193
|
await (0, _1.startGraphQL)({
|
|
194
194
|
resolvers,
|
|
195
|
-
app
|
|
195
|
+
app,
|
|
196
196
|
});
|
|
197
197
|
const response = await (0, supertest_1.default)(app)
|
|
198
198
|
.post('/graphql')
|
|
199
199
|
.send({
|
|
200
200
|
operationName: 'testOperation',
|
|
201
201
|
variables: {
|
|
202
|
-
name: 'Nico'
|
|
202
|
+
name: 'Nico',
|
|
203
203
|
},
|
|
204
204
|
query: `query testOperation($name: String) {
|
|
205
205
|
helloWorld(name: $name)
|
|
206
|
-
}
|
|
206
|
+
}`,
|
|
207
207
|
});
|
|
208
208
|
expect(response.statusCode).toBe(200);
|
|
209
209
|
expect(response.body).toEqual({
|
|
@@ -213,8 +213,8 @@ describe('Test GraphQL Server', () => {
|
|
|
213
213
|
locations: [
|
|
214
214
|
{
|
|
215
215
|
line: 2,
|
|
216
|
-
column: 11
|
|
217
|
-
}
|
|
216
|
+
column: 11,
|
|
217
|
+
},
|
|
218
218
|
],
|
|
219
219
|
path: ['helloWorld'],
|
|
220
220
|
extensions: {
|
|
@@ -224,14 +224,14 @@ describe('Test GraphQL Server', () => {
|
|
|
224
224
|
hash: '6f9b9af3cd',
|
|
225
225
|
info: {
|
|
226
226
|
error: 'code',
|
|
227
|
-
message: 'message'
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
227
|
+
message: 'message',
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
231
|
],
|
|
232
232
|
data: {
|
|
233
|
-
helloWorld: null
|
|
234
|
-
}
|
|
233
|
+
helloWorld: null,
|
|
234
|
+
},
|
|
235
235
|
});
|
|
236
236
|
});
|
|
237
237
|
it('should return server errors correctly', async () => {
|
|
@@ -239,31 +239,31 @@ describe('Test GraphQL Server', () => {
|
|
|
239
239
|
helloWorld: (0, resolvers_1.resolver)({
|
|
240
240
|
params: {
|
|
241
241
|
name: {
|
|
242
|
-
type: 'string'
|
|
243
|
-
}
|
|
242
|
+
type: 'string',
|
|
243
|
+
},
|
|
244
244
|
},
|
|
245
245
|
returns: 'string',
|
|
246
246
|
async resolve({ name }) {
|
|
247
247
|
throw new Error('message');
|
|
248
248
|
return `Hello ${name}`;
|
|
249
|
-
}
|
|
250
|
-
})
|
|
249
|
+
},
|
|
250
|
+
}),
|
|
251
251
|
};
|
|
252
252
|
const app = (0, http_1.express)();
|
|
253
253
|
await (0, _1.startGraphQL)({
|
|
254
254
|
resolvers,
|
|
255
|
-
app
|
|
255
|
+
app,
|
|
256
256
|
});
|
|
257
257
|
const response = await (0, supertest_1.default)(app)
|
|
258
258
|
.post('/graphql')
|
|
259
259
|
.send({
|
|
260
260
|
operationName: 'testOperation',
|
|
261
261
|
variables: {
|
|
262
|
-
name: 'Nico'
|
|
262
|
+
name: 'Nico',
|
|
263
263
|
},
|
|
264
264
|
query: `query testOperation($name: String) {
|
|
265
265
|
helloWorld(name: $name)
|
|
266
|
-
}
|
|
266
|
+
}`,
|
|
267
267
|
});
|
|
268
268
|
expect(response.statusCode).toBe(200);
|
|
269
269
|
const hash = '6f9b9af3cd';
|
|
@@ -274,21 +274,21 @@ describe('Test GraphQL Server', () => {
|
|
|
274
274
|
locations: [
|
|
275
275
|
{
|
|
276
276
|
line: 2,
|
|
277
|
-
column: 11
|
|
278
|
-
}
|
|
277
|
+
column: 11,
|
|
278
|
+
},
|
|
279
279
|
],
|
|
280
280
|
path: ['helloWorld'],
|
|
281
281
|
extensions: {
|
|
282
282
|
isOrionError: false,
|
|
283
283
|
isValidationError: false,
|
|
284
284
|
code: 'INTERNAL_SERVER_ERROR',
|
|
285
|
-
hash: hash
|
|
286
|
-
}
|
|
287
|
-
}
|
|
285
|
+
hash: hash,
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
288
|
],
|
|
289
289
|
data: {
|
|
290
|
-
helloWorld: null
|
|
291
|
-
}
|
|
290
|
+
helloWorld: null,
|
|
291
|
+
},
|
|
292
292
|
});
|
|
293
293
|
});
|
|
294
294
|
it('Should make requests to schemas with typed models', async () => {
|
|
@@ -319,51 +319,96 @@ describe('Test GraphQL Server', () => {
|
|
|
319
319
|
return null;
|
|
320
320
|
return {
|
|
321
321
|
name: 'Nico',
|
|
322
|
-
age: 20
|
|
322
|
+
age: 20,
|
|
323
323
|
};
|
|
324
324
|
};
|
|
325
325
|
const user = (0, resolvers_1.resolver)({
|
|
326
326
|
params: Params,
|
|
327
327
|
returns: User,
|
|
328
|
-
resolve
|
|
328
|
+
resolve,
|
|
329
329
|
});
|
|
330
330
|
const model = (0, models_1.createModel)({
|
|
331
331
|
name: 'Model',
|
|
332
332
|
schema: {
|
|
333
|
-
user: { type: User }
|
|
334
|
-
}
|
|
333
|
+
user: { type: User },
|
|
334
|
+
},
|
|
335
335
|
});
|
|
336
336
|
const modelMutation = (0, resolvers_1.resolver)({
|
|
337
337
|
params: Params,
|
|
338
338
|
returns: [model],
|
|
339
339
|
mutation: true,
|
|
340
|
-
resolve
|
|
340
|
+
resolve,
|
|
341
341
|
});
|
|
342
342
|
const resolvers = { user, modelMutation };
|
|
343
343
|
const app = (0, http_1.express)();
|
|
344
344
|
await (0, _1.startGraphQL)({
|
|
345
345
|
resolvers,
|
|
346
|
-
app
|
|
346
|
+
app,
|
|
347
347
|
});
|
|
348
348
|
const response = await (0, supertest_1.default)(app)
|
|
349
349
|
.post('/graphql')
|
|
350
350
|
.send({
|
|
351
351
|
variables: {
|
|
352
|
-
userId: '1'
|
|
352
|
+
userId: '1',
|
|
353
353
|
},
|
|
354
354
|
query: `query ($userId: String) {
|
|
355
355
|
user(userId: $userId) {
|
|
356
356
|
name
|
|
357
357
|
age
|
|
358
358
|
}
|
|
359
|
-
}
|
|
359
|
+
}`,
|
|
360
360
|
});
|
|
361
361
|
expect(response.statusCode).toBe(200);
|
|
362
362
|
expect(response.body.data).toEqual({
|
|
363
363
|
user: {
|
|
364
364
|
name: 'Nico',
|
|
365
|
-
age: 20
|
|
366
|
-
}
|
|
365
|
+
age: 20,
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
it('Should pass graphql request info in fourth param', async () => {
|
|
370
|
+
let User = class User {
|
|
371
|
+
};
|
|
372
|
+
__decorate([
|
|
373
|
+
(0, typed_model_1.Prop)(),
|
|
374
|
+
__metadata("design:type", String)
|
|
375
|
+
], User.prototype, "name", void 0);
|
|
376
|
+
__decorate([
|
|
377
|
+
(0, typed_model_1.Prop)(),
|
|
378
|
+
__metadata("design:type", Number)
|
|
379
|
+
], User.prototype, "age", void 0);
|
|
380
|
+
User = __decorate([
|
|
381
|
+
(0, typed_model_1.TypedSchema)()
|
|
382
|
+
], User);
|
|
383
|
+
let resolveInfo;
|
|
384
|
+
const user = (0, resolvers_1.resolver)({
|
|
385
|
+
params: {},
|
|
386
|
+
returns: User,
|
|
387
|
+
async resolve(_params, _viewer, info) {
|
|
388
|
+
resolveInfo = info;
|
|
389
|
+
return {
|
|
390
|
+
name: 'Nico',
|
|
391
|
+
age: 20,
|
|
392
|
+
};
|
|
393
|
+
},
|
|
367
394
|
});
|
|
395
|
+
const resolvers = { user };
|
|
396
|
+
const app = (0, http_1.express)();
|
|
397
|
+
await (0, _1.startGraphQL)({
|
|
398
|
+
resolvers,
|
|
399
|
+
app,
|
|
400
|
+
});
|
|
401
|
+
const response = await (0, supertest_1.default)(app)
|
|
402
|
+
.post('/graphql')
|
|
403
|
+
.send({
|
|
404
|
+
query: `query {
|
|
405
|
+
user {
|
|
406
|
+
name
|
|
407
|
+
age
|
|
408
|
+
}
|
|
409
|
+
}`,
|
|
410
|
+
});
|
|
411
|
+
expect(response.statusCode).toBe(200);
|
|
412
|
+
expect(resolveInfo.fieldName).toEqual('user');
|
|
368
413
|
});
|
|
369
414
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/graphql",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "nicolaslopezj",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@apollo/server": "^4.3.0",
|
|
17
17
|
"@graphql-tools/schema": "^9.0.12",
|
|
18
|
-
"@orion-js/env": "^3.
|
|
19
|
-
"@orion-js/helpers": "^3.
|
|
20
|
-
"@orion-js/http": "^3.
|
|
21
|
-
"@orion-js/models": "^3.
|
|
22
|
-
"@orion-js/resolvers": "^3.
|
|
23
|
-
"@orion-js/schema": "^3.
|
|
24
|
-
"@orion-js/services": "^3.
|
|
25
|
-
"@orion-js/typed-model": "^3.
|
|
18
|
+
"@orion-js/env": "^3.10.0",
|
|
19
|
+
"@orion-js/helpers": "^3.10.0",
|
|
20
|
+
"@orion-js/http": "^3.10.0",
|
|
21
|
+
"@orion-js/models": "^3.10.0",
|
|
22
|
+
"@orion-js/resolvers": "^3.10.0",
|
|
23
|
+
"@orion-js/schema": "^3.10.0",
|
|
24
|
+
"@orion-js/services": "^3.10.0",
|
|
25
|
+
"@orion-js/typed-model": "^3.10.0",
|
|
26
26
|
"graphql-iso-date": "^3.6.1",
|
|
27
27
|
"graphql-subscriptions": "2.0.0",
|
|
28
28
|
"graphql-ws": "^5.11.2",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "68036a0293066cc23feb3000ab44e58600540615"
|
|
55
55
|
}
|