add fields to Thing
This commit is contained in:
@@ -4,8 +4,19 @@
|
||||
|
||||
type Thing {
|
||||
id: Int!
|
||||
url: String!
|
||||
name: String!
|
||||
thumbnail: String!
|
||||
previewImage: String!
|
||||
likeCount: Int!
|
||||
makeCount: Int!
|
||||
commentCount: Int!
|
||||
|
||||
"""URL to thingiverse.com page"""
|
||||
publicUrl: String!
|
||||
|
||||
"""ISO 8601 date string"""
|
||||
createdAt: String!
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
||||
@@ -1,13 +1,34 @@
|
||||
import { Field, Int, ObjectType, } from '@nestjs/graphql';
|
||||
import { Field, Int, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class Thing {
|
||||
@Field(() => Int)
|
||||
id: number;
|
||||
|
||||
@Field(() => String)
|
||||
url: string;
|
||||
|
||||
@Field(() => String)
|
||||
name: string;
|
||||
|
||||
@Field(() => String)
|
||||
thumbnail: string;
|
||||
|
||||
@Field(() => String)
|
||||
previewImage: string;
|
||||
|
||||
@Field(() => Int)
|
||||
likeCount: number;
|
||||
|
||||
@Field(() => Int)
|
||||
makeCount: number;
|
||||
|
||||
@Field(() => Int)
|
||||
commentCount: number;
|
||||
|
||||
@Field(() => String, { description: 'URL to thingiverse.com page' })
|
||||
publicUrl: string;
|
||||
|
||||
@Field(() => String, { description: 'ISO 8601 date string' })
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Args, Query, Resolver } from '@nestjs/graphql';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import * as camelcase from 'camelcase-object-deep';
|
||||
import { firstValueFrom, lastValueFrom, map } from 'rxjs';
|
||||
import { ThingsArgs } from './dto/things.args';
|
||||
import { Thing } from './thing.model';
|
||||
|
||||
@@ -20,14 +21,22 @@ export class ThingResolver {
|
||||
|
||||
const queryStirng = `/search?${params.toString()}`;
|
||||
|
||||
const { data } = await firstValueFrom(
|
||||
this.httpService.get<{
|
||||
this.httpService.axiosRef.interceptors.response.use((response) => {
|
||||
response.data = camelcase(response);
|
||||
return response;
|
||||
});
|
||||
|
||||
type Response = {
|
||||
data: {
|
||||
hits: Thing[];
|
||||
total: number;
|
||||
}>(queryStirng),
|
||||
}
|
||||
}
|
||||
const { data: response } = await firstValueFrom(
|
||||
this.httpService.get<Response>(queryStirng),
|
||||
);
|
||||
|
||||
return data.hits;
|
||||
return response.data.hits
|
||||
}
|
||||
|
||||
@Query(() => Thing)
|
||||
|
||||
Reference in New Issue
Block a user