GithubHelp home page GithubHelp logo

hack-the-supergraph's Introduction

Hack the Supergraph - Example Fullstack Supergraph

This repository contains an example of a Fullstack Supergraph with GraphOS.

πŸ“– Prerequisites

In order to run the project locally, you'll need node>=14 installed on your development machines.

πŸƒβ€β™‚οΈπŸ• Powered by GraphOS

GraphOS automatically provisions and hosts a serverless cloud router for this example. Clients query the router instead of individual subgraphs, which enables the router to automatically collect operation metrics and usage data that you can then visualize in Apollo Studio.

Create your free serverless cloud router with GraphOS by signing up for free here.

πŸ‘©β€πŸš€πŸš€βœ¨ Exploring the Supergraph with Explorer, our GraphQL IDE

GraphOS makes it possible to expose a public set of docs for your supergraph that anyone can use! Check out this supergraph's example and try running some queries.

You can create operation collections in the Apollo Studio Explorer, enabling you to save, organize, and share your frequently used GraphQL operations. There is an operation collection for the Website's grouped queries.

🌐 Using @defer in a React App hosted on Netlify

Deployed on Netlify, try @defer

This fullstack application contains a simple React app that utilizes @apollo/client to query GraphOS.

πŸ–₯️ Local development

If you would like to run the website locally, setup the website:

cd website
npm install

To start a local copy of the app on port 3000:

npm start

To debuge the instance, open VS Code and use the launch configuration available in the Debug panel:

code .

VS Code Debugger

Subgraphs

All of the subgraph projects are located in the subgraphs folder. There are currently five subgraphs: orders, products, reviews, shipping, users. Each subgraph is currently built with @apollo/server and hosted on Railway

GitHub Actions

All of the subgraphs in this example have GitHub Action workflows to interact with GraphOS. We created separate workflows to isolate each subgraphs tests and deploys. It was easy enough to do this using paths for each subgrpah folder.

This README

We keep this repositories README in sync with GraphOS in case anyone visits our public Explorer referenced above. We are using the Rover CLI to do this in this example, but you can also using the public GraphOS Platform API if you want.

Schema Checks

Certain changes to your graph's schema (such as removing a field or type) might break one of your application's clients. GraphOS provides schema checks to help you identify breaking changes before you make them, and to help you identify when a potentially dangerous change won't break anything.

To try out schema checks on this repository:

  1. Navigate to the products subgraph
  2. Edit the file and remove the mediaUrl filed from the Product type
  3. Create a new PR and commit
  4. GitHub Actions will trigger in PR and fail due to schema checks

Deploying Subgraph changes with Launches

In GraphOS, a launch represents the complete process of making a set of updates to a supergraph, usually initiated by changes to one of its subgraphs.

For this example we've kept it simple and have the minimum of what you want, keeping the main branch of this repository in sync with the main variant in GraphOS. Each variant of a supergraph has its own subgraph schemas, supergraph schema, change history, and metrics. You might have a staging or pre-production environment and that's exactly what variants are for!

Deploy to Railway and GraphOS

Deploy on Railway

You can easily deploy all of the subgraphs to Railway by clicking the button aboveβ€”just configure your first subgraph with the repo you want to clone this to, and click into the rest to accept the defaults. Once all of the subgraphs are deployed, create a new supergraph in GraphOS pointing to the users subgraph, then add new subgraphs in this order:

  1. reviews
  2. products
  3. orders
  4. shipping

Once your last deploy finishes in Studio, you can test it out by running a query like this:

  fragment ProductFragment on Product {
    averageRating
    reviews {
      content
      rating
    }
  }
  query GetProductDetails {
    products {
      id
      title
      description
      mediaUrl
      ...ProductFragment @defer
    }
  }

hack-the-supergraph's People

Contributors

blenderdude avatar dbanty avatar michael-watson avatar patrick91 avatar svc-secops avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hack-the-supergraph's Issues

Michelle Fricton Log

start

  • Location entity reference resolver was already there. The way the README was worded ("this is where we'll define...") made it seem like I was supposed to add it myself.
  • There's also a bunch more things in the resolver that aren't present in the README code snippet. (sleep, name, etc)
  • Specify "In a new terminal window..." for this instruction: Try running rover dev and use the server you have running locally:
  • specify the url and subgraph name we want them to use (4001 and start)
  • what query am I supposed to run in Sandbox? make it copy-pastable instead of just a screenshot
  • I took a peek at the "I don't want to write code..." and it seems like they are also writing code?
  • Got stuck at the step to create a supergraph - seeing the warning that is also in the screenshot but no way to move forward. Uploaded schema after some prompting from the group, but wouldn't have known to select "advanced options" to do this.

Add prettier for markdown files

Minor thing, shall we add prettier for the markdown files, so we get consistent line length, formatting, and we also get formatting for the code snippets?

Solar Seas, I don't want to write code, no completed schema

Seems we should have a schema_final.graphql (or something similar) in the solar-seas folder for the people who do not want to write code. Alternatively, provide what the solar-seas schema should look like (in whole) upon completion as part of this track so it can be easily copied into the schema file.

e-commerce schemas questions

I was looking at the schema for users and noticed some things that can be updated:

Cart:

type Cart {
  """
  Items saved in the cart session
  """
  items: [Product]

  """
  The current total of all the items in the cart, before taxes and shipping
  """
  subtotal: Float
}

I think we can change this to

type Cart {
  """
  Items saved in the cart session
  """
  items: [Product!]! # made this non nullable

  """
  The current total of all the items in the cart, before taxes and shipping
  """
  subtotal: Money! # made this money and non nullable (default could be 0 USD?)
}

OrderFilters

input OrderFilters {
  orderId: ID!
  priceHigh: Float
  priceLow: Float
  itemsInOrder: Int
}

is orderId non-nullable on purpose?


There's other places where we have nullable list of nullables, I can update those to non-nullable list of non-nullables if we prefer that approach :)

user and orders

Users shouldn't have orders inside this subgraph

"""
An user account in our system
"""
type User @key(fields: "id") {
  id: ID!

  """
  The users login username
  """
  username: String!

  """
  The user's active cart session. Once the cart items have been purchases, they transition to an Order
  """
  cart: Cart

  """
  The users previous purchases
  """
  orders(filters: OrderFilters): [Order]

Add screenshots

  • Account sign-up section
  • Screenshot for initial schema upload/pasting

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.