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

Quickstart tutorial with Next.js #8269

Merged
merged 37 commits into from
Feb 19, 2025
Merged

Quickstart tutorial with Next.js #8269

merged 37 commits into from
Feb 19, 2025

Conversation

scotttrinh
Copy link
Contributor

No description provided.

@scotttrinh scotttrinh changed the title Add edb::env-switcher and edb::split-section sphinx directives wip Quickstart tutorial with Next.js Jan 29, 2025
@scotttrinh scotttrinh requested a review from beerose January 29, 2025 02:06
@scotttrinh scotttrinh force-pushed the quickstart-next branch 2 times, most recently from 149c3ab to c3cea31 Compare January 30, 2025 20:30
@scotttrinh scotttrinh changed the base branch from new-gel-docs to gel-docs-directives January 30, 2025 21:32
@jaclarke jaclarke force-pushed the gel-docs-directives branch from 43ca0e9 to 9719a03 Compare February 4, 2025 13:46
Base automatically changed from gel-docs-directives to new-gel-docs February 4, 2025 13:48
Copy link

github-actions bot commented Feb 4, 2025

Docs preview deploy

✅ Successfully deployed docs preview for commit e5d167e:

https://edgedb-docs-17ruec9gk-edgedb.vercel.app

(Last updated: Feb 19, 2025, 14:40:44 UTC)

- Show query builder in the very first example
- Move query strings (and query builder expression) out of the route
  handler function to make the route handler more readable.
- Use JS to get an `order` value for the card instead of EdgeQL
- Make the tip about parsing input data more emphatic
@scotttrinh scotttrinh marked this pull request as ready for review February 6, 2025 17:37
@scotttrinh scotttrinh changed the title wip Quickstart tutorial with Next.js Quickstart tutorial with Next.js Feb 6, 2025
scotttrinh and others added 4 commits February 6, 2025 13:25
It works fine without the namespace, but if any other tool happened to
shadow that same name, it would break.

.. edb:split-section::

Let's take a look at the schema we've generated in our built-in database UI. We can use this tool to visualize our data model and see the object types and links we've defined.
Copy link
Member

Choose a reason for hiding this comment

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

We need like a gallery widget here. First screenshot will be dashboard with circled button for "Schema Viewer", second will be the viewer

Suggested change
Let's take a look at the schema we've generated in our built-in database UI. We can use this tool to visualize our data model and see the object types and links we've defined.
Let's take a look at the schema we've generated in our built-in database UI. We can use it to visualize our data model and see the object types and links we've defined.


.. edb:split-section::

Use git to clone the Next.js starter template into a new directory called ``flashcards``. This will create a fully configured Next.js project and a local |Gel| instance with an empty schema. You will see the database instance being installed and the project being initialized. You are now ready to start building the application.
Copy link
Contributor

@diksipav diksipav Feb 17, 2025

Choose a reason for hiding this comment

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

maybe we can add link to github repo anyway
maybe say: instance being created instead of installed even tho we repeat the create

- ``gel.toml``: The configuration file for the Gel project instance. Notice that we have a ``hooks.migration.apply.after`` hook that will run ``npx @gel/generate edgeql-js`` after migrations are applied. This will generate the query builder code that you'll use to interact with the database. More details on that to come!
- ``dbschema/``: This directory contains the schema for the database, and later supporting files like migrations, and generated code.
- ``dbschema/default.gel``: The default schema file that you'll use to define your data model. It is empty for now, but you'll add your data model to this file in the next step.
- ``lib/gel.ts``: A utility module that exports the Gel client, which you'll use to interact with the database.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe just say files instead of new files (all files are new), I am biased to think that new files are generated with gel project init, but here actually nothing new is created because it already exist in the cloned folder, ofc I know that new users don't have this bias... I just find it weird to say new files, maybe is just me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I meant "new to you" as in: "you already recognize most of the files since they're Next.js app router files, here are the ones you do not recognize". I'll reword!


.. edb:split-section::

The flashcards application has a simple data model, but it's interesting enough to get a taste of many of the features of the |Gel| schema language. You have a ``Card`` type that describes a single flashcard, which for now contains two required string properties: ``front`` and ``back``. Each ``Card`` belongs to a ``Deck``, and there is an explicit ordering to the cards in a given deck.
Copy link
Contributor

Choose a reason for hiding this comment

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

of many features instead of of many of the features, or we can say sth along the lines: The flashcards application has a straightforward data model, yet it's engaging enough to showcase many features of the Gel schema language.


.. code-block:: typescript

interface Card {
Copy link
Contributor

Choose a reason for hiding this comment

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

in the tutorial app we define RawJSONCard and RawJSONDeck in both lib/models and in the app/model, is that needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we don't need both, PRs welcome, but that's more of an implementation detail than something related to the quickstart text itself. We don't actually mention those model modules directly.


The flashcards application has a simple data model, but it's interesting enough to get a taste of many of the features of the |Gel| schema language. You have a ``Card`` type that describes a single flashcard, which for now contains two required string properties: ``front`` and ``back``. Each ``Card`` belongs to a ``Deck``, and there is an explicit ordering to the cards in a given deck.

Looking at the mock data, you can see this structure in the JSON.
Copy link
Contributor

@diksipav diksipav Feb 18, 2025

Choose a reason for hiding this comment

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

maybe to mention here that we mean the file deck-edgeql.json?
actually there is also empty file decks.json, s maybe we delete that one and rename the deck-edgeql.json to deck.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

decks.json is where the data lives once you import the deck-edgeql.json, so I'd like to keep that rather than make the actions module more complicated by needing to check if it exists, etc.

maybe to mention here that we mean the file deck-edgeql.json?

Yeah, that's a good call. Maybe show a bit of the data itself.


To make |Gel| do that, you need to do two quick steps:

1. **Create a migration**: a file with a list of low-level instructions.
Copy link
Contributor

@diksipav diksipav Feb 18, 2025

Choose a reason for hiding this comment

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

I'd explain this a bit more clearly:
Create a migration: a file containing a set of low level instructions that define how the database schema should change. It records any additions, modifications, or deletions to your schema in a way that the database can understand.

and something along the lines:
Apply the migration: This executes the migration file, instructing Gel to implement the recorded changes in the database. Essentially, this step updates the database structure to match your defined schema, ensuring that the Deck and Card types are created and ready for use.


.. note::

Notice that the ``createClient`` function isn't being passed any connection details. How does |Gel| know how to connect to the database you set up earlier? When we ran ``npx gel project init`` earlier, the CLI created credentials for the local database and stored them in a well-known location. When you initialize your client with ``createClient()``, |Gel| will check the places it knows about for connection details.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe: the CLI created credentials for the local database and stored them in a well-known location on disk. When you initialize your client with createClient(), Gel will check these known locations on your machine for connection details."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It checks both this project location and also environment variables, as well as explicit connection details. What I'm trying to say here is that you do not ever need to worry about createClient: locally it will use the project details, and in production, you use environment variables. I'll try to make that more clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes yes I know it check all those things, if u think what is already here is good enough feel free to ignore my comment : ) I feel like we should try to give a bit more explanations in the tutorial and more links to the reference docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, in general my feelings on the quick start are:

  • Do not give more details than absolutely necessary or make the user make any decisions. This is a guided path, not an exploration.
  • We absolutely should provide more resources in each section to the relevant documentation for further reading.

To the first point, what "absolutely necessary" means is open to interpretation, and our createClient flow is just unusual enough to require some explanation, but I think it needs to be as absolutely limited as possible without being confusing. Just give enough detail to answer the most obvious questions a typical reader might have.

As far as linking to more details: absolutely! We're currently rewriting all of the documentation, so we don't yet have links to these places. As soon as we do, we should do another pass and add links and resources sections to each one.

@scotttrinh scotttrinh merged commit c086931 into new-gel-docs Feb 19, 2025
25 checks passed
@scotttrinh scotttrinh deleted the quickstart-next branch February 19, 2025 15:04
vpetrovykh pushed a commit that referenced this pull request Feb 19, 2025
1st1 pushed a commit that referenced this pull request Feb 21, 2025
1st1 pushed a commit that referenced this pull request Feb 21, 2025
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.

5 participants