-
-
Notifications
You must be signed in to change notification settings - Fork 643
feat: graphql #371
base: master
Are you sure you want to change the base?
feat: graphql #371
Changes from all commits
e0f2d80
0795bae
8317a8e
a94c180
20f0dfd
4a9f984
b895362
11d46e2
7756159
c46b22e
62d5ad3
af1f570
17824a8
df39eaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,17 @@ | |
"fastify": "~3.7.0", | ||
"fastify-autoload": "~3.5.2", | ||
"fastify-blipp": "~3.0.0", | ||
"fastify-cors": "~4.1.0", | ||
"fastify-helmet": "~5.0.1", | ||
"fastify-http-proxy": "~4.3.0", | ||
"fastify-mongodb": "~2.0.1", | ||
"fastify-no-icon": "~4.0.0", | ||
"fastify-plugin": "~3.0.0", | ||
"graphiql": "~1.0.5", | ||
"graphql-tools": "~7.0.0" | ||
"make-promises-safe": "~5.1.0", | ||
"mercurius": "~6.3.0", | ||
"mongoose": "~5.10.7", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not going to use mongoose since it is really slow and it will become a major bottleneck soon. For the moment we can leave just the mongodb driver |
||
"nano": "~9.0.0", | ||
"qs": "~6.9.1", | ||
"require-from-string": "~2.0.2", | ||
|
@@ -51,7 +59,8 @@ | |
"@commitlint/prompt": "~12.0.0", | ||
"@types/glob": "~7.1.1", | ||
"@types/mkdirp": "~1.0.0", | ||
"@types/node": "~14.14.2", | ||
"@types/mongoose": "~5.7.36", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this. |
||
"@types/node": "~~14.14.2", | ||
"@types/qs": "6.9.5", | ||
"@types/require-from-string": "~1.2.0", | ||
"@types/sade": "~1.7.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,20 @@ | ||
import { Server, IncomingMessage, ServerResponse } from 'http' | ||
import { FastifyInstance, FastifyPluginOptions } from 'fastify' | ||
import fastifyCors from 'fastify-cors' | ||
import fastifyHelmet from 'fastify-helmet' | ||
import fastifyAutoload from 'fastify-autoload' | ||
import { join } from 'path' | ||
import GQL from 'fastify-gql' | ||
import schema from './graphql/schema' | ||
import resolvers from './graphql/resolvers' | ||
import mercurius from 'mercurius' | ||
|
||
export default ( | ||
fastify: FastifyInstance<Server, IncomingMessage, ServerResponse>, | ||
_: FastifyPluginOptions, | ||
next: (error?: Error) => void, | ||
) => { | ||
fastify.register(fastifyCors, { | ||
allowedHeaders: ['Content-Type', 'Authorization'], | ||
}) | ||
fastify.register(fastifyHelmet) | ||
// fastify.register(fastifyHelmet) | ||
fastify.register(mercurius, { | ||
defineMutation: true, | ||
} as any) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the types wrong here? If so we can make a PR to mercurius. |
||
fastify.register(fastifyAutoload, { | ||
dir: join(__dirname, 'services'), | ||
}) | ||
|
||
fastify.register(GQL, { schema, resolvers }) | ||
next() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import mongoose, { Schema, Types } from 'mongoose' | ||
import Patient from '../model/Patient' | ||
|
||
const PatientSchema = new Schema({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use json schema for the schemas so we can add them to fastify too when needed. |
||
id: Types.ObjectId, | ||
code: String, | ||
name: Object, | ||
}) | ||
|
||
export default mongoose.model<Patient>('Patient', PatientSchema) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const infoResolvers = { | ||
Query: { | ||
info: () => 'HospitalRun GraphQL API', | ||
}, | ||
} | ||
|
||
export default infoResolvers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const infoSchema = ` | ||
extend type Query { | ||
info: String! | ||
} | ||
` | ||
|
||
export default infoSchema |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const patientResolvers = { | ||
Query: { | ||
info: () => 'HospitalRun GraphQL API', | ||
}, | ||
Mutation: { | ||
createPatient: async (_: any, args: any) => { | ||
console.log(args.patientRequest) | ||
return { | ||
id: 'helloWorld', | ||
name: args.patientRequest.name, | ||
code: args.patientRequest.code, | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
export default patientResolvers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const patientSchema = ` | ||
type Name { | ||
givenName: String | ||
familyName: String | ||
prefix: String | ||
suffix: String | ||
fullName: String | ||
} | ||
|
||
type Patient { | ||
id: ID! | ||
name: Name | ||
code: String! | ||
} | ||
|
||
input NameRequest { | ||
givenName: String | ||
familyName: String | ||
prefix: String | ||
suffix: String | ||
fullName: String | ||
} | ||
|
||
input PatientRequest { | ||
name: NameRequest | ||
code: String! | ||
} | ||
|
||
extend type Mutation { | ||
createPatient(patientRequest: PatientRequest!): Patient! | ||
} | ||
` | ||
|
||
export default patientSchema |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import mongoose from 'mongoose' | ||
|
||
export type Entity = mongoose.Document |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default interface Name { | ||
givenName?: string | ||
familyName?: string | ||
suffix?: string | ||
prefix?: string | ||
fullName?: string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Entity } from './Entity' | ||
import Name from './Name' | ||
|
||
export default interface Patient extends Entity { | ||
name: Name | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Server, IncomingMessage, ServerResponse } from 'http' | ||
import { FastifyInstance, FastifyPluginOptions } from 'fastify' | ||
import infoSchema from '../graphql/info/info-schema' | ||
import infoResolvers from '../graphql/info/info-resolvers' | ||
|
||
export default ( | ||
fastify: FastifyInstance<Server, IncomingMessage, ServerResponse>, | ||
_: FastifyPluginOptions, | ||
next: (error?: Error) => void, | ||
) => { | ||
fastify.graphql.extendSchema(infoSchema) | ||
fastify.graphql.defineResolvers(infoResolvers) | ||
next() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Server, IncomingMessage, ServerResponse } from 'http' | ||
import { FastifyInstance, FastifyPluginOptions } from 'fastify' | ||
import patientSchema from '../graphql/patient/patient-schema' | ||
import patientResolvers from '../graphql/patient/patient-resolvers' | ||
|
||
export default ( | ||
fastify: FastifyInstance<Server, IncomingMessage, ServerResponse>, | ||
_: FastifyPluginOptions, | ||
next: (error?: Error) => void, | ||
) => { | ||
fastify.graphql.extendSchema(patientSchema) | ||
fastify.graphql.defineResolvers(patientResolvers) | ||
next() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
"exclude": [ | ||
"node_modules", | ||
"dist", | ||
"src/db", | ||
"src/bin" | ||
], | ||
"compilerOptions": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed a comma here which is causing build failure. Thankyou