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

adding required methods and functions for "__typename must be const" change #137

Closed

Conversation

Rash-Hit
Copy link
Contributor

@Rash-Hit Rash-Hit commented Mar 25, 2024

Resolves #122

This pr will add

  • Required Method and function for " __typename must be const" Change
  • Test Files
  • Changes In Other Test Files

Before -

image

After

image

Fix

image


@captbaritone Please review , and let me know for the change's

Copy link

netlify bot commented Mar 25, 2024

Deploy Preview for grats ready!

Name Link
🔨 Latest commit d95570c
🔍 Latest deploy log https://app.netlify.com/sites/grats/deploys/6609126576200c00080b0f37
😎 Deploy Preview https://deploy-preview-137--grats.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@captbaritone
Copy link
Owner

Nice work, this is looking great! Next steps would be:

  1. Update the existing tests (unit and itegration) to not trigger this issue
  2. Create new test fixtures which trigger each of these conditions
  3. Update docs to always include as const (Running pnpm run build in the grats dir and pnpm run grats from within the website dir should uncover some of these, as it will rebuild many of the snippets)
  4. Update example projects to include as const (pnpm run integration-tests should uncover these)

Tips on running fixtures tests can be found here: https://github.com/captbaritone/grats/blob/main/CONTRIBUTING.md#automated-tests

Copy link
Owner

@captbaritone captbaritone left a comment

Choose a reason for hiding this comment

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

Looking good! A few comments about error messages.

Also, this would be a great candidate for a code action. I landed support for them yesterday: 0b53e3d

If you'd like to add support for that as part of this change, you can see an example here. (you'll need to rebase)

Also happy to add this myself or have that be a followup PR.

Finally, can search through the website directory for instances of __typename and see if there are any changes that need to be made there?

return false;
}

if (node.initializer.type.typeName.escapedText !== "const") {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if (node.initializer.type.typeName.escapedText !== "const") {
if (node.initializer.type.typeName.escapedText !== ts.SyntaxKind.ConstKeyword) {

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've tried this thing , but getting this error
image

and the reason is
image

image

Copy link
Owner

Choose a reason for hiding this comment

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

Interesting. I guess it doesn't parse as const as a keyword! Leaving this as a string is fine.

src/Errors.ts Outdated Show resolved Hide resolved
src/Errors.ts Outdated
}

export function typeNameTypeNotReferenceNode() {
return `Expected \`__typename\` property type to be a TypeReferenceNode. ${TYPENAME_CONTEXT}`;
Copy link
Owner

Choose a reason for hiding this comment

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

I'd love to try to avoid using AST type names in error messages if possible. I don't think most developers know (or should need to know) what a TypeReferenceNode or Identifier are. Maybe we should just simplify this down to one error message that looks more like the one in typeNameInitializeNotExpression and use it for all of these new error cases?

@captbaritone
Copy link
Owner

Also, can we make sure to have a fixture test for every error case? I don't think I see some of the new error messages represented in the test fixtures.

@Rash-Hit
Copy link
Contributor Author

@captbaritone . sir can you please review it and let me know for the required changes ..

@captbaritone
Copy link
Owner

Thanks! I had some commits on main which I had to revert (unrelated to this PR) which meant I had to manually merge as 1eed523

You can see your commits (plus a few additions/and fixups) there.

@Rash-Hit Rash-Hit deleted the #122-__typename-must-be-const---fix branch April 1, 2024 02:04
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.

__typename must be const
2 participants