This repository was archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 672
feat: graphql #371
Draft
jackcmeyer
wants to merge
14
commits into
master
Choose a base branch
from
add-graphql
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: graphql #371
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e0f2d80
feat: adding some graphql setup
jackcmeyer 0795bae
Merge branch 'master' into add-graphql
fox1t 8317a8e
Merge branch 'master' into add-graphql
matteovivona a94c180
Merge branch 'master' into add-graphql
20f0dfd
Merge branch 'master' into add-graphql
4a9f984
Merge branch 'master' into add-graphql
matteovivona b895362
Merge branch 'master' into add-graphql
11d46e2
Merge branch 'master' into add-graphql
matteovivona 7756159
Merge branch 'master' into add-graphql
c46b22e
Merge branch 'master' into add-graphql
62d5ad3
Merge branch 'master' into add-graphql
af1f570
Merge branch 'master' into add-graphql
17824a8
Merge branch 'master' into add-graphql
df39eaa
Merge branch 'master' into add-graphql
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,24 +33,28 @@ | |
| "fastify": "~3.5.0", | ||
| "fastify-autoload": "~3.3.0", | ||
| "fastify-blipp": "~3.0.0", | ||
| "fastify-cors": "~4.1.0", | ||
| "fastify-helmet": "~5.0.1", | ||
| "fastify-http-proxy": "~4.0.2", | ||
| "fastify-mongodb": "~2.0.1", | ||
| "fastify-no-icon": "~4.0.0", | ||
| "fastify-plugin": "~2.3.3", | ||
| "graphiql": "~1.0.5", | ||
| "graphql-tools": "~6.2.0", | ||
| "make-promises-safe": "~5.1.0", | ||
| "mercurius": "~6.3.0", | ||
| "mongoose": "~5.10.7", | ||
| "nano": "~8.2.1", | ||
| "qs": "~6.9.1", | ||
| "require-from-string": "~2.0.2", | ||
| "fastify-cors": "~4.1.0", | ||
| "fastify-gql": "~5.8.1", | ||
| "fastify-helmet": "~5.0.1", | ||
| "fastify-no-icon": "~4.0.0", | ||
| "graphql-tools": "~6.2.0" | ||
| "require-from-string": "~2.0.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@commitlint/cli": "~11.0.0", | ||
| "@commitlint/config-conventional": "~11.0.0", | ||
| "@commitlint/prompt": "~11.0.0", | ||
| "@types/glob": "~7.1.1", | ||
| "@types/mkdirp": "~1.0.0", | ||
| "@types/mongoose": "~5.7.36", | ||
|
Member
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.11.1", | ||
| "@types/qs": "6.9.5", | ||
| "@types/require-from-string": "~1.2.0", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
Member
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() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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({ | ||
|
Member
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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const infoResolvers = { | ||
| Query: { | ||
| info: () => 'HospitalRun GraphQL API', | ||
| }, | ||
| } | ||
|
|
||
| export default infoResolvers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const infoSchema = ` | ||
| extend type Query { | ||
| info: String! | ||
| } | ||
| ` | ||
|
|
||
| export default infoSchema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import mongoose from 'mongoose' | ||
|
|
||
| export type Entity = mongoose.Document |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| "exclude": [ | ||
| "node_modules", | ||
| "dist", | ||
| "src/db", | ||
| "src/bin" | ||
| ], | ||
| "compilerOptions": { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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