Skip to content
Snippets Groups Projects
Commit d3b37dbc authored by stevereis's avatar stevereis
Browse files

WIP : add union type for testing purpose

parent e981261a
No related branches found
No related tags found
No related merge requests found
......@@ -122,6 +122,6 @@ export const dataToTransient = (data: TransientDataResult): Experiment => {
return {
title: data.name,
result: tables,
results: tables,
};
};
import { Field, GraphQLISODateTime, ObjectType } from '@nestjs/graphql';
import { Result } from '../result/result.model';
import {
createUnionType,
Field,
GraphQLISODateTime,
ObjectType,
} from '@nestjs/graphql';
import { DummyResult } from '../result/dummy-result.model';
import { TableResult } from '../result/table-result.model';
export const ResultUnion = createUnionType({
name: 'ResultUnion',
types: () => [TableResult, DummyResult],
resolveType(value) {
if (value.metadatas) {
return TableResult;
}
if (value.listMax) {
return DummyResult;
}
return null;
},
});
@ObjectType()
export class Experiment {
......@@ -18,6 +39,6 @@ export class Experiment {
@Field(() => GraphQLISODateTime, { nullable: true })
finished_at?: Date;
@Field(() => [Result])
result: Result[];
@Field(() => [ResultUnion])
results: Array<typeof ResultUnion>;
}
import { Field, ObjectType } from '@nestjs/graphql';
import { Result } from './common/result.model';
@ObjectType()
export class DummyResult extends Result {
@Field()
name: string;
@Field(() => [[String]])
data: string[][];
@Field(() => [String])
listMax: string[];
}
import { Field, ObjectType } from '@nestjs/graphql';
import { MetaData } from './common/metadata.model';
import { Result } from './result.model';
import { Result } from './common/result.model';
@ObjectType()
export class TableResult extends Result {
......
......@@ -34,8 +34,9 @@ type Domain {
rootGroup: Group!
}
type Result {
groupBy: String
type MetaData {
name: String!
type: String!
}
type Experiment {
......@@ -44,7 +45,7 @@ type Experiment {
created_at: DateTime
update_at: DateTime
finished_at: DateTime
result: [Result!]!
results: [ResultUnion!]!
}
"""
......@@ -52,9 +53,20 @@ A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date
"""
scalar DateTime
type MetaData {
union ResultUnion = TableResult | DummyResult
type TableResult {
groupBy: String
name: String!
type: String!
data: [[String!]!]!
metadatas: [MetaData!]!
}
type DummyResult {
groupBy: String
name: String!
data: [[String!]!]!
listMax: [String!]!
}
type Query {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment