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

feat: rover dev #1190

Merged
merged 118 commits into from
Sep 22, 2022
Merged

feat: rover dev #1190

merged 118 commits into from
Sep 22, 2022

Conversation

EverlastingBugstopper
Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper commented Jul 26, 2022

Test it out

pre-built release

we are actively publishing alphas from this branch. please see the release notes for testing instructions.

bleeding edge

if you want to test the very latest changes made to this branch, follow these instructions:

  1. clone this repo (git clone https://github.com/apollographql/rover.git)
  2. check out this branch (git checkout avery/alt-subgraph-dev)
  3. install rustup
  4. run cargo rover install --force to build rover and install it locally
  5. if you have your own subgraph projects to test, try spinning up your subgraph servers, and then running rover dev in each subgraph project directory to run through the auto-setup
  6. if you don't have your own subgraph projects, check out the examples directory. there are two examples set up to work with rover dev - dev (which is like a hello world for 4 different subgraphs, each with one field, nothing fancy) and supergraph-demo, which takes the JS subgraphs from supergraph-demo-fed2 and provides you with a live-reloading supergraph dev server (see the README for more info)

Usage

this is the output of the help command (minus global options that already exist in other rover commands)

$ cargo rover dev --help
rover-dev 
Run your supergraph locally with a router and one or more subgraphs.

The first `rover dev` process you run starts a dev instance of the Apollo Router and connects it to
the running subgraph you specify. You can then run additional instances of `rover dev` to add more
subgraphs to your local supergraph (the same router instance is used). As you add subgraphs, `rover
dev` automatically composes all subgraph schemas into a new supergraph schema for the router.

The router instance is tied to the *first* `rover dev` process. If you terminate that process, the
router terminates. If you terminate a `rover dev` process *besides* the first process (thereby
removing a subgraph), a new supergraph schema is composed from the remaining subgraphs.

⚠️ Do not run this command in production! ⚠️ It is intended for local development.

USAGE:
    rover dev [OPTIONS]

OPTIONS:
        --name <SUBGRAPH_NAME>
            The name of the subgraph. 

            This must be unique to each `rover dev` session.

    -p, --port <PORT>
            The port the graph router should listen on.
            
            If you start multiple `rover dev` sessions on the same port, they will communicate with
            each other.
            
            If you start multiple `rover dev` sessions with different ports, they will not
            communicate with each other.
            
            [default: 3000]

    -s, --schema <SUBGRAPH_SCHEMA_PATH>
            The path to a GraphQL schema file that `rover dev` will use as this subgraph's schema.
            
            If this argument is passed, `rover dev` does not periodically introspect the running
            subgraph to obtain its schema. Instead, it watches the file at the provided path and
            recomposes the supergraph schema whenever changes occur.

    -u, --url <SUBGRAPH_URL>
            The URL that the `rover dev` router should use to communicate with this running subgraph
            (e.g., http://localhost:4000).
            
            This must be unique to each `rover dev` session and cannot be the same endpoint used by
            the graph router, which are specified by the `--port` argument.

🚧 Outstanding work

🐞Bugs

According to the issue tracker there are no bugs in rover dev. This is highly unlikely. If you encounter a bug, please submit an issue.

🎉Features

No new planned features.

💅Polish

No planned polish.

📚 Docs

No planned docs.

Completed items

🙅 Things we won't do for the initial release

Before releasing

  • make sure to add tests back to our release pipeline, it's nice to skip them for quick alphas but we should run them when we go to main

This is a long-running feature branch

this one is a doozy with lots of commits. i'm trying my best to keep this branch as stable as possible, and will be making individual pull requests against it before merging them in as of commit ae3f337.

background

this pr lays the ground work for an opinionated federated workflow. see the below for an approximate workflow (log messages were just typed by me in figma and don't reflect the state of this PR)

screenshot of a figma workflow file that depicts the workflow i describe in the next two paragraphs

currently this PR does almost everything in the screenshot except rover new. rover new work can be found in #1287

@EverlastingBugstopper
Copy link
Contributor Author

fwiw - i cannot reproduce when i just run rover supergraph compose with the ./examples/dev/supergraph.graphql file with the router. it seems to take it a bit to detect the change and then apply the reload, i wonder what's going on behind the scenes here...

@EverlastingBugstopper
Copy link
Contributor Author

relevant code is in ./src/command/subgraph/dev.rs and if you wanna know what all the saucer stuff is about, src is here. all it's really doing is wrapping the user-provided beam function in a closure and using rayon::join on them with ParallelSaucer - but we don't even really use that here and are just calling beam directly

fixes #1260 by sending a version check at the start of each `rover dev`
session that ensures the two are the same. this should prevent protocol
bugs if we make changes to it down the line since everything will use
the same version.
fixes #1311 by updating to the latest `interprocess` commit, we can be
sure we aren't using too many file descriptors per process since they
are cleaned up, even on M1 machines.
fixes #1315 by using a `crossbeam_channel` to handle all subgraph updates in the main `rover dev` session. this should significantly reduce the overhead of running a single `rover dev` session, and make router shutdowns on ctrl+c much more durable. additionally, if the unix socket is broken, it shouldn't crash the main `rover dev` session, it will log the error and continue gracefully, while the attached session shuts down.
router logs are no longer printed by default when running `rover dev`.
they can be printed with `--log info` or `--log debug` and they will be
printed in the same format as `rover` logs are.

additionally this PR renames `--port` to `--supergraph-port` and adds
`--supergraph-address` which allows you to bind the router to a specific
ip.
@EverlastingBugstopper EverlastingBugstopper merged commit 74e9ea7 into main Sep 22, 2022
@EverlastingBugstopper EverlastingBugstopper deleted the avery/alt-subgraph-dev branch September 22, 2022 19:18
EverlastingBugstopper added a commit that referenced this pull request Sep 26, 2022
## 🚀 Features

- **`rover template` command suite - @dbanty, @michael-watson,
@EverlastingBugstopper, #1287**

Two new commands have made their way to Rover: `rover template list` and
`rover template use`. These commands provide a similar experience to
`create-react-app`, and allow you to extract GraphQL project templates
to your local machine. Check out [the
docs](https://www.apollographql.com/docs/rover/commands/template/) for
more on this new functionality.

- **`rover dev` to facilitate developing a supergraph on your local
machine - @EverlastingBugstopper, #1190**

`rover dev` allows you to join multiple running subgraph servers
together into a local supergraph, providing the ability to run queries
and inspect query plans with Apollo Sandbox. Check out [the
docs](https://www.apollographql.com/docs/rover/commands/dev) for more on
this new functionality.

- **If E013 is thrown and `$APOLLO_KEY` is set, give a more helpful
suggestion - @ptondereau, #1284, #1285**

If Studio fails to recognize an API key and `APOLLO_KEY` is set,
recommend unsetting the environment variable to use `--profile default`
instead.

## 🐛 Fixes

- **Remove useless stdout line for composition results - @ptondereau,
#1124, #1291**

## 🛠 Maintenance

- **Link directly to API Keys page in Studio - @abernix, #1202**

The `rover config auth` command will now provide a link that takes you
directly to the "API Keys" page where you can create a Personal API Key,
rather than a page that requires you to click through to another page.

- **Prefer "supergraph schema" terminology to "gateway" -
@EverlastingBugstopper, #1239, #1332**

`rover subgraph publish` now refers to updating the "supergraph schema"
as opposed to updating the "gateway," since supergraph schema consumers
can be routers and/or gateways now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment