File tree 4 files changed +100
-4
lines changed
4 files changed +100
-4
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,8 @@ import { jobApplicationTypeDefs } from "./schema/jobApplicationSchema";
88
88
import { jobApplicationResolver } from "./resolvers/jobApplicationResolver" ;
89
89
import { blogRelatedResolvers } from "./resolvers/blogRelatedArticlesResolver" ;
90
90
import { blogRelatedArticlesSchema } from "./schema/blogRelatedArticlesSchema" ;
91
-
91
+ import { DocSchema } from "./schema/doc" ;
92
+ import { docResolver } from "./resolvers/Doc" ;
92
93
const PORT = process . env . PORT || 3000 ;
93
94
94
95
const resolvers = mergeResolvers ( [
@@ -135,7 +136,8 @@ const resolvers = mergeResolvers([
135
136
commentResolvers ,
136
137
commentLikeResolvers ,
137
138
commentReplyResolvers ,
138
- blogRelatedResolvers
139
+ blogRelatedResolvers ,
140
+ docResolver
139
141
] ) ;
140
142
const typeDefs = mergeTypeDefs ( [
141
143
applicationCycleTypeDefs ,
@@ -177,7 +179,8 @@ const typeDefs = mergeTypeDefs([
177
179
commentReplySchema ,
178
180
commentLikeSchema ,
179
181
jobApplicationTypeDefs ,
180
- blogRelatedArticlesSchema
182
+ blogRelatedArticlesSchema ,
183
+ DocSchema
181
184
] ) ;
182
185
183
186
const server = new ApolloServer ( {
@@ -209,4 +212,4 @@ const server = new ApolloServer({
209
212
connect ( ) . then ( ( ) => {
210
213
console . log ( "Database connected!" ) ;
211
214
server . listen ( PORT ) . then ( ( { url } ) => console . info ( `App on ${ url } ` ) ) ;
212
- } ) ;
215
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import mongoose , { Schema } from "mongoose" ;
2
+
3
+ export const docModels = mongoose . model ( 'docModel' ,
4
+ new mongoose . Schema ( {
5
+ title :{
6
+ type :String ,
7
+ } ,
8
+ description :{
9
+ type :String ,
10
+ } ,
11
+ role :{
12
+ type :String
13
+ }
14
+ } )
15
+ )
Original file line number Diff line number Diff line change
1
+ import { docModels } from "../models/doc" ;
2
+
3
+ export const docResolver :any = {
4
+ Query :{
5
+ async getDoc ( _ :any , args :any ) {
6
+ const doc = await docModels . findOne ( { _id :args . id } ) ;
7
+ return doc ;
8
+ } ,
9
+ async getAllDocs ( ) {
10
+ const docs = await docModels . find ( ) ;
11
+ return docs ;
12
+ } ,
13
+ async getDocByRole ( _ :any , args :any ) {
14
+ const { role} = args ;
15
+ const docs = await docModels . find ( { role :role } )
16
+ return docs
17
+ }
18
+ } ,
19
+ Mutation :{
20
+ async createDoc ( _ :any , args :any ) {
21
+ const { title, description, role} = args . docFields ;
22
+ const doc = await docModels . create ( {
23
+ title :title ,
24
+ description :description ,
25
+ role :role
26
+ } ) ;
27
+ return doc ;
28
+ } ,
29
+ async deleteDoc ( _ :any , args :any ) {
30
+ const doc = await docModels . findOneAndDelete ( { id :args . id } )
31
+ return doc ;
32
+ } ,
33
+ async updateDoc ( _ :any , args :any ) {
34
+ const { id} = args ;
35
+ const { title, description, role} = args . docFields
36
+ let doc = await docModels . findOne ( { _id :id } ) ;
37
+ if ( ! doc ) {
38
+ return "Document don't exist"
39
+ }
40
+ doc . title = title ;
41
+ doc . description = description ;
42
+ doc . role = role
43
+ await doc ?. save ( )
44
+ return doc
45
+ }
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ import { gql } from "apollo-server-core" ;
2
+
3
+ export const DocSchema = gql `
4
+ type Doc {
5
+ id: ID!
6
+ title: String!
7
+ description: String!
8
+ role:String!
9
+ }
10
+
11
+ input createDocVariables {
12
+ title:String
13
+ description:String
14
+ role:String
15
+ }
16
+ type Query {
17
+ getDoc(id: ID!): Doc
18
+ getAllDocs: [Doc!]!
19
+ getDocByRole(role:String!):[Doc!]!
20
+ }
21
+ input docUpdate {
22
+ title: String
23
+ description: String
24
+ role:String
25
+ }
26
+ type Mutation {
27
+ createDoc(docFields: createDocVariables!): Doc
28
+ deleteDoc(id: ID!): Doc
29
+ updateDoc(id: ID!, docFields: docUpdate): Doc
30
+ }
31
+ ` ;
You can’t perform that action at this time.
0 commit comments