You can group related models (and actions) by adding namespaces to your API. Namespaces allow you to organize your models and actions and give you more control over the shape of your generated JavaScript and GraphQL API.
Available in Gadget framework version 1.1+
API namespaces were added with Gadget framework version 1.1. If you're using an older version of Gadget, you'll need to
upgrade your framework version to use model namespaces.
How model namespaces work
Namespacing in Gadget is folder-based, and model namespaces are added by creating folders in the api/models directory. The folder name is used as the namespace in the generated API.
Namespaces can also be shared between actions and models, and nested.
Just want a folder without changing your API?
If you want to add a folder to organize models without changing your API, you can put the folder name in parentheses (). If you already have an app that uses the API client, this is a great way to organize your files and folders without changing your API.
For example, adding a (shopify) folder for all Shopify models:
Add a (shopify) folder to organize models without changing your API
yml
1api/
2 models/
3 (shopify)/ # folder to organize Shopify models, doesn't modify API
Models and global actions can share namespaces. For example, if you wanted to add a biz namespace that contains both a model's actions and a global action:
Example: a shared 'biz' namespace
yml
1api/
2 models/
3 biz/ # shared namespace
4 shopifyProduct/
5 schema.gadget.ts
6 actions/
7 create.js # model action, JS example: `api.biz.shopifyProduct.create(...)`
8 actions/
9 biz/ # shared namespace
10 bar.js # global action, JS example: `api.biz.bar(...)`
The bar global action and shopifyProduct.create model action could then be called using the biz namespace: