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

Make operations work with any #2170

Merged
merged 11 commits into from
Jul 11, 2024
Merged

Make operations work with any #2170

merged 11 commits into from
Jul 11, 2024

Conversation

sodic
Copy link
Contributor

@sodic sodic commented Jul 9, 2024

Steps to reproduce

In 0.14.0-rc1:

  1. User defines their operation's input type to be any (either explicitly or because they are using JS). For example:
export const getFoo = (args: any, context: any): any => { ... }
  1. Both server and client API don't accept a payload:
  • Client: getFoo has type () => Promise<any>
  • Server: getFoo has type () => Promise<any> if non-authenticated or (ctx: ...) => Promise<any> if authenticated.

Expected behavior:

The types should be (args: any) => Promise<any> and (args: any, ctx: ...) => Promise<any>.

Explanation

We wanted to expose void operations as receiving no arguments (#2004).
To do so, we check whether Input extends void and act accordingly.

Unfortunately, any extends void as well, which made us treat an operation with input of type any like it had input of type void.

To fix it, we now first check whether the input is of type any.

Comment on lines 64 to 65
Expect<Equal<typeof getAnyNoAuth, QueryMetadata & ((args: any) => Promise<any>)>>,
Expect<Equal<typeof getAnyAuth, QueryMetadata & ((args: any) => Promise<any>)>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regression tests.

Comment on lines 107 to 108
Expect<Equal<typeof getAnyNoAuth, (args: any) => Promise<any>>>,
Expect<Equal<typeof getAnyAuth, (args: any, ctx: { user: AuthUser }) => Promise<any>>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regression tests.


export const testingAction: TestingAction = async (args, context) => {
// todo(filip): When sorting out the tests, we should also test whether the
// TODO: (Filip) When sorting out the tests, we should also test whether the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed how I write these notes because my editor nicely highlights them if they start with TODO:

Copy link
Contributor

@infomiho infomiho left a comment

Choose a reason for hiding this comment

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

Left some small comments. Make sure to update the e2e tests 👍

@sodic sodic merged commit 1aa139e into main Jul 11, 2024
6 checks passed
@sodic sodic deleted the filip-fix-any-in-operations branch July 11, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants