Build your Supergraph & Make Queries
What's about to happen?
After connecting a data source and exposing models, you can create a new local build of your supergraph.
A build is a compiled, immutable state of your metadata which the Hasura Engine uses to run your API.
When you execute the command below, the CLI will create a new build for your supergraph. You'll then be able to execute a GraphQL query on your API using any models you've added.
Steps
- The DDN CLI, VS Code extension, and Docker installed
- A new or existing project
- At least one subgraph
- At least one data connector running
- Models and/or Commands added to your subgraph
Step 1. Create a supergraph build
ddn supergraph build local
This will create a build of your supergraph located in the /engine/build
directory.
Want to test your supergraph? Make sure that your services are still up and running with the following command.
ddn run docker-start
If you haven't included your connector(s) in your
compose.yaml
, don't forget to start it as well.
You can check out your local API by launching the Hasura console using the CLI.
ddn console --local
Your browser settings or privacy tools may prevent the Console from accessing your local Hasura instance. This could be
due to features designed to protect your privacy and security. Should you encounter one of these issues, we recommend
disabling these settings for the console.hasura.io
domain.
Chrome and Firefox are the recommended browsers for the best experience with the Hasura Console including for local development.
Step 2. Write your first query
Use the GraphiQL explorer to either write a query or construct it using the menu on the left-hand side of the console. When you're ready, hit the run button to execute your query.
query MyFirstQuery {
carts {
id
isComplete
userId
}
}
All types are namespaced with the subgraph to which they belong. Here, you can see that carts
belongs to a subgraph
named my_subgraph
. Thus, the query above will return a response that looks like this:
In GraphQL, you can provide a name for your query, which in this example is MyFirstQuery
. This name is customizable by
you at query time and just helps with logging and debugging.
What did this do?
When you executed the command above, the CLI used the Hasura metadata in your directory - generated based on your data source(s) — to create a local build of your supergraph. This local build is immutable and can be used to test the changes to your API before either making more changes or, eventually, creating a build on Hasura DDN.
Next, we recommend learning how easy it is to add authorization rules, which limit a user's access to data, using permissions.
Next steps
Now that you have a build of your supergraph you can do a lot more with it. Here are some suggestions to allow you to jump around the Getting Started section according to your interests:
- Deploy to cloud to make your API available to the world
- Add permissions to your models
- Create relationships between models
- Mutate your data with Hasura DDN