mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2025-01-09 05:26:50 -06:00
PR-442185: fixing the type graphql schema.
This commit is contained in:
parent
28c1d501a0
commit
00a60519a2
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@aleleba/create-node-ts-graphql-server",
|
"name": "@aleleba/create-node-ts-graphql-server",
|
||||||
"version": "1.4.0",
|
"version": "1.4.1",
|
||||||
"description": "Node with Typescript and GraphQL Server",
|
"description": "Node with Typescript and GraphQL Server",
|
||||||
"bin": "./bin/cli.js",
|
"bin": "./bin/cli.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
12
schema.gql
12
schema.gql
@ -12,17 +12,9 @@ type Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Test {
|
type Test {
|
||||||
text: Text!
|
text: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestMutation {
|
type TestMutation {
|
||||||
textMutation(text: String!): TextMutation!
|
text(text: String!): String!
|
||||||
}
|
|
||||||
|
|
||||||
type Text {
|
|
||||||
text: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
type TextMutation {
|
|
||||||
text: String!
|
|
||||||
}
|
}
|
@ -1,18 +1,19 @@
|
|||||||
|
/* eslint-disable no-mixed-spaces-and-tabs */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { Query, Resolver, Mutation, Arg } from 'type-graphql';
|
import { Query, Resolver, Mutation } from 'type-graphql';
|
||||||
import { Test, TestMutation } from '@GraphQL/schema/test.schema';
|
import { Test, TestMutation } from '@GraphQL/schema/test.schema';
|
||||||
|
|
||||||
@Resolver(() => Test)
|
@Resolver(() => Test)
|
||||||
export class TestResolver {
|
export class TestResolver {
|
||||||
@Query(() => Test)
|
@Query(() => Test)
|
||||||
async test() {
|
async test() {
|
||||||
return {};
|
return Test;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => TestMutation)
|
@Mutation(() => TestMutation)
|
||||||
async testMutation() {
|
async testMutation() {
|
||||||
return {};
|
return TestMutation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,36 +1,21 @@
|
|||||||
|
/* eslint-disable no-mixed-spaces-and-tabs */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { Field, ObjectType, Arg } from "type-graphql";
|
import { Field, ObjectType, Arg } from 'type-graphql';
|
||||||
import { getTest, addText } from '@controllerGraphQL';
|
import { getTest, addText } from '@controllerGraphQL';
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class Test {
|
export class Test {
|
||||||
@Field(() => Text)
|
@Field(() => String)
|
||||||
async text(){
|
async text(){
|
||||||
return {
|
return await getTest({});
|
||||||
text: await getTest({})
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ObjectType()
|
|
||||||
export class Text {
|
|
||||||
@Field()
|
|
||||||
text?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class TestMutation {
|
export class TestMutation {
|
||||||
@Field(type => TextMutation)
|
@Field(() => String)
|
||||||
async textMutation(@Arg('text') text?: string){
|
async text(@Arg('text') text?: string){
|
||||||
return {
|
return await addText({text});
|
||||||
text: await addText({text})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObjectType()
|
|
||||||
export class TextMutation {
|
|
||||||
@Field()
|
|
||||||
text?: string
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { getTestModel, addTextModel } from '@models';
|
import { getTestModel, addTextModel } from '@models';
|
||||||
import { TextMutation } from '@src/GraphQL/schema/test.schema';
|
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
export const getTest = async ({}) => {
|
export const getTest = async ({}) => {
|
||||||
@ -9,6 +8,6 @@ export const getTest = async ({}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
export const addText = async ({ text }: TextMutation) => {
|
export const addText = async ({ text }: {text?: string}) => {
|
||||||
return addTextModel({ text });
|
return addTextModel({ text });
|
||||||
};
|
};
|
@ -1,11 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { TextMutation } from "@GraphQL/schema/test.schema";
|
|
||||||
|
|
||||||
export const getTestModel = async () => {
|
export const getTestModel = async () => {
|
||||||
return 'This is the text response for Test Query from a model';
|
return 'This is the text response for Test Query from a model';
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addTextModel = async ({ text }: TextMutation) => {
|
export const addTextModel = async ({ text }: {text?: string}) => {
|
||||||
return `Simulate to insert some text: ${text} from a model`;
|
return `Simulate to insert some text: ${text} from a model`;
|
||||||
};
|
};
|
@ -10,14 +10,12 @@ describe('global server tests', () => {
|
|||||||
const bodyResponse = {
|
const bodyResponse = {
|
||||||
data: {
|
data: {
|
||||||
test: {
|
test: {
|
||||||
text: {
|
text: 'This is the text response for Test Query from a model'
|
||||||
text: "This is the text response for Test Query from a model"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
const response = await request.get('/graphql?query=%7B%0A%20%20test%7B%0A%20%20%20%20text%0A%20%20%7D%0A%7D')
|
||||||
const response = await request.get('/graphql?query=%7B%0A%20%20test%7B%0A%20%20%20%20text%7B%0A%20%20%20%20%20%20text%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A%0A')
|
.set('Accept', 'application/json');
|
||||||
.set('Accept', 'application/json')
|
|
||||||
expect(response.status).toEqual(200);
|
expect(response.status).toEqual(200);
|
||||||
expect(response.body).toEqual(bodyResponse);
|
expect(response.body).toEqual(bodyResponse);
|
||||||
});
|
});
|
||||||
@ -26,21 +24,17 @@ describe('global server tests', () => {
|
|||||||
const bodyResponse = {
|
const bodyResponse = {
|
||||||
data: {
|
data: {
|
||||||
testMutation: {
|
testMutation: {
|
||||||
textMutation: {
|
text: 'Simulate to insert some text: testing text from a model'
|
||||||
text: "Simulate to insert some text: testing text from a model"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
const response = await request.post('/graphql')
|
const response = await request.post('/graphql')
|
||||||
.send({'query': `mutation{
|
.send({'query': `mutation{
|
||||||
testMutation{
|
testMutation{
|
||||||
textMutation(text: "testing text"){
|
text(text: "testing text")
|
||||||
text
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}`})
|
}`})
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json');
|
||||||
expect(response.status).toEqual(200);
|
expect(response.status).toEqual(200);
|
||||||
expect(response.body).toEqual(bodyResponse);
|
expect(response.body).toEqual(bodyResponse);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user