@aleleba/create-node-ts-graphql-server 1.4.0 → 1.4.1
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/package.json
CHANGED
package/schema.gql
CHANGED
|
@@ -12,17 +12,9 @@ type Query {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
type Test {
|
|
15
|
-
text: Text!
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type TestMutation {
|
|
19
|
-
textMutation(text: String!): TextMutation!
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type Text {
|
|
23
15
|
text: String!
|
|
24
16
|
}
|
|
25
17
|
|
|
26
|
-
type
|
|
27
|
-
text: String!
|
|
18
|
+
type TestMutation {
|
|
19
|
+
text(text: String!): String!
|
|
28
20
|
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
/* eslint-disable no-mixed-spaces-and-tabs */
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
|
-
import { Query, Resolver, Mutation
|
|
4
|
+
import { Query, Resolver, Mutation } from 'type-graphql';
|
|
4
5
|
import { Test, TestMutation } from '@GraphQL/schema/test.schema';
|
|
5
6
|
|
|
6
7
|
@Resolver(() => Test)
|
|
7
8
|
export class TestResolver {
|
|
8
9
|
@Query(() => Test)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
async test() {
|
|
11
|
+
return Test;
|
|
12
|
+
}
|
|
12
13
|
|
|
13
14
|
@Mutation(() => TestMutation)
|
|
14
15
|
async testMutation() {
|
|
15
|
-
|
|
16
|
+
return TestMutation;
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -1,36 +1,21 @@
|
|
|
1
|
+
/* eslint-disable no-mixed-spaces-and-tabs */
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
|
-
import { Field, ObjectType, Arg } from
|
|
4
|
+
import { Field, ObjectType, Arg } from 'type-graphql';
|
|
4
5
|
import { getTest, addText } from '@controllerGraphQL';
|
|
5
6
|
|
|
6
7
|
@ObjectType()
|
|
7
8
|
export class Test {
|
|
8
|
-
@Field(() =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@ObjectType()
|
|
17
|
-
export class Text {
|
|
18
|
-
@Field()
|
|
19
|
-
text?: string
|
|
9
|
+
@Field(() => String)
|
|
10
|
+
async text(){
|
|
11
|
+
return await getTest({});
|
|
12
|
+
}
|
|
20
13
|
}
|
|
21
14
|
|
|
22
15
|
@ObjectType()
|
|
23
16
|
export class TestMutation {
|
|
24
|
-
@Field(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@ObjectType()
|
|
33
|
-
export class TextMutation {
|
|
34
|
-
@Field()
|
|
35
|
-
text?: string
|
|
17
|
+
@Field(() => String)
|
|
18
|
+
async text(@Arg('text') text?: string){
|
|
19
|
+
return await addText({text});
|
|
20
|
+
}
|
|
36
21
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import { getTestModel, addTextModel } from '@models';
|
|
4
|
-
import { TextMutation } from '@src/GraphQL/schema/test.schema';
|
|
5
4
|
|
|
6
5
|
// eslint-disable-next-line
|
|
7
6
|
export const getTest = async ({}) => {
|
|
@@ -9,6 +8,6 @@ export const getTest = async ({}) => {
|
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
// eslint-disable-next-line
|
|
12
|
-
export const addText = async ({ text }:
|
|
11
|
+
export const addText = async ({ text }: {text?: string}) => {
|
|
13
12
|
return addTextModel({ text });
|
|
14
13
|
};
|
package/src/models/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import { TextMutation } from "@GraphQL/schema/test.schema";
|
|
4
|
-
|
|
5
3
|
export const getTestModel = async () => {
|
|
6
4
|
return 'This is the text response for Test Query from a model';
|
|
7
5
|
};
|
|
8
6
|
|
|
9
|
-
export const addTextModel = async ({ text }:
|
|
7
|
+
export const addTextModel = async ({ text }: {text?: string}) => {
|
|
10
8
|
return `Simulate to insert some text: ${text} from a model`;
|
|
11
9
|
};
|
|
@@ -1,47 +1,41 @@
|
|
|
1
1
|
import server from '@src';
|
|
2
2
|
import supertest from 'supertest';
|
|
3
3
|
describe('global server tests', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let request: supertest.SuperTest<supertest.Test>;
|
|
5
|
+
beforeEach( async () => {
|
|
6
|
+
request = await supertest(server);
|
|
7
|
+
});
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
expect(response.body).toEqual(bodyResponse);
|
|
23
|
-
});
|
|
9
|
+
it('should return Test data from test Query', async () => {
|
|
10
|
+
const bodyResponse = {
|
|
11
|
+
data: {
|
|
12
|
+
test: {
|
|
13
|
+
text: 'This is the text response for Test Query from a model'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const response = await request.get('/graphql?query=%7B%0A%20%20test%7B%0A%20%20%20%20text%0A%20%20%7D%0A%7D')
|
|
18
|
+
.set('Accept', 'application/json');
|
|
19
|
+
expect(response.status).toEqual(200);
|
|
20
|
+
expect(response.body).toEqual(bodyResponse);
|
|
21
|
+
});
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
textMutation(text: "testing text"){
|
|
39
|
-
text
|
|
40
|
-
}
|
|
41
|
-
}
|
|
23
|
+
it('should return Test data from test Mutation', async () => {
|
|
24
|
+
const bodyResponse = {
|
|
25
|
+
data: {
|
|
26
|
+
testMutation: {
|
|
27
|
+
text: 'Simulate to insert some text: testing text from a model'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const response = await request.post('/graphql')
|
|
32
|
+
.send({'query': `mutation{
|
|
33
|
+
testMutation{
|
|
34
|
+
text(text: "testing text")
|
|
35
|
+
}
|
|
42
36
|
}`})
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
.set('Accept', 'application/json');
|
|
38
|
+
expect(response.status).toEqual(200);
|
|
39
|
+
expect(response.body).toEqual(bodyResponse);
|
|
40
|
+
});
|
|
47
41
|
});
|