add fields to Thing
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
"@nestjs/platform-express": "^9.0.0",
|
||||
"apollo-server-express": "^3.10.1",
|
||||
"axios-cache-adapter": "^2.7.3",
|
||||
"camelcase-object-deep": "^1.1.7",
|
||||
"graphql": "^16.5.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1957,6 +1957,11 @@ callsites@^3.0.0:
|
||||
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
|
||||
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
|
||||
|
||||
camelcase-object-deep@^1.1.7:
|
||||
version "1.1.7"
|
||||
resolved "https://registry.yarnpkg.com/camelcase-object-deep/-/camelcase-object-deep-1.1.7.tgz#e6de1c4eaa1cd1d4d2ad3e77fc85e2ad1801f822"
|
||||
integrity sha512-hKykTR59km6Xo3QOns12em/qScl8N4Q1yAyiJFZ/lfPFHHiOweV5omRL1FWJnNSJL8rXnGZmKC/JSQl/Lyp1pQ==
|
||||
|
||||
camelcase@^5.3.1:
|
||||
version "5.3.1"
|
||||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
|
||||
|
||||
Reference in New Issue
Block a user