GQL Functions and hooks generator which can be used in andrjs and the CLI.
Inside the plugins
directory, we have a powerful custom plugin. It's a type of AST that visits each node and creates a special query for it if it satisfies these requirements:
- It's a node that requires arguments, e.g., the
isOperator
node needs an address as an argument. - It's an object node with subfields like the
andr
query,app config
query, etc.
Files are generated using the npm run codegen:master
script. This always runs before codegen to generate all the operation nodes.
This tool is potent and will generate almost all the queries you might need, even specifics like querying only the app config.
You can also add custom queries if needed. For instance, to get app config and app components in a single query without wanting addresses in the query. Adding new queries is straightforward and described in the next section.
- Create
.graphql
files inside theschema
folder. These files will contain the document node (the query you use in the GQL playground). - After creating all the queries, run
npm run codegen
, and codegen will produce the following files:-
apollo-helper.ts
: Contains field policy types used to define key fields for the arguments. -
node.ts
: Containsgraphql-request
functions. Use this for non-React applications like CLI. -
react.ts
: Producesapollo-client
hooks which can be used directly in your React projects. -
types.d.ts
: Contains all the Base Types declared in the GraphQL schema, likeIAndrSearchOptions
,IAdoType
, etc.
-
Here are a few guidelines to keep the project streamlined:
- Assign descriptive names to each query.
- Ensure there are no duplicate queries or queries with the same name.
- Avoid modifying existing queries. If a query name is already present but you want to use it for a new query, use a different name instead of changing the existing one.
- Don't clutter queries with unnecessary data. If you anticipate a future use case, create two queries: one with specific fields and another with additional fields that may be useful. This approach ensures you won't need to add a new query later as all the fields would likely be included in your master query.
Being a monorepo makes it easy to test local changes in the CLI and andrjs
. Ensure your modifications don't break other packages in the repo.
For external projects, like a React project, navigate to the gql
package directory and execute npm run build && pnpm pack
. This will generate a local package which you can then integrate into your React project without having to deploy the package to a registry.
We might be able to reference this package using a GitHub link in the future. However, this hasn't been tested yet, so it's not recommended for now.