Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events v2: Skeleton GraphQL resolvers for basic operations #8033

Merged
merged 23 commits into from
Nov 25, 2024

Conversation

rikukissa
Copy link
Member

@rikukissa rikukissa commented Nov 20, 2024

Copy link

Oops! Looks like you forgot to update the changelog. When updating CHANGELOG.md, please consider the following:

  • Changelog is read by country implementors who might not always be familiar with all technical details of OpenCRVS. Keep language high-level, user friendly and avoid technical references to internals.
  • Answer "What's new?", "Why was the change made?" and "Why should I care?" for each change.
  • If it's a breaking change, include a migration guide answering "What do I need to do to upgrade?".

@@ -3,7 +3,8 @@
"skipLibCheck": true,
"baseUrl": "./src",
"paths": {
"@gateway/*": ["./*"]
"@gateway/*": ["./*"],
"@events/*": ["../../events/src/*"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little nasty – it is because gateway imports the appRouter from events

import type { AppRouter } from '@opencrvs/events/src/router'

which again imports modules inside Events with the @events/... paths.

❯ yarn test:compilation
yarn run v1.22.4
$ tsc --noEmit
../events/src/service/events.ts:12:27 - error TS2307: Cannot find module '@events/storage/mongodb' or its corresponding type declarations.

12 import { getClient } from '@events/storage/mongodb'
                             ~~~~~~~~~~~~~~~~~~~~~~~~~

])
})
)
type: z.string()
Copy link
Member Author

@rikukissa rikukissa Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only field the user can really send at the point of Event creation is type if we take on the approach of only submitting actions like registerEvent(eventId, registrationData) from the client

url: env.EVENTS_URL,
transformer: superjson,
headers({ opList }) {
const headers = opList[0].context?.headers
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all happy about this. opList is a non-empty list but still..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we parse it and throw to be sure, have a default or acknowledge the possibly undefined?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit wonky that the opList cannot be strictly typed :/ but yeah works like this or ! with a comment or ^

@rikukissa rikukissa added the 🚀 Ready to deploy Deployment automation should pick this PR up and start auto-deploying it label Nov 21, 2024
@ocrvs-bot
Copy link
Collaborator

Your environment is deployed to https://ocrvs-7824-b.opencrvs.dev

Copy link
Collaborator

@makelicious makelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Non functional comments

if (obj.type === ActionType.REGISTER) {
return 'RegisterAction'
}
return 'CreateAction'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to be explicit here e.g. not defaulting to anything but exhausting the options

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do type satisfies never to make sure all cases are handled at the end

url: env.EVENTS_URL,
transformer: superjson,
headers({ opList }) {
const headers = opList[0].context?.headers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we parse it and throw to be sure, have a default or acknowledge the possibly undefined?

@@ -29,6 +29,7 @@ export const env = cleanEnv(process.env, {
APPLICATION_CONFIG_URL: url({ devDefault: 'http://localhost:2021/' }),
NOTIFICATION_URL: url({ devDefault: 'http://localhost:2020/' }),
WORKFLOW_URL: url({ devDefault: 'http://localhost:5050/' }),
EVENTS_URL: url({ devDefault: 'http://localhost:5555/' }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opinion: Since we are using both conventions, with and without trailing slash, I would opt for without when introducing new ones. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; an extra trailing slash in our current setup might convey to a newcomer that it has a meaning that it doesn't

.mutation(async (options) => {
return addAction(options.input.eventId, {
...options.input.action,
type: 'NOTIFY',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using these through the ActionType.NOTIFY will make changing them much easier in the future.

registrationNumber: z.string()
})
export const CreateActionInput = ActionInputBase.extend({})
export const NotifyActionInput = ActionInputBase.extend({})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment for this pattern? Is it a matter of taking copy of the base an separating the type extension?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegisterActionInput.extend({ type: z.enum([ActionType.REGISTER]) }) since one could argue that this is not RegisterActionInput until it has the type

DeclareActionInput.extend({ type: z.enum([ActionType.DECLARE]) }),
RegisterActionInput.extend({ type: z.enum([ActionType.REGISTER]) })
])
.and(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there semantic difference between extend and and?

Copy link
Collaborator

@naftis naftis Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.and apparently creates { name: string } & { age: number } while .extend creates { name: string; age: number }

https://zod.dev/?id=merge (merge is equivalent to extend but has better example :D)
vs
https://zod.dev/?id=and

@@ -85,17 +85,36 @@ jobs:
with:
node-version-file: .nvmrc

- name: Extract dependencies for ${{ matrix.package }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could benefit from adding description for this documenting the reason/aim

@@ -108,6 +108,7 @@
"xregexp": "^4.2.0"
},
"devDependencies": {
"@opencrvs/gateway": "^1.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the client need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does now as I added the logic to look at workflow dependencies to figure out which packages cannot be optimised away in build and test processes. Client did seem to have a dependency to gateway for whatever reason

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to find the dependency but couldn't :O

@rikukissa rikukissa changed the base branch from feat/event-types to develop November 25, 2024 08:39
@rikukissa rikukissa merged commit 89ce49a into develop Nov 25, 2024
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Ready to deploy Deployment automation should pick this PR up and start auto-deploying it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants