graphql setup

This commit is contained in:
João Geonizeli
2022-08-15 07:08:51 -03:00
parent 0e27984e8e
commit 458d9a1376
10 changed files with 585 additions and 64 deletions

7
src/thing/thing.model.ts Normal file
View File

@@ -0,0 +1,7 @@
import { Field, Int, ObjectType } from '@nestjs/graphql';
@ObjectType()
export class Thing {
@Field(type => Int)
id: number;
}

View File

@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ThingResolver } from './thing.resolver';
describe('ThingResolver', () => {
let resolver: ThingResolver;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ThingResolver],
}).compile();
resolver = module.get<ThingResolver>(ThingResolver);
});
it('should be defined', () => {
expect(resolver).toBeDefined();
});
});

View File

@@ -0,0 +1,19 @@
import { Query, Resolver } from '@nestjs/graphql';
import { Thing } from './thing.model';
@Resolver(() => Thing)
export class ThingResolver {
constructor() {}
@Query(() => [Thing])
async things(): Promise<Thing[]> {
return [
{
id: 1,
},
{
id: 2,
},
];
}
}