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

updated fastify plugin to work with fastify v5 #2669

Merged
merged 3 commits into from
Oct 12, 2024

Conversation

imolorhe
Copy link
Collaborator

@imolorhe imolorhe commented Oct 6, 2024

Fixes

Closes #2663

Checks

  • Ran yarn test-build
  • Updated relevant documentations
  • Updated matching config options in altair-static

Changes proposed in this pull request:

Summary by Sourcery

Update the Altair Fastify plugin to support Fastify v5 by modifying the plugin function signature and adding an example for Fastify v5 usage.

New Features:

  • Introduce an example for using the Altair Fastify plugin with Fastify v5.

Enhancements:

  • Update the Altair Fastify plugin to be compatible with Fastify v5 by changing the plugin function signature and using FastifyInstance.

Copy link

sourcery-ai bot commented Oct 6, 2024

Reviewer's Guide by Sourcery

This pull request updates the Altair Fastify plugin to work with Fastify v5. The main changes involve modifying the plugin structure, updating type imports, and adjusting the export mechanism. An example for Fastify v5 usage has also been added.

Sequence diagram for Fastify v5 plugin registration

sequenceDiagram
    actor User
    participant FastifyApp as Fastify Application
    participant AltairFastify as AltairFastify Plugin
    User->>FastifyApp: Start application
    FastifyApp->>AltairFastify: Register plugin
    AltairFastify-->>FastifyApp: Plugin registered
    FastifyApp->>User: Server listening at http://localhost:3000
Loading

Updated class diagram for Altair Fastify Plugin

classDiagram
    class AltairFastifyPluginOptions {
        path: string
        baseURL: string
        endpointURL: string
    }
    class fastifyAltairPluginFn {
        +fastify: FastifyInstance
        +AltairFastifyPluginOptions
    }
    class AltairFastify {
        +fastify: ">= 3.x"
        +name: "altair-fastify-plugin"
    }
    AltairFastifyPluginOptions <|-- fastifyAltairPluginFn
    fastifyAltairPluginFn <|-- AltairFastify
    AltairFastifyPluginOptions : RenderOptions
Loading

File-Level Changes

Change Details Files
Refactored the Fastify plugin to use async/await syntax
  • Changed the plugin function signature from a callback to an async function
  • Removed the 'done' callback parameter
  • Updated the function name from 'fastifyAltairPlugin' to 'fastifyAltairPluginFn'
packages/altair-fastify-plugin/src/index.ts
Updated type imports and usage for Fastify v5 compatibility
  • Replaced 'FastifyPluginCallback' import with 'FastifyInstance'
  • Updated the plugin function parameter type to 'FastifyInstance'
packages/altair-fastify-plugin/src/index.ts
Modified the plugin export mechanism
  • Changed the default export to a named export 'AltairFastify'
  • Updated the fastify-plugin wrapper to use the new function name
packages/altair-fastify-plugin/src/index.ts
Added an example for Fastify v5 usage
  • Created a new file with an example of how to use the updated plugin with Fastify v5
  • Demonstrated the import of the new named export 'AltairFastify'
  • Showed how to register the plugin with Fastify v5
examples/fastify-v5/index.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @imolorhe - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding basic error handling in the new example file (examples/fastify-v5/index.ts) for server startup.
  • Please ensure that the documentation is updated to reflect the changes for Fastify v5 compatibility.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

github-actions bot commented Oct 6, 2024

Visit the preview URL for this PR (updated for commit 5b0a193):

https://altair-gql--pr2669-imolorhe-support-fas-p7fv048u.web.app

(expires Sat, 19 Oct 2024 12:49:06 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 02d6323d75a99e532a38922862e269d63351a6cf

@xoldd
Copy link

xoldd commented Oct 7, 2024

@imolorhe Better to follow the standard fastify plugin syntax:

export const AltairFastify = fp<AltairFastifyPluginOptions>(
	async (
		fastify,
		{
			baseURL = "/altair/",
			endpointURL = "/graphql",
			path = "/altair/",
			...renderOptions
		},
	) => {
		// logic here
	},
	{
		fastify: ">= 3.x",
		name: "altair-fastify-plugin",
	},
);

export default AltairFastify;

@imolorhe
Copy link
Collaborator Author

imolorhe commented Oct 7, 2024

@xoldd fastify plugins can't use named exports?

@xoldd
Copy link

xoldd commented Oct 7, 2024

@xoldd fastify plugins can't use named exports?

They can. I've used a named export. I also used a default export because many fastify plugins do that.

Edit: Just, noticed the export const plugin, removed that.

@imolorhe
Copy link
Collaborator Author

imolorhe commented Oct 7, 2024

@xoldd considering the issues @kingston pointed out in #2667 I would be more comfortable sticking with just the named export, unless there's a valid reason why the default export is necessary.

@xoldd
Copy link

xoldd commented Oct 7, 2024

@xoldd considering the issues @kingston pointed out in #2667 I would be more comfortable sticking with just the named export, unless there's a valid reason why the default export is necessary.

Yeah the default export isn't necessary. I don't see how it would be a problem but you can skip it if you want to. Everything I've shown in the syntax is just the more cleaner way of doing it, it wouldn't make a difference in functionality compared to how you've done it.

@imolorhe imolorhe added this pull request to the merge queue Oct 12, 2024
Merged via the queue into master with commit 250baea Oct 12, 2024
14 checks passed
@imolorhe imolorhe deleted the imolorhe/support-fastify-v5 branch October 12, 2024 13:03
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.

[BUG] altair-plugin-fastify doesn't work with fastify v5
2 participants