Skip to content

Instantly share code, notes, and snippets.

@annitya
Created May 28, 2021 08:41
Show Gist options
  • Save annitya/b4dd1237520d6fb50c2b5f58b94bfd0d to your computer and use it in GitHub Desktop.
Save annitya/b4dd1237520d6fb50c2b5f58b94bfd0d to your computer and use it in GitHub Desktop.
@ObjectType()
export default class GraphTimeseries {
@Field()
assetId: number;
@Field()
asset: GraphAsset;
@Field(() => [Number])
eventsOwnerIds: number[] = [];
}
@Resolver(() => GraphTimeseries)
export default class GraphTimeseriesResolver implements ResolverInterface<GraphTimeseries> {
@Query(() => [GraphTimeseries])
async getTimeseriesByIds(@Arg('ids', () => [Float]) ids: number[], @Ctx() source: Source) {
return source.getTimeseriesByIds(ids);
}
@FieldResolver()
async asset(@Root() timeseries: GraphTimeseries, @Ctx() source: Source) {
return await source.getAssetById(timeseries.assetId);
}
@FieldResolver()
@DependsOn('asset')
async eventsOwnerIds(@Root() timeseries: GraphTimeseries, @Ctx() source: Source, @Info() info) {
const { asset } = timeseries; // No longer undefined.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment