Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions backend/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { gql } from 'apollo-server-express';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { merge } from 'lodash';

import sampleResolvers from './resolvers/sampleResolvers';
import sampleType from './types/sampleType';

const query = gql`
type Query {
_empty: String
}
`;

const mutation = gql`
type Mutation {
_empty: String
}
`;

const executableSchema = makeExecutableSchema({
typeDefs: [query, mutation, sampleType],
resolvers: merge(sampleResolvers),
});

export default executableSchema;
34 changes: 34 additions & 0 deletions backend/graphql/resolvers/sampleResolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SampleService from '../../services/implementations/sampleService';
import ISampleService from '../../services/interfaces/sampleService';

const sampleService: ISampleService = new SampleService();

const sampleResolvers = {
Query: {
sampleById: async (_: unknown, { id }: { id: string }) => {
return sampleService.getSampleById(id);
},
samples: async () => {
return sampleService.getAllSamples();
},
},
Mutation: {
createSample: async (
_: unknown,
{ sample }: { sample: { name: string; description: string } }
) => {
return sampleService.createSample(sample);
},
updateSample: async (
_: unknown,
{ id, sample }: { id: string; sample: { name: string; description: string } }
) => {
return sampleService.updateSample(id, sample);
},
deleteSampleById: async (_: unknown, { id }: { id: string }) => {
return sampleService.deleteSampleById(id);
},
},
};

export default sampleResolvers;
29 changes: 29 additions & 0 deletions backend/graphql/types/sampleType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { gql } from 'apollo-server-express';

const sampleType = gql`
type SampleDTO {
id: String!
name: String!
description: String!
createdAt: String!
updatedAt: String!
}

input CreateSampleDTO {
name: String!
description: String!
}

extend type Query {
sampleById(id: String!): SampleDTO!
samples: [SampleDTO!]!
}

extend type Mutation {
createSample(sample: CreateSampleDTO!): SampleDTO!
updateSample(id: String!, sample: CreateSampleDTO!): SampleDTO!
deleteSampleById(id: String!): SampleDTO!
}
`;

export default sampleType;
19 changes: 19 additions & 0 deletions backend/models/sample.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Column, DataType, Model, Table } from 'sequelize-typescript';

@Table({ tableName: 'samples' })
export default class Sample extends Model {
@Column({ type: DataType.STRING, primaryKey: true })
id!: string;

@Column({ type: DataType.STRING })
name!: string;

@Column({ type: DataType.STRING })
description!: string;

@Column({ type: DataType.DATE })
createdAt!: Date;

@Column({ type: DataType.DATE })
updatedAt!: Date;
}
Loading