Links

File Structure

This README provides a brief overview of the file structure created by the Satsuma Querier CLI for managing your custom queries.

Project Structure

When you run the init command from the Satsuma Querier CLI, the following files and directories will be created:
  • .satsuma.json
  • custom-queries/
    • resolvers.ts
    • helpers.ts
    • typedefs.ts

.satsuma.json

This is a JSON configuration file stored at the root level of your project. It includes metadata about the custom query configuration.
Example:
{
// Corresponds to the CLI version used to create the custom queries.
"version": "v1",
// If you move your custom queries to a different directory, you should change this value.
"projectPathPrefix": "custom-queries/"
}

custom-queries/

This is a directory created by the init command. It stores files related to custom queries for a specific subgraph.
Within custom-queries/, you will find the following files:

resolvers.ts

This TypeScript file contains resolver functions for your custom queries. These functions are responsible for fetching the data associated with each custom query. All resolvers should be exported in the resolvers object. These functions are run inside a VM, so you can't access variables outside of the function scope. Imports won't work.
Example:
export const resolvers = {
Query: {
yourCustomQuery: (parent, args, context, info) => {
// Your resolver logic here
// `context.helpers` contains helper functions defined in helpers.ts
},
},
};

helpers.ts

This TypeScript file can contain helper functions used by your resolvers. These might be utility functions or shared logic that you don't want to duplicate across different resolvers. All helper functions should be exported in the helpers object. These functions are run inside a VM, so you can't access variables outside of the function scope. Imports won't work.
Example:
export const helpers = {
reusableDataLoader: (arg1, arg2) => {
// Your modular logic here
}
}

typedefs.ts

This TypeScript file contains the GraphQL type definitions for your custom queries. These type definitions define the shape of the data that can be queried. All type definitions should be exported in the typeDefs string.
Example:
export const typeDefs = `
type Query {
yourCustomQuery: CustomType
}
type CustomType {
field1: String
field2: Int
}
`;
Remember to run npx satsuma querier codegen to generate TypeScript types based on your GraphQL schema after modifying typedefs.ts.