mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2025-01-08 04:56:46 -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",
|
||||
"version": "1.4.0",
|
||||
"version": "1.4.1",
|
||||
"description": "Node with Typescript and GraphQL Server",
|
||||
"bin": "./bin/cli.js",
|
||||
"main": "index.js",
|
||||
|
12
schema.gql
12
schema.gql
@ -12,17 +12,9 @@ type Query {
|
||||
}
|
||||
|
||||
type Test {
|
||||
text: Text!
|
||||
text: String!
|
||||
}
|
||||
|
||||
type TestMutation {
|
||||
textMutation(text: String!): TextMutation!
|
||||
}
|
||||
|
||||
type Text {
|
||||
text: String!
|
||||
}
|
||||
|
||||
type TextMutation {
|
||||
text: String!
|
||||
text(text: String!): String!
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
/* eslint-disable no-mixed-spaces-and-tabs */
|
||||
'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';
|
||||
|
||||
@Resolver(() => Test)
|
||||
export class TestResolver {
|
||||
@Query(() => Test)
|
||||
async test() {
|
||||
return {};
|
||||
}
|
||||
async test() {
|
||||
return Test;
|
||||
}
|
||||
|
||||
@Mutation(() => TestMutation)
|
||||
async testMutation() {
|
||||
return {};
|
||||
return TestMutation;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,36 +1,21 @@
|
||||
/* eslint-disable no-mixed-spaces-and-tabs */
|
||||
'use strict';
|
||||
|
||||
import { Field, ObjectType, Arg } from "type-graphql";
|
||||
import { Field, ObjectType, Arg } from 'type-graphql';
|
||||
import { getTest, addText } from '@controllerGraphQL';
|
||||
|
||||
@ObjectType()
|
||||
export class Test {
|
||||
@Field(() => Text)
|
||||
async text(){
|
||||
return {
|
||||
text: await getTest({})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class Text {
|
||||
@Field()
|
||||
text?: string
|
||||
@Field(() => String)
|
||||
async text(){
|
||||
return await getTest({});
|
||||
}
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class TestMutation {
|
||||
@Field(type => TextMutation)
|
||||
async textMutation(@Arg('text') text?: string){
|
||||
return {
|
||||
text: await addText({text})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class TextMutation {
|
||||
@Field()
|
||||
text?: string
|
||||
@Field(() => String)
|
||||
async text(@Arg('text') text?: string){
|
||||
return await addText({text});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
import { getTestModel, addTextModel } from '@models';
|
||||
import { TextMutation } from '@src/GraphQL/schema/test.schema';
|
||||
|
||||
// eslint-disable-next-line
|
||||
export const getTest = async ({}) => {
|
||||
@ -9,6 +8,6 @@ export const getTest = async ({}) => {
|
||||
};
|
||||
|
||||
// eslint-disable-next-line
|
||||
export const addText = async ({ text }: TextMutation) => {
|
||||
export const addText = async ({ text }: {text?: string}) => {
|
||||
return addTextModel({ text });
|
||||
};
|
@ -1,11 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
import { TextMutation } from "@GraphQL/schema/test.schema";
|
||||
|
||||
export const getTestModel = async () => {
|
||||
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`;
|
||||
};
|
@ -1,47 +1,41 @@
|
||||
import server from '@src';
|
||||
import supertest from 'supertest';
|
||||
describe('global server tests', () => {
|
||||
let request: supertest.SuperTest<supertest.Test>;
|
||||
beforeEach( async () => {
|
||||
request = await supertest(server);
|
||||
});
|
||||
let request: supertest.SuperTest<supertest.Test>;
|
||||
beforeEach( async () => {
|
||||
request = await supertest(server);
|
||||
});
|
||||
|
||||
it('should return Test data from test Query', async () => {
|
||||
const bodyResponse = {
|
||||
data: {
|
||||
test: {
|
||||
text: {
|
||||
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%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')
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(bodyResponse);
|
||||
});
|
||||
it('should return Test data from test Query', async () => {
|
||||
const bodyResponse = {
|
||||
data: {
|
||||
test: {
|
||||
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')
|
||||
.set('Accept', 'application/json');
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(bodyResponse);
|
||||
});
|
||||
|
||||
it('should return Test data from test Mutation', async () => {
|
||||
const bodyResponse = {
|
||||
data: {
|
||||
testMutation: {
|
||||
textMutation: {
|
||||
text: "Simulate to insert some text: testing text from a model"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const response = await request.post('/graphql')
|
||||
.send({'query': `mutation{
|
||||
testMutation{
|
||||
textMutation(text: "testing text"){
|
||||
text
|
||||
}
|
||||
}
|
||||
it('should return Test data from test Mutation', async () => {
|
||||
const bodyResponse = {
|
||||
data: {
|
||||
testMutation: {
|
||||
text: 'Simulate to insert some text: testing text from a model'
|
||||
}
|
||||
}
|
||||
};
|
||||
const response = await request.post('/graphql')
|
||||
.send({'query': `mutation{
|
||||
testMutation{
|
||||
text(text: "testing text")
|
||||
}
|
||||
}`})
|
||||
.set('Accept', 'application/json')
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(bodyResponse);
|
||||
});
|
||||
.set('Accept', 'application/json');
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(bodyResponse);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user