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.
Summary
This sets up a GraphQL API for
next-ai-news
using Fuse.Instead of having database queries in the server components directly, this introduces a central data layer that can be used across server- and client components to resolve data.
This, of course, adds additional complexity & code by introducing an extra layer in the architecture. Whether that additional layer is worth the overhead really depends on the goals of this project; I cannot make that tradeoff decision.
Implementation notes
types/
folder, mostly in thetypes/Story.ts
nodeschema.graphql
) matches the underlying database schemaUser
node and exposing a stories submitter centrally asStory.submitter
, whether it's AI generated or from an authenticated user (i.e.story.submitted_by ?? story.username
only exists once in the API layer and is opaque to the client)execute
runs GraphQL resolution in-process so the data gets resolved from the server rendering process immediately/api/fuse
execute
) or via the API route (withuseQuery
)story.id.replace(/^story_/, "")
to Fuse's opaque unique IDs for simpler client logic and better client caching.--turbo
fromnext dev
for nowLocal development
Everything about local development stays the same as before:
next dev
. The only additional step is that when first opening this code in VSCode, you need to CMD+Shift+P, "TypeScript: Select TypeScript Version…" and select "Use Workspace Version" to enable GraphQLSP and get type auto-completion for GraphQL queries on the client:One of the deep dependencies throws a strange webpack parsing error. This error does not impact any functionality however I haven't found a way to silence it either. We can dig further into this.
Todo